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

@@ -123,6 +123,8 @@
icon={'img cloud-connection'}
title={data.name}
menu={createMenu}
colorMark={passProps?.cloudContentColorFactory &&
passProps?.cloudContentColorFactory({ cntid: data.cntid, folid: data.folid })}
on:click={handleOpenContent}
on:dblclick
on:expand

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
)
);
}

View File

@@ -34,12 +34,15 @@
import ConfirmModal from '../modals/ConfirmModal.svelte';
import { showSnackbarInfo } from '../utility/snackbar';
import { isProApp } from '../utility/proTools';
import { useCloudContentColorFactory, useConnectionColorFactory } from '../utility/useConnectionColor';
let filter = '';
let domSqlObjectList = null;
const cloudContentList = useCloudContentList();
const serverStatus = useServerStatus();
const cloudContentColorFactory = useCloudContentColorFactory(3);
const connectionColorFactory = useConnectionColorFactory(3);
$: emptyCloudContent = ($cloudContentList || []).filter(x => !x.items?.length).map(x => x.folid);
$: cloudContentFlat = _.sortBy(
@@ -240,6 +243,8 @@
}}
passProps={{
onFocusSqlObjectList: () => domSqlObjectList.focus(),
cloudContentColorFactory: $cloudContentColorFactory,
connectionColorFactory: $connectionColorFactory,
}}
groupContextMenu={createGroupContextMenu}
/>