mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 14:46:01 +00:00
database & connection color overrides
This commit is contained in:
@@ -3,35 +3,76 @@ import { derived } from 'svelte/store';
|
||||
import { currentThemeDefinition } from '../stores';
|
||||
import { useConnectionList } from '../utility/metadataLoaders';
|
||||
|
||||
export function getConnectionColor(connections, dbid, themeType, colorIndex, backgroundStyle = false) {
|
||||
export function getConnectionColor(
|
||||
connections,
|
||||
dbid,
|
||||
themeType,
|
||||
colorIndex,
|
||||
backgroundStyle = false,
|
||||
useConnectionFallback = true
|
||||
) {
|
||||
if (!dbid || !connections) return undefined;
|
||||
const current = connections.find(x => x._id == dbid.conid);
|
||||
if (!current?.connectionColor) return undefined;
|
||||
const { database } = dbid;
|
||||
let colorName = useConnectionFallback || !database ? current?.connectionColor : null;
|
||||
if (
|
||||
database &&
|
||||
current.databaseConfig &&
|
||||
current.databaseConfig[database] &&
|
||||
current.databaseConfig[database].databaseColor
|
||||
) {
|
||||
colorName = current.databaseConfig[database].databaseColor;
|
||||
}
|
||||
if (!colorName) return undefined;
|
||||
const palettes = themeType == 'dark' ? presetDarkPalettes : presetPalettes;
|
||||
if (colorIndex == null) return current?.connectionColor;
|
||||
const color = palettes[current?.connectionColor][colorIndex];
|
||||
if (colorIndex == null) return colorName;
|
||||
const color = palettes[colorName][colorIndex];
|
||||
if (backgroundStyle) return `background:${color}`;
|
||||
return color;
|
||||
}
|
||||
|
||||
export function useConnectionColor(dbid, colorIndex, themeType = null, backgroundStyle = false) {
|
||||
export function useConnectionColor(
|
||||
dbid,
|
||||
colorIndex,
|
||||
themeType = null,
|
||||
backgroundStyle = false,
|
||||
useConnectionFallback = true
|
||||
) {
|
||||
const connections = useConnectionList();
|
||||
return derived([connections, currentThemeDefinition], ([$connections, $themeDef]) =>
|
||||
getConnectionColor($connections, dbid, themeType ?? $themeDef?.themeType, colorIndex, backgroundStyle)
|
||||
getConnectionColor(
|
||||
$connections,
|
||||
dbid,
|
||||
themeType ?? $themeDef?.themeType,
|
||||
colorIndex,
|
||||
backgroundStyle,
|
||||
useConnectionFallback
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function useConnectionColorFactory(colorIndex, themeType = null, backgroundStyle = false) {
|
||||
export function useConnectionColorFactory(
|
||||
colorIndex,
|
||||
themeType = null,
|
||||
backgroundStyle = false,
|
||||
useConnectionFallback = true
|
||||
) {
|
||||
const connections = useConnectionList();
|
||||
return derived(
|
||||
[connections, currentThemeDefinition],
|
||||
([$connections, $themeDef]) => (dbid, colorIndexOverride = null) =>
|
||||
([$connections, $themeDef]) => (
|
||||
dbid,
|
||||
colorIndexOverride = null,
|
||||
backgroundStyleOverride = null,
|
||||
useConnectionFallbackOverride = null
|
||||
) =>
|
||||
getConnectionColor(
|
||||
$connections,
|
||||
dbid,
|
||||
themeType ?? $themeDef?.themeType,
|
||||
colorIndexOverride || colorIndex,
|
||||
backgroundStyle
|
||||
colorIndexOverride ?? colorIndex,
|
||||
backgroundStyleOverride ?? backgroundStyle,
|
||||
useConnectionFallbackOverride ?? useConnectionFallback
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user