mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 10:16:03 +00:00
memorize grid config
This commit is contained in:
@@ -42,29 +42,28 @@ export default function TableDataGrid({
|
|||||||
setCache = undefined,
|
setCache = undefined,
|
||||||
masterLoadedTime = undefined,
|
masterLoadedTime = undefined,
|
||||||
}) {
|
}) {
|
||||||
const [myConfig, setMyConfig] = React.useState(createGridConfig());
|
|
||||||
// const [childConfig, setChildConfig] = React.useState(createGridConfig());
|
// const [childConfig, setChildConfig] = React.useState(createGridConfig());
|
||||||
const [myCache, setMyCache] = React.useState(createGridCache());
|
const [myCache, setMyCache] = React.useState(createGridCache());
|
||||||
const [childCache, setChildCache] = React.useState(createGridCache());
|
const [childCache, setChildCache] = React.useState(createGridCache());
|
||||||
const [refReloadToken, setRefReloadToken] = React.useState(0);
|
const [refReloadToken, setRefReloadToken] = React.useState(0);
|
||||||
const [myLoadedTime, setMyLoadedTime] = React.useState(0);
|
const [myLoadedTime, setMyLoadedTime] = React.useState(0);
|
||||||
|
|
||||||
const { childConfig } = config || myConfig;
|
const { childConfig } = config;
|
||||||
const setChildConfig = (value, reference = undefined) => {
|
const setChildConfig = (value, reference = undefined) => {
|
||||||
if (_.isFunction(value)) {
|
if (_.isFunction(value)) {
|
||||||
(setConfig || setMyConfig)((x) => ({
|
setConfig((x) => ({
|
||||||
...x,
|
...x,
|
||||||
childConfig: value(x.childConfig),
|
childConfig: value(x.childConfig),
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
(setConfig || setMyConfig)((x) => ({
|
setConfig((x) => ({
|
||||||
...x,
|
...x,
|
||||||
childConfig: value,
|
childConfig: value,
|
||||||
reference: reference === undefined ? x.reference : reference,
|
reference: reference === undefined ? x.reference : reference,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const { reference } = config || myConfig;
|
const { reference } = config;
|
||||||
|
|
||||||
const connection = useConnectionInfo({ conid });
|
const connection = useConnectionInfo({ conid });
|
||||||
const dbinfo = useDatabaseInfo({ conid, database });
|
const dbinfo = useDatabaseInfo({ conid, database });
|
||||||
@@ -75,8 +74,8 @@ export default function TableDataGrid({
|
|||||||
? new TableGridDisplay(
|
? new TableGridDisplay(
|
||||||
{ schemaName, pureName },
|
{ schemaName, pureName },
|
||||||
engines(connection),
|
engines(connection),
|
||||||
config || myConfig,
|
config,
|
||||||
setConfig || setMyConfig,
|
setConfig,
|
||||||
cache || myCache,
|
cache || myCache,
|
||||||
setCache || setMyCache,
|
setCache || setMyCache,
|
||||||
dbinfo
|
dbinfo
|
||||||
@@ -95,7 +94,7 @@ export default function TableDataGrid({
|
|||||||
const newDisplay = createDisplay();
|
const newDisplay = createDisplay();
|
||||||
if (display && display.isLoadedCorrectly && !newDisplay.isLoadedCorrectly) return;
|
if (display && display.isLoadedCorrectly && !newDisplay.isLoadedCorrectly) return;
|
||||||
setDisplay(newDisplay);
|
setDisplay(newDisplay);
|
||||||
}, [connection, config || myConfig, cache || myCache, conid, database, schemaName, pureName, dbinfo]);
|
}, [connection, config, cache || myCache, conid, database, schemaName, pureName, dbinfo]);
|
||||||
|
|
||||||
const handleDatabaseStructureChanged = React.useCallback(() => {
|
const handleDatabaseStructureChanged = React.useCallback(() => {
|
||||||
(setCache || setMyCache)(createGridCache());
|
(setCache || setMyCache)(createGridCache());
|
||||||
|
|||||||
@@ -4,16 +4,18 @@ import useUndoReducer from '../utility/useUndoReducer';
|
|||||||
import usePropsCompare from '../utility/usePropsCompare';
|
import usePropsCompare from '../utility/usePropsCompare';
|
||||||
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
||||||
import TableDataGrid from '../datagrid/TableDataGrid';
|
import TableDataGrid from '../datagrid/TableDataGrid';
|
||||||
|
import useGridConfig from '../utility/useGridConfig';
|
||||||
|
|
||||||
export default function TableDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef, tabid }) {
|
export default function TableDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef, tabid }) {
|
||||||
const [changeSetState, dispatchChangeSet] = useUndoReducer(createChangeSet());
|
const [changeSetState, dispatchChangeSet] = useUndoReducer(createChangeSet());
|
||||||
useUpdateDatabaseForTab(tabVisible, conid, database);
|
useUpdateDatabaseForTab(tabVisible, conid, database);
|
||||||
// const [config, setConfig] = React.useState(createGridConfig());
|
const [config, setConfig] = useGridConfig(tabid);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableDataGrid
|
<TableDataGrid
|
||||||
conid={conid}
|
conid={conid}
|
||||||
// config={config}
|
config={config}
|
||||||
|
setConfig={setConfig}
|
||||||
database={database}
|
database={database}
|
||||||
schemaName={schemaName}
|
schemaName={schemaName}
|
||||||
pureName={pureName}
|
pureName={pureName}
|
||||||
|
|||||||
@@ -3,16 +3,17 @@ import useFetch from '../utility/useFetch';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import theme from '../theme';
|
import theme from '../theme';
|
||||||
import DataGrid from '../datagrid/DataGrid';
|
import DataGrid from '../datagrid/DataGrid';
|
||||||
import { ViewGridDisplay, createGridConfig, createGridCache, createChangeSet } from '@dbgate/datalib';
|
import { ViewGridDisplay, createGridCache, createChangeSet } from '@dbgate/datalib';
|
||||||
import { useConnectionInfo, useViewInfo } from '../utility/metadataLoaders';
|
import { useConnectionInfo, useViewInfo } from '../utility/metadataLoaders';
|
||||||
import engines from '@dbgate/engines';
|
import engines from '@dbgate/engines';
|
||||||
import useUndoReducer from '../utility/useUndoReducer';
|
import useUndoReducer from '../utility/useUndoReducer';
|
||||||
import usePropsCompare from '../utility/usePropsCompare';
|
import usePropsCompare from '../utility/usePropsCompare';
|
||||||
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
||||||
|
import useGridConfig from '../utility/useGridConfig';
|
||||||
|
|
||||||
export default function ViewDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef }) {
|
export default function ViewDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef, tabid }) {
|
||||||
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
||||||
const [config, setConfig] = React.useState(createGridConfig());
|
const [config, setConfig] = useGridConfig(tabid);
|
||||||
const [cache, setCache] = React.useState(createGridCache());
|
const [cache, setCache] = React.useState(createGridCache());
|
||||||
const [changeSetState, dispatchChangeSet] = useUndoReducer(createChangeSet());
|
const [changeSetState, dispatchChangeSet] = useUndoReducer(createChangeSet());
|
||||||
|
|
||||||
@@ -24,7 +25,15 @@ export default function ViewDataTab({ conid, database, schemaName, pureName, tab
|
|||||||
const display = React.useMemo(
|
const display = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
viewInfo && connection
|
viewInfo && connection
|
||||||
? new ViewGridDisplay(viewInfo, engines(connection), config, setConfig, cache, setCache)
|
? new ViewGridDisplay(
|
||||||
|
viewInfo,
|
||||||
|
engines(connection),
|
||||||
|
//@ts-ignore
|
||||||
|
config,
|
||||||
|
setConfig,
|
||||||
|
cache,
|
||||||
|
setCache
|
||||||
|
)
|
||||||
: null,
|
: null,
|
||||||
[viewInfo, connection, config, cache]
|
[viewInfo, connection, config, cache]
|
||||||
);
|
);
|
||||||
|
|||||||
18
packages/web/src/utility/useGridConfig.js
Normal file
18
packages/web/src/utility/useGridConfig.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { createGridConfig } from '@dbgate/datalib';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const loadGridConfigFunc = (tabid) => () => {
|
||||||
|
const existing = localStorage.getItem(`grid_${tabid}`);
|
||||||
|
if (existing) return JSON.parse(existing);
|
||||||
|
return createGridConfig();
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function useGridConfig(tabid) {
|
||||||
|
const [config, setConfig] = React.useState(loadGridConfigFunc(tabid));
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
localStorage.setItem(`grid_${tabid}`, JSON.stringify(config));
|
||||||
|
}, [config]);
|
||||||
|
|
||||||
|
return [config, setConfig];
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ function OpenedTabsList() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WidgetTitle>Opened tabs</WidgetTitle>
|
<WidgetTitle>Recently closed tabs</WidgetTitle>
|
||||||
<WidgetsInnerContainer>
|
<WidgetsInnerContainer>
|
||||||
<AppObjectList list={tabs} makeAppObj={openedTabAppObject()} />
|
<AppObjectList list={tabs} makeAppObj={openedTabAppObject()} />
|
||||||
</WidgetsInnerContainer>
|
</WidgetsInnerContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user