From 0dcdfc69ff0f0bfd332abec3da7f6aa9dbde5758 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 9 Oct 2022 20:50:59 -0700 Subject: [PATCH] Toolbar actions buttons are dissabled until maps is created. --- .../editor/src/classes/model/editor/index.ts | 4 ++++ packages/editor/src/components/index.tsx | 2 +- .../toolbar/toolbarConfigBuilder.tsx | 22 ++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/editor/src/classes/model/editor/index.ts b/packages/editor/src/classes/model/editor/index.ts index ba19faa2..7fc18a7c 100644 --- a/packages/editor/src/classes/model/editor/index.ts +++ b/packages/editor/src/classes/model/editor/index.ts @@ -24,6 +24,10 @@ class Editor { this.component = mindplotComponent; } + isMapLoadded(): boolean { + return this.component.getDesigner()?.getMindmap() != null; + } + save(minor: boolean) { this.component.save(minor); } diff --git a/packages/editor/src/components/index.tsx b/packages/editor/src/components/index.tsx index 61ca9209..185a64a5 100644 --- a/packages/editor/src/components/index.tsx +++ b/packages/editor/src/components/index.tsx @@ -81,7 +81,7 @@ const Editor = ({ const msg = I18nMsg.loadLocaleData(locale); const menubarConfiguration = buildAppBarConfig( - model?.getDesigner(), + model, options.mapTitle, capability, onAction, diff --git a/packages/editor/src/components/toolbar/toolbarConfigBuilder.tsx b/packages/editor/src/components/toolbar/toolbarConfigBuilder.tsx index 5ba07b3f..6061b3bf 100644 --- a/packages/editor/src/components/toolbar/toolbarConfigBuilder.tsx +++ b/packages/editor/src/components/toolbar/toolbarConfigBuilder.tsx @@ -48,6 +48,7 @@ import TopicNote from '../action-widget/pane/topic-note'; import IconPicker from '../action-widget/pane/icon-picker'; import FontFamilySelector from '../action-widget/button/font-family-selector'; import Capability from '../../classes/action/capability'; +import Editor from '../../classes/model/editor'; export type ToolbarActionType = 'export' | 'publish' | 'history' | 'print' | 'share' | 'info'; @@ -348,18 +349,18 @@ export function buildZoomToolbarConfig(capability: Capability, designer: Designe } export function buildAppBarConfig( - designer: Designer, + model: Editor, mapTitle: string, capability: Capability, onAction: (type: ToolbarActionType) => void, accountConfiguration, save: () => void, ): ActionConfig[] { - if (!designer) { - return []; - } + const appBarDivisor = { + render: () => , + }; - let commonConfiguration: ActionConfig[] = [ + return [ { icon: , tooltip: $msg('BACK_TO_MAP_LIST'), @@ -382,14 +383,6 @@ export function buildAppBarConfig( ), }, - ]; - - const appBarDivisor = { - render: () => , - }; - - return [ - ...commonConfiguration, null, { render: () => ( @@ -403,6 +396,7 @@ export function buildAppBarConfig( > ), visible: !capability.isHidden('undo-changes'), + disabled: () => !model?.isMapLoadded(), }, { render: () => ( @@ -416,6 +410,7 @@ export function buildAppBarConfig( > ), visible: !capability.isHidden('redo-changes'), + disabled: () => !model?.isMapLoadded(), }, null, { @@ -423,6 +418,7 @@ export function buildAppBarConfig( tooltip: $msg('SAVE') + ' (' + $msg('CTRL') + ' + S)', onClick: save, visible: !capability.isHidden('save'), + disabled: () => !model?.isMapLoadded(), }, { icon: ,