Merge pull request #942 from dbgate/feature-prevent-spawning-same-modal

feat: prevent spawning the same modal if one instance is opened
This commit is contained in:
Jan Prochazka
2024-11-22 08:21:00 +01:00
committed by GitHub
3 changed files with 17 additions and 1 deletions

View File

@@ -2,18 +2,22 @@ import { openedModals } from '../stores';
import { get } from 'svelte/store'; import { get } from 'svelte/store';
import uuidv1 from 'uuid/v1'; import uuidv1 from 'uuid/v1';
import _ from 'lodash'; import _ from 'lodash';
import invalidateCommands from '../commands/invalidateCommands';
export function showModal(component, props = {}) { export function showModal(component, props = {}) {
const modalId = uuidv1(); const modalId = uuidv1();
openedModals.update(x => [...x, { component, modalId, props }]); openedModals.update(x => [...x, { component, modalId, props }]);
invalidateCommands();
} }
export function closeModal(modalId) { export function closeModal(modalId) {
openedModals.update(x => x.filter(y => y.modalId != modalId)); openedModals.update(x => x.filter(y => y.modalId != modalId));
invalidateCommands();
} }
export function closeCurrentModal() { export function closeCurrentModal() {
openedModals.update(modals => modals.slice(0, modals.length - 1)); openedModals.update(modals => modals.slice(0, modals.length - 1));
invalidateCommands();
} }
export function getActiveModalId() { export function getActiveModalId() {

View File

@@ -323,3 +323,9 @@ appliedCurrentSchema.subscribe(value => {
appliedCurrentSchemaValue = value; appliedCurrentSchemaValue = value;
}); });
export const getAppliedCurrentSchema = () => appliedCurrentSchemaValue; export const getAppliedCurrentSchema = () => appliedCurrentSchemaValue;
let openedModalsValue = [];
openedModals.subscribe(value => {
openedModalsValue = value;
});
export const getOpenedModals = () => openedModalsValue;

View File

@@ -224,7 +224,12 @@
category: 'Tabs', category: 'Tabs',
name: 'Close tab', name: 'Close tab',
keyText: isElectronAvailable() ? 'CtrlOrCommand+W' : null, keyText: isElectronAvailable() ? 'CtrlOrCommand+W' : null,
testEnabled: () => getOpenedTabs().filter(x => !x.closedTime).length >= 1, testEnabled: () => {
const hasAnyOtherTab = getOpenedTabs().filter(x => !x.closedTime).length >= 1;
const hasAnyModalOpen = getOpenedModals().length > 0;
return hasAnyOtherTab && !hasConfirmModalOpen;
},
onClick: closeCurrentTab, onClick: closeCurrentTab,
}); });
@@ -283,6 +288,7 @@
draggingDbGroupTarget, draggingDbGroupTarget,
draggingTab, draggingTab,
draggingTabTarget, draggingTabTarget,
getOpenedModals,
} from '../stores'; } from '../stores';
import tabs from '../tabs'; import tabs from '../tabs';
import { setSelectedTab, switchCurrentDatabase } from '../utility/common'; import { setSelectedTab, switchCurrentDatabase } from '../utility/common';