mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 22:16:00 +00:00
SYNC: connection color for cloud connections
This commit is contained in:
committed by
Diflow
parent
620705c87a
commit
4181b75af7
@@ -123,6 +123,8 @@
|
|||||||
icon={'img cloud-connection'}
|
icon={'img cloud-connection'}
|
||||||
title={data.name}
|
title={data.name}
|
||||||
menu={createMenu}
|
menu={createMenu}
|
||||||
|
colorMark={passProps?.cloudContentColorFactory &&
|
||||||
|
passProps?.cloudContentColorFactory({ cntid: data.cntid, folid: data.folid })}
|
||||||
on:click={handleOpenContent}
|
on:click={handleOpenContent}
|
||||||
on:dblclick
|
on:dblclick
|
||||||
on:expand
|
on:expand
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { presetPalettes, presetDarkPalettes } from '@ant-design/colors';
|
import { presetPalettes, presetDarkPalettes } from '@ant-design/colors';
|
||||||
import { derived } from 'svelte/store';
|
import { derived } from 'svelte/store';
|
||||||
import { currentThemeDefinition } from '../stores';
|
import { cloudConnectionsStore, currentThemeDefinition } from '../stores';
|
||||||
import { useConnectionList } from '../utility/metadataLoaders';
|
import { useCloudContentList, useConnectionList } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
export function getConnectionColor(
|
export function getConnectionColor(
|
||||||
connections,
|
connections,
|
||||||
|
cloudConnectionsStore,
|
||||||
dbid,
|
dbid,
|
||||||
themeType,
|
themeType,
|
||||||
colorIndex,
|
colorIndex,
|
||||||
@@ -12,7 +13,7 @@ export function getConnectionColor(
|
|||||||
useConnectionFallback = true
|
useConnectionFallback = true
|
||||||
) {
|
) {
|
||||||
if (!dbid || !connections) return undefined;
|
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;
|
const { database } = dbid;
|
||||||
let colorName = useConnectionFallback || !database ? current?.connectionColor : null;
|
let colorName = useConnectionFallback || !database ? current?.connectionColor : null;
|
||||||
const dbConfig = (current?.databases || []).find(x => x.name == database);
|
const dbConfig = (current?.databases || []).find(x => x.name == database);
|
||||||
@@ -27,6 +28,18 @@ export function getConnectionColor(
|
|||||||
return color;
|
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(
|
export function useConnectionColor(
|
||||||
dbid,
|
dbid,
|
||||||
colorIndex,
|
colorIndex,
|
||||||
@@ -55,20 +68,33 @@ export function useConnectionColorFactory(
|
|||||||
) {
|
) {
|
||||||
const connections = useConnectionList();
|
const connections = useConnectionList();
|
||||||
return derived(
|
return derived(
|
||||||
[connections, currentThemeDefinition],
|
[connections, currentThemeDefinition, cloudConnectionsStore],
|
||||||
([$connections, $themeDef]) => (
|
([$connections, $themeDef, $cloudConnectionsStore]) =>
|
||||||
dbid,
|
(dbid, colorIndexOverride = null, backgroundStyleOverride = null, useConnectionFallbackOverride = null) =>
|
||||||
colorIndexOverride = null,
|
getConnectionColor(
|
||||||
backgroundStyleOverride = null,
|
$connections,
|
||||||
useConnectionFallbackOverride = null
|
$cloudConnectionsStore,
|
||||||
) =>
|
dbid,
|
||||||
getConnectionColor(
|
themeType ?? $themeDef?.themeType,
|
||||||
$connections,
|
colorIndexOverride ?? colorIndex,
|
||||||
dbid,
|
backgroundStyleOverride ?? backgroundStyle,
|
||||||
themeType ?? $themeDef?.themeType,
|
useConnectionFallbackOverride ?? useConnectionFallback
|
||||||
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
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,15 @@
|
|||||||
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||||
import { showSnackbarInfo } from '../utility/snackbar';
|
import { showSnackbarInfo } from '../utility/snackbar';
|
||||||
import { isProApp } from '../utility/proTools';
|
import { isProApp } from '../utility/proTools';
|
||||||
|
import { useCloudContentColorFactory, useConnectionColorFactory } from '../utility/useConnectionColor';
|
||||||
|
|
||||||
let filter = '';
|
let filter = '';
|
||||||
let domSqlObjectList = null;
|
let domSqlObjectList = null;
|
||||||
|
|
||||||
const cloudContentList = useCloudContentList();
|
const cloudContentList = useCloudContentList();
|
||||||
const serverStatus = useServerStatus();
|
const serverStatus = useServerStatus();
|
||||||
|
const cloudContentColorFactory = useCloudContentColorFactory(3);
|
||||||
|
const connectionColorFactory = useConnectionColorFactory(3);
|
||||||
|
|
||||||
$: emptyCloudContent = ($cloudContentList || []).filter(x => !x.items?.length).map(x => x.folid);
|
$: emptyCloudContent = ($cloudContentList || []).filter(x => !x.items?.length).map(x => x.folid);
|
||||||
$: cloudContentFlat = _.sortBy(
|
$: cloudContentFlat = _.sortBy(
|
||||||
@@ -240,6 +243,8 @@
|
|||||||
}}
|
}}
|
||||||
passProps={{
|
passProps={{
|
||||||
onFocusSqlObjectList: () => domSqlObjectList.focus(),
|
onFocusSqlObjectList: () => domSqlObjectList.focus(),
|
||||||
|
cloudContentColorFactory: $cloudContentColorFactory,
|
||||||
|
connectionColorFactory: $connectionColorFactory,
|
||||||
}}
|
}}
|
||||||
groupContextMenu={createGroupContextMenu}
|
groupContextMenu={createGroupContextMenu}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user