From eab5f4fe5eda392c3d39f4b26ac280a7e4d7f5fd Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 1 Sep 2022 11:18:25 +0200 Subject: [PATCH] new perspective command --- app/src/mainMenuDefinition.js | 1 + packages/datalib/src/PerspectiveConfig.ts | 11 ++++++++++- packages/web/src/commands/stdCommands.ts | 11 ++++++++++- packages/web/src/query/newQuery.ts | 4 ++++ packages/web/src/tabs/PerspectiveTab.svelte | 12 ++++++++---- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/src/mainMenuDefinition.js b/app/src/mainMenuDefinition.js index a86a569f..8d5e8c02 100644 --- a/app/src/mainMenuDefinition.js +++ b/app/src/mainMenuDefinition.js @@ -8,6 +8,7 @@ module.exports = ({ editMenu }) => [ { command: 'new.query', hideDisabled: true }, { command: 'new.queryDesign', hideDisabled: true }, { command: 'new.diagram', hideDisabled: true }, + { command: 'new.perspective', hideDisabled: true }, { command: 'new.freetable', hideDisabled: true }, { command: 'new.shell', hideDisabled: true }, { command: 'new.jsonl', hideDisabled: true }, diff --git a/packages/datalib/src/PerspectiveConfig.ts b/packages/datalib/src/PerspectiveConfig.ts index 75850885..9fee2e2b 100644 --- a/packages/datalib/src/PerspectiveConfig.ts +++ b/packages/datalib/src/PerspectiveConfig.ts @@ -116,7 +116,16 @@ export function createPerspectiveNodeConfig(name: { schemaName?: string; pureNam return node; } -export function createPerspectiveConfig(rootObject: { schemaName?: string; pureName: string }): PerspectiveConfig { +export function createPerspectiveConfig(rootObject?: { schemaName?: string; pureName: string }): PerspectiveConfig { + if (!rootObject) { + return { + nodes: [], + references: [], + isArranged: true, + rootDesignerId: null, + }; + } + const rootNode = createPerspectiveNodeConfig(rootObject); return { nodes: [rootNode], diff --git a/packages/web/src/commands/stdCommands.ts b/packages/web/src/commands/stdCommands.ts index 4d04aa59..951a6759 100644 --- a/packages/web/src/commands/stdCommands.ts +++ b/packages/web/src/commands/stdCommands.ts @@ -6,7 +6,7 @@ import SettingsModal from '../settings/SettingsModal.svelte'; import ImportExportModal from '../modals/ImportExportModal.svelte'; import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte'; import { showModal } from '../modals/modalTools'; -import newQuery, { newDiagram, newQueryDesign } from '../query/newQuery'; +import newQuery, { newDiagram, newPerspective, newQueryDesign } from '../query/newQuery'; import saveTabFile from '../utility/saveTabFile'; import openNewTab from '../utility/openNewTab'; import getElectron from '../utility/getElectron'; @@ -129,6 +129,15 @@ registerCommand({ onClick: () => newQueryDesign(), }); +registerCommand({ + id: 'new.perspective', + category: 'New', + icon: 'img perspective', + name: 'Perspective', + menuName: 'New perspective', + onClick: () => newPerspective(), +}); + registerCommand({ id: 'new.diagram', category: 'New', diff --git a/packages/web/src/query/newQuery.ts b/packages/web/src/query/newQuery.ts index 8c5c05aa..5aa81082 100644 --- a/packages/web/src/query/newQuery.ts +++ b/packages/web/src/query/newQuery.ts @@ -40,3 +40,7 @@ export function newQueryDesign() { export function newDiagram() { return newQuery({ tabComponent: 'DiagramTab', icon: 'img diagram', title: 'Diagram #' }); } + +export function newPerspective() { + return newQuery({ tabComponent: 'PerspectiveTab', icon: 'img perspective', title: 'Perspective #' }); +} diff --git a/packages/web/src/tabs/PerspectiveTab.svelte b/packages/web/src/tabs/PerspectiveTab.svelte index 83bc004a..1c77835a 100644 --- a/packages/web/src/tabs/PerspectiveTab.svelte +++ b/packages/web/src/tabs/PerspectiveTab.svelte @@ -101,10 +101,14 @@ }); const [modelState, dispatchModel] = createUndoReducer( - createPerspectiveConfig({ - schemaName, - pureName, - }) + createPerspectiveConfig( + pureName + ? { + schemaName, + pureName, + } + : null + ) ); const cache = new PerspectiveCache();