mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 06:06:01 +00:00
refactor - visibleSecondary not stored, computed in component
This commit is contained in:
@@ -18,7 +18,6 @@ export interface TabDefinition {
|
|||||||
tabComponent: string;
|
tabComponent: string;
|
||||||
tabOrder?: number;
|
tabOrder?: number;
|
||||||
multiTabIndex?: number;
|
multiTabIndex?: number;
|
||||||
visibleSecondary?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writableWithStorage<T>(defaultValue: T, storageName) {
|
export function writableWithStorage<T>(defaultValue: T, storageName) {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<script>
|
<script>
|
||||||
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
|
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
|
||||||
import { openedTabs } from '../stores';
|
import { currentDatabase, lockedDatabaseMode, openedTabs } from '../stores';
|
||||||
import TabsContainer from './TabsContainer.svelte';
|
import TabsContainer from './TabsContainer.svelte';
|
||||||
|
import { shouldShowTab } from './TabsPanel.svelte';
|
||||||
|
|
||||||
$: isLeft = !!$openedTabs.find(x => x.closedTime == null && !x.multiTabIndex);
|
$: filteredTabsFromAllParts = $openedTabs.filter(x => shouldShowTab(x, $lockedDatabaseMode, $currentDatabase));
|
||||||
$: isRight = !!$openedTabs.find(x => x.closedTime == null && x.multiTabIndex == 1);
|
$: isLeft = !!filteredTabsFromAllParts.find(x => !x.multiTabIndex);
|
||||||
|
$: isRight = !!filteredTabsFromAllParts.find(x => x.multiTabIndex == 1);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<HorizontalSplitter hideFirst={!isLeft && isRight} isSplitter={isRight}>
|
<HorizontalSplitter hideFirst={!isLeft && isRight} isSplitter={isRight}>
|
||||||
|
|||||||
@@ -1,16 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { openedTabs } from '../stores';
|
import { currentDatabase, lockedDatabaseMode, openedTabs, TabDefinition } from '../stores';
|
||||||
import TabContent from './TabContent.svelte';
|
import TabContent from './TabContent.svelte';
|
||||||
import tabs from '../tabs';
|
import tabs from '../tabs';
|
||||||
|
import { shouldShowTab } from './TabsPanel.svelte';
|
||||||
|
|
||||||
export let multiTabIndex;
|
export let multiTabIndex;
|
||||||
|
|
||||||
let mountedTabs = {};
|
let mountedTabs = {};
|
||||||
$: selectedTab = $openedTabs.find(
|
|
||||||
x => (x.selected || x.visibleSecondary) && x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex
|
function findShownTab(tabs: TabDefinition[], multiTabIndex, lockedDbMode, currentDb) {
|
||||||
|
const selectedTab = tabs.find(x => x.selected && x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex);
|
||||||
|
if (selectedTab) {
|
||||||
|
return selectedTab;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedIndex = _.findLastIndex(
|
||||||
|
tabs,
|
||||||
|
x => (x.multiTabIndex || 0) == multiTabIndex && shouldShowTab(x, lockedDbMode, currentDb)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return tabs[selectedIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
$: shownTab = findShownTab($openedTabs, multiTabIndex, $lockedDatabaseMode, $currentDatabase);
|
||||||
|
|
||||||
// cleanup closed tabs
|
// cleanup closed tabs
|
||||||
$: {
|
$: {
|
||||||
if (
|
if (
|
||||||
@@ -28,10 +42,10 @@
|
|||||||
|
|
||||||
// open missing tabs
|
// open missing tabs
|
||||||
$: {
|
$: {
|
||||||
if (selectedTab) {
|
if (shownTab) {
|
||||||
const { tabid } = selectedTab;
|
const { tabid } = shownTab;
|
||||||
if (tabid && !mountedTabs[tabid]) {
|
if (tabid && !mountedTabs[tabid]) {
|
||||||
const newTab = tabs[selectedTab.tabComponent]?.default;
|
const newTab = tabs[shownTab.tabComponent]?.default;
|
||||||
if (newTab) {
|
if (newTab) {
|
||||||
mountedTabs = {
|
mountedTabs = {
|
||||||
...mountedTabs,
|
...mountedTabs,
|
||||||
@@ -50,6 +64,6 @@
|
|||||||
tabComponent={mountedTabs[tabid]}
|
tabComponent={mountedTabs[tabid]}
|
||||||
{...openedTabsByTabId[tabid]?.props}
|
{...openedTabsByTabId[tabid]?.props}
|
||||||
{tabid}
|
{tabid}
|
||||||
tabVisible={tabid == (selectedTab && selectedTab.tabid)}
|
tabVisible={tabid == (shownTab && shownTab.tabid)}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
...x,
|
...x,
|
||||||
closedTime: shouldShowTab(x) && closeCondition(x, active) ? new Date().getTime() : x.closedTime,
|
closedTime: shouldShowTab(x) && closeCondition(x, active) ? new Date().getTime() : x.closedTime,
|
||||||
selected: false,
|
selected: false,
|
||||||
visibleSecondary: false,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (newFiles.find(x => x.selected && shouldShowTab(x))) {
|
if (newFiles.find(x => x.selected && shouldShowTab(x))) {
|
||||||
@@ -75,7 +74,6 @@
|
|||||||
...x,
|
...x,
|
||||||
closedTime: shouldShowTab(x) && closeCondition(x) ? new Date().getTime() : x.closedTime,
|
closedTime: shouldShowTab(x) && closeCondition(x) ? new Date().getTime() : x.closedTime,
|
||||||
selected: false,
|
selected: false,
|
||||||
visibleSecondary: false,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (newFiles.find(x => x.selected && shouldShowTab(x))) {
|
if (newFiles.find(x => x.selected && shouldShowTab(x))) {
|
||||||
@@ -92,14 +90,12 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function splitTab(multiTabIndex) {
|
function splitTab(multiTabIndex) {
|
||||||
openedTabs.update(tabs => {
|
openedTabs.update(tabs =>
|
||||||
const secondaryIndex = _.findLastIndex(tabs, x => shouldShowTab(x) && !x.selected);
|
tabs.map((x, i) => ({
|
||||||
return tabs.map((x, i) => ({
|
|
||||||
...x,
|
...x,
|
||||||
multiTabIndex: x.selected ? 1 - multiTabIndex : x.multiTabIndex,
|
multiTabIndex: x.selected ? 1 - multiTabIndex : x.multiTabIndex,
|
||||||
visibleSecondary: i == secondaryIndex,
|
}))
|
||||||
}));
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeTab = closeTabFunc((x, active) => x.tabid == active.tabid);
|
const closeTab = closeTabFunc((x, active) => x.tabid == active.tabid);
|
||||||
@@ -306,7 +302,7 @@
|
|||||||
|
|
||||||
$: scrollInViewTab($activeTabId);
|
$: scrollInViewTab($activeTabId);
|
||||||
|
|
||||||
$: filteredTabsFromAllParts = $openedTabs.filter(x => shouldShowTab(x));
|
$: filteredTabsFromAllParts = $openedTabs.filter(x => shouldShowTab(x, $lockedDatabaseMode, $currentDatabase));
|
||||||
$: allowSplitTab =
|
$: allowSplitTab =
|
||||||
_.uniq(filteredTabsFromAllParts.map(x => x.multiTabIndex || 0)).length == 1 && filteredTabsFromAllParts.length >= 2;
|
_.uniq(filteredTabsFromAllParts.map(x => x.multiTabIndex || 0)).length == 1 && filteredTabsFromAllParts.length >= 2;
|
||||||
|
|
||||||
|
|||||||
@@ -29,24 +29,9 @@ export function markTabSaved(tabid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setSelectedTabFunc(files, tabid) {
|
export function setSelectedTabFunc(files, tabid) {
|
||||||
const oldSelected = files.find(x => x.selected);
|
|
||||||
const newSelected = files.find(x => x.tabid == tabid);
|
|
||||||
const changeVisibleSecondary = (oldSelected.multiTabIndex || 0) != (newSelected.multiTabIndex || 0);
|
|
||||||
return [
|
return [
|
||||||
...(files || [])
|
...(files || []).filter(x => x.tabid != tabid).map(x => ({ ...x, selected: false })),
|
||||||
.filter(x => x.tabid != tabid)
|
...(files || []).filter(x => x.tabid == tabid).map(x => ({ ...x, selected: true })),
|
||||||
.map(x => ({
|
|
||||||
...x,
|
|
||||||
selected: false,
|
|
||||||
visibleSecondary: changeVisibleSecondary ? x.selected : x.visibleSecondary,
|
|
||||||
})),
|
|
||||||
...(files || [])
|
|
||||||
.filter(x => x.tabid == tabid)
|
|
||||||
.map(x => ({
|
|
||||||
...x,
|
|
||||||
selected: true,
|
|
||||||
visibleSecondary: false,
|
|
||||||
})),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user