SYNC: connection color for cloud connections

This commit is contained in:
SPRINX0\prochazka
2025-06-13 15:08:26 +02:00
committed by Diflow
parent 620705c87a
commit 4181b75af7
3 changed files with 51 additions and 18 deletions

View File

@@ -1,10 +1,11 @@
import { presetPalettes, presetDarkPalettes } from '@ant-design/colors';
import { derived } from 'svelte/store';
import { currentThemeDefinition } from '../stores';
import { useConnectionList } from '../utility/metadataLoaders';
import { cloudConnectionsStore, currentThemeDefinition } from '../stores';
import { useCloudContentList, useConnectionList } from '../utility/metadataLoaders';
export function getConnectionColor(
connections,
cloudConnectionsStore,
dbid,
themeType,
colorIndex,
@@ -12,7 +13,7 @@ export function getConnectionColor(
useConnectionFallback = true
) {
if (!dbid || !connections) return undefined;
const current = connections.find(x => x._id == dbid.conid);
const current = connections.find(x => x._id == dbid.conid) ?? cloudConnectionsStore?.[dbid.conid];
const { database } = dbid;
let colorName = useConnectionFallback || !database ? current?.connectionColor : null;
const dbConfig = (current?.databases || []).find(x => x.name == database);
@@ -27,6 +28,18 @@ export function getConnectionColor(
return color;
}
export function getCloudContentColor(cloudContent, { cntid, folid }, themeType, colorIndex, backgroundStyle = false) {
if (!cntid || !folid || !cloudContent) return undefined;
const current = cloudContent.flatMap(x => x.items).find(x => x.cntid == cntid && x.folid == folid);
const colorName = current?.contentAttributes?.connectionColor;
if (!colorName) return undefined;
const palettes = themeType == 'dark' ? presetDarkPalettes : presetPalettes;
if (colorIndex == null) return colorName;
const color = palettes[colorName][colorIndex];
if (backgroundStyle) return `background:${color}`;
return color;
}
export function useConnectionColor(
dbid,
colorIndex,
@@ -55,20 +68,33 @@ export function useConnectionColorFactory(
) {
const connections = useConnectionList();
return derived(
[connections, currentThemeDefinition],
([$connections, $themeDef]) => (
dbid,
colorIndexOverride = null,
backgroundStyleOverride = null,
useConnectionFallbackOverride = null
) =>
getConnectionColor(
$connections,
dbid,
themeType ?? $themeDef?.themeType,
colorIndexOverride ?? colorIndex,
backgroundStyleOverride ?? backgroundStyle,
useConnectionFallbackOverride ?? useConnectionFallback
)
[connections, currentThemeDefinition, cloudConnectionsStore],
([$connections, $themeDef, $cloudConnectionsStore]) =>
(dbid, colorIndexOverride = null, backgroundStyleOverride = null, useConnectionFallbackOverride = null) =>
getConnectionColor(
$connections,
$cloudConnectionsStore,
dbid,
themeType ?? $themeDef?.themeType,
colorIndexOverride ?? colorIndex,
backgroundStyleOverride ?? backgroundStyle,
useConnectionFallbackOverride ?? useConnectionFallback
)
);
}
export function useCloudContentColorFactory(colorIndex, themeType = null, backgroundStyle = false) {
const contentList = useCloudContentList();
return derived(
[contentList, currentThemeDefinition],
([$contentList, $themeDef]) =>
(idpack, colorIndexOverride = null, backgroundStyleOverride = null) =>
getCloudContentColor(
$contentList,
idpack,
themeType ?? $themeDef?.themeType,
colorIndexOverride ?? colorIndex,
backgroundStyleOverride ?? backgroundStyle
)
);
}