mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 16:16:02 +00:00
end tab preview mode when change grid config
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { createGridConfig } from 'dbgate-datalib';
|
||||
import { writable } from 'svelte/store';
|
||||
import { onDestroy } from 'svelte';
|
||||
import { getOpenedTabs, openedTabs } from '../stores';
|
||||
import _ from 'lodash';
|
||||
|
||||
function doLoadGridConfigFunc(tabid) {
|
||||
try {
|
||||
@@ -17,9 +19,35 @@ function doLoadGridConfigFunc(tabid) {
|
||||
return createGridConfig();
|
||||
}
|
||||
|
||||
function containsNotEmptyObject(obj) {
|
||||
for (const key of Object.keys(obj)) {
|
||||
if (!_.isEmpty(obj[key])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export default function useGridConfig(tabid) {
|
||||
const config = writable(doLoadGridConfigFunc(tabid));
|
||||
const unsubscribe = config.subscribe(value => localStorage.setItem(`tabdata_grid_${tabid}`, JSON.stringify(value)));
|
||||
const unsubscribe = config.subscribe(value => {
|
||||
localStorage.setItem(`tabdata_grid_${tabid}`, JSON.stringify(value));
|
||||
|
||||
if (containsNotEmptyObject(value)) {
|
||||
if (getOpenedTabs().find(x => x.tabid == tabid)?.tabPreviewMode) {
|
||||
openedTabs.update(tabs =>
|
||||
tabs.map(x =>
|
||||
x.tabid == tabid
|
||||
? {
|
||||
...x,
|
||||
tabPreviewMode: false,
|
||||
}
|
||||
: x
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
onDestroy(unsubscribe);
|
||||
return config;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user