mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 23:06:01 +00:00
recently closed tabs
This commit is contained in:
@@ -131,12 +131,26 @@ export default function TabsPanel() {
|
|||||||
setOpenedTabs((files) => {
|
setOpenedTabs((files) => {
|
||||||
const active = files.find((x) => x.tabid == tabid);
|
const active = files.find((x) => x.tabid == tabid);
|
||||||
if (!active) return files;
|
if (!active) return files;
|
||||||
let index = _.findIndex(files, (x) => x.tabid == tabid);
|
const lastSelectedIndex = _.findIndex(files, (x) => x.tabid == tabid);
|
||||||
const newFiles = files.filter((x) => !closeCondition(x, active));
|
let selectedIndex = lastSelectedIndex;
|
||||||
|
|
||||||
if (!newFiles.find((x) => x.selected)) {
|
const newFiles = files.map((x) => ({
|
||||||
while (index >= newFiles.length) index -= 1;
|
...x,
|
||||||
if (index >= 0) newFiles[index].selected = true;
|
closedTime: x.closedTime || (closeCondition(x, active) ? new Date().getTime() : undefined),
|
||||||
|
}));
|
||||||
|
|
||||||
|
while (selectedIndex >= 0 && newFiles[selectedIndex].closedTime) selectedIndex -= 1;
|
||||||
|
|
||||||
|
if (selectedIndex < 0) {
|
||||||
|
selectedIndex = lastSelectedIndex;
|
||||||
|
while (selectedIndex < newFiles.length && newFiles[selectedIndex].closedTime) selectedIndex += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedIndex != lastSelectedIndex) {
|
||||||
|
return newFiles.map((x, index) => ({
|
||||||
|
...x,
|
||||||
|
selected: index == selectedIndex,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return newFiles;
|
return newFiles;
|
||||||
@@ -184,12 +198,14 @@ export default function TabsPanel() {
|
|||||||
// 't',
|
// 't',
|
||||||
// tabs.map(x => x.tooltip)
|
// tabs.map(x => x.tooltip)
|
||||||
// );
|
// );
|
||||||
const tabsWithDb = tabs.map((tab) => ({
|
const tabsWithDb = tabs
|
||||||
...tab,
|
.filter((x) => !x.closedTime)
|
||||||
tabDbName: tab.props && tab.props.conid && tab.props.database ? tab.props.database : '(no DB)',
|
.map((tab) => ({
|
||||||
tabDbKey:
|
...tab,
|
||||||
tab.props && tab.props.conid && tab.props.database ? formatDbKey(tab.props.conid, tab.props.database) : noDbKey,
|
tabDbName: tab.props && tab.props.conid && tab.props.database ? tab.props.database : '(no DB)',
|
||||||
}));
|
tabDbKey:
|
||||||
|
tab.props && tab.props.conid && tab.props.database ? formatDbKey(tab.props.conid, tab.props.database) : noDbKey,
|
||||||
|
}));
|
||||||
const tabsByDb = _.groupBy(tabsWithDb, 'tabDbKey');
|
const tabsByDb = _.groupBy(tabsWithDb, 'tabDbKey');
|
||||||
const dbKeys = _.keys(tabsByDb).sort();
|
const dbKeys = _.keys(tabsByDb).sort();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import moment from 'moment';
|
||||||
import { getIconImage } from '../icons';
|
import { getIconImage } from '../icons';
|
||||||
|
|
||||||
const openedTabAppObject = () => ({ tabid, props, selected, icon, title, busy }, { setOpenedTabs }) => {
|
const closedTabAppObject = () => ({ tabid, props, selected, icon, title, closedTime, busy }, { setOpenedTabs }) => {
|
||||||
const key = tabid;
|
const key = tabid;
|
||||||
const Icon = (props) => getIconImage(icon, props);
|
const Icon = (props) => getIconImage(icon, props);
|
||||||
const isBold = !!selected;
|
const isBold = !!selected;
|
||||||
@@ -12,11 +13,12 @@ const openedTabAppObject = () => ({ tabid, props, selected, icon, title, busy },
|
|||||||
files.map((x) => ({
|
files.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
selected: x.tabid == tabid,
|
selected: x.tabid == tabid,
|
||||||
|
closedTime: x.tabid == tabid ? undefined : x.closedTime,
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return { title, key, Icon, isBold, onClick, isBusy: busy };
|
return { title: `${title} ${moment(closedTime).fromNow()}`, key, Icon, isBold, onClick, isBusy: busy };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default openedTabAppObject;
|
export default closedTabAppObject;
|
||||||
@@ -76,7 +76,7 @@ export default function QueryTab({
|
|||||||
...other
|
...other
|
||||||
}) {
|
}) {
|
||||||
const loadingText = 'Loading SQL template...';
|
const loadingText = 'Loading SQL template...';
|
||||||
const localStorageKey = storageKey || `sql_${tabid}`;
|
const localStorageKey = storageKey || `tabdata_sql_${tabid}`;
|
||||||
const { sqlTemplate } = initialArgs || {};
|
const { sqlTemplate } = initialArgs || {};
|
||||||
const [queryText, setQueryText] = React.useState(
|
const [queryText, setQueryText] = React.useState(
|
||||||
() => localStorage.getItem(localStorageKey) || initialScript || (sqlTemplate ? loadingText : '')
|
() => localStorage.getItem(localStorageKey) || initialScript || (sqlTemplate ? loadingText : '')
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export default function ShellTab({
|
|||||||
storageKey,
|
storageKey,
|
||||||
...other
|
...other
|
||||||
}) {
|
}) {
|
||||||
const localStorageKey = storageKey || `shell_${tabid}`;
|
const localStorageKey = storageKey || `tabdata_shell_${tabid}`;
|
||||||
const [shellText, setShellText] = React.useState(() => localStorage.getItem(localStorageKey) || initialScript || '');
|
const [shellText, setShellText] = React.useState(() => localStorage.getItem(localStorageKey) || initialScript || '');
|
||||||
const shellTextRef = React.useRef(shellText);
|
const shellTextRef = React.useRef(shellText);
|
||||||
const [busy, setBusy] = React.useState(false);
|
const [busy, setBusy] = React.useState(false);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { createGridConfig } from '@dbgate/datalib';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const loadGridConfigFunc = (tabid) => () => {
|
const loadGridConfigFunc = (tabid) => () => {
|
||||||
const existing = localStorage.getItem(`grid_${tabid}`);
|
const existing = localStorage.getItem(`tabdata_grid_${tabid}`);
|
||||||
if (existing) return JSON.parse(existing);
|
if (existing) return JSON.parse(existing);
|
||||||
return createGridConfig();
|
return createGridConfig();
|
||||||
};
|
};
|
||||||
@@ -11,7 +11,7 @@ export default function useGridConfig(tabid) {
|
|||||||
const [config, setConfig] = React.useState(loadGridConfigFunc(tabid));
|
const [config, setConfig] = React.useState(loadGridConfigFunc(tabid));
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
localStorage.setItem(`grid_${tabid}`, JSON.stringify(config));
|
localStorage.setItem(`tabdata_grid_${tabid}`, JSON.stringify(config));
|
||||||
}, [config]);
|
}, [config]);
|
||||||
|
|
||||||
return [config, setConfig];
|
return [config, setConfig];
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import _ from 'lodash';
|
|||||||
|
|
||||||
import { AppObjectList } from '../appobj/AppObjectList';
|
import { AppObjectList } from '../appobj/AppObjectList';
|
||||||
import { useOpenedTabs, useSavedSqlFiles } from '../utility/globalState';
|
import { useOpenedTabs, useSavedSqlFiles } from '../utility/globalState';
|
||||||
import openedTabAppObject from '../appobj/openedTabAppObject';
|
import closedTabAppObject from '../appobj/closedTabAppObject';
|
||||||
import {
|
import {
|
||||||
SearchBoxWrapper,
|
SearchBoxWrapper,
|
||||||
WidgetsInnerContainer,
|
WidgetsInnerContainer,
|
||||||
@@ -14,14 +14,20 @@ import {
|
|||||||
} from './WidgetStyles';
|
} from './WidgetStyles';
|
||||||
import savedSqlFileAppObject from '../appobj/savedSqlFileAppObject';
|
import savedSqlFileAppObject from '../appobj/savedSqlFileAppObject';
|
||||||
|
|
||||||
function OpenedTabsList() {
|
function ClosedTabsList() {
|
||||||
const tabs = useOpenedTabs();
|
const tabs = useOpenedTabs();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WidgetTitle>Recently closed tabs</WidgetTitle>
|
<WidgetTitle>Recently closed tabs</WidgetTitle>
|
||||||
<WidgetsInnerContainer>
|
<WidgetsInnerContainer>
|
||||||
<AppObjectList list={tabs} makeAppObj={openedTabAppObject()} />
|
<AppObjectList
|
||||||
|
list={_.sortBy(
|
||||||
|
tabs.filter((x) => x.closedTime),
|
||||||
|
(x) => -x.closedTime
|
||||||
|
)}
|
||||||
|
makeAppObj={closedTabAppObject()}
|
||||||
|
/>
|
||||||
</WidgetsInnerContainer>
|
</WidgetsInnerContainer>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -44,7 +50,7 @@ export default function FilesWidget() {
|
|||||||
return (
|
return (
|
||||||
<WidgetsMainContainer>
|
<WidgetsMainContainer>
|
||||||
<WidgetsOuterContainer>
|
<WidgetsOuterContainer>
|
||||||
<OpenedTabsList />
|
<ClosedTabsList />
|
||||||
</WidgetsOuterContainer>
|
</WidgetsOuterContainer>
|
||||||
<WidgetsOuterContainer>
|
<WidgetsOuterContainer>
|
||||||
<SavedSqlFilesList />
|
<SavedSqlFilesList />
|
||||||
|
|||||||
Reference in New Issue
Block a user