From f177a61d4f965fc17d888f2d7351f9dc3e8ed8f8 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 11 Jul 2022 15:09:47 +0200 Subject: [PATCH] Hide template button if disabled --- src/commands/Content.ts | 1 + .../components/ChoiceButton.tsx | 65 ++++++++++--------- .../components/Header/Header.tsx | 1 + src/dashboardWebView/hooks/useMessages.tsx | 2 - src/dashboardWebView/models/Settings.ts | 1 + src/helpers/DashboardSettings.ts | 3 +- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/commands/Content.ts b/src/commands/Content.ts index 0c3f0159..c3d982fe 100644 --- a/src/commands/Content.ts +++ b/src/commands/Content.ts @@ -8,6 +8,7 @@ export class Content { const templatesEnabled = await Settings.get(SETTING_TEMPLATES_ENABLED); if (!templatesEnabled) { commands.executeCommand(COMMAND_NAME.createByContentType); + return; } const options: QuickPickItem[] = [{ diff --git a/src/dashboardWebView/components/ChoiceButton.tsx b/src/dashboardWebView/components/ChoiceButton.tsx index 84929f4d..323700e8 100644 --- a/src/dashboardWebView/components/ChoiceButton.tsx +++ b/src/dashboardWebView/components/ChoiceButton.tsx @@ -12,10 +12,11 @@ export interface IChoiceButtonProps { onClick: () => void; }[]; disabled?: boolean; + isTemplatesEnabled?: boolean; onClick: () => void; } -export const ChoiceButton: React.FunctionComponent = ({onClick, disabled, choices, title}: React.PropsWithChildren) => { +export const ChoiceButton: React.FunctionComponent = ({onClick, disabled, choices, isTemplatesEnabled, title}: React.PropsWithChildren) => { return ( - - - Open options - + { + isTemplatesEnabled && ( + + + Open options + - -
- {choices.map((choice, idx) => ( - - {choice.icon} - {choice.title} -
- ) : ( - choice.title - ) - )} - value={null} - onClick={choice.onClick} - disabled={choice.disabled} /> - ))} - -
-
+ +
+ {choices.map((choice, idx) => ( + + {choice.icon} + {choice.title} +
+ ) : ( + choice.title + ) + )} + value={null} + onClick={choice.onClick} + disabled={choice.disabled} /> + ))} + +
+
+ ) + }
); }; \ No newline at end of file diff --git a/src/dashboardWebView/components/Header/Header.tsx b/src/dashboardWebView/components/Header/Header.tsx index b44af033..4ad2920d 100644 --- a/src/dashboardWebView/components/Header/Header.tsx +++ b/src/dashboardWebView/components/Header/Header.tsx @@ -134,6 +134,7 @@ export const Header: React.FunctionComponent = ({header, totalPage ...customActions ]} onClick={createContent} + isTemplatesEnabled={settings?.dashboardState?.contents?.templatesEnabled || undefined} disabled={!settings?.initialized} /> diff --git a/src/dashboardWebView/hooks/useMessages.tsx b/src/dashboardWebView/hooks/useMessages.tsx index 80cd7d06..7d7c83c5 100644 --- a/src/dashboardWebView/hooks/useMessages.tsx +++ b/src/dashboardWebView/hooks/useMessages.tsx @@ -21,8 +21,6 @@ export default function useMessages() { Messenger.listen((event: MessageEvent>) => { const message = event.data; - console.log(`Received message:`, message); - switch (message.command) { case DashboardCommand.loading: setLoading(message.data); diff --git a/src/dashboardWebView/models/Settings.ts b/src/dashboardWebView/models/Settings.ts index f03e4e8e..d9d94ae9 100644 --- a/src/dashboardWebView/models/Settings.ts +++ b/src/dashboardWebView/models/Settings.ts @@ -42,6 +42,7 @@ export interface ContentsViewState { sorting: SortingOption | null | undefined; defaultSorting: string | null | undefined; tags: string | null | undefined; + templatesEnabled: boolean | null | undefined; } export interface MediaViewState extends ContentsViewState { diff --git a/src/helpers/DashboardSettings.ts b/src/helpers/DashboardSettings.ts index 8ab0f120..a071bdc6 100644 --- a/src/helpers/DashboardSettings.ts +++ b/src/helpers/DashboardSettings.ts @@ -2,7 +2,7 @@ import { basename, join } from "path"; import { workspace } from "vscode"; import { Folders } from "../commands/Folders"; import { Project } from "../commands/Project"; -import { CONTEXT, ExtensionState, SETTING_CONTENT_DRAFT_FIELD, SETTING_CONTENT_SORTING, SETTING_CONTENT_SORTING_DEFAULT, SETTING_DASHBOARD_OPENONSTART, SETTING_DATA_FILES, SETTING_DATA_FOLDERS, SETTING_DATA_TYPES, SETTING_FRAMEWORK_ID, SETTING_MEDIA_SORTING_DEFAULT, SETTING_CUSTOM_SCRIPTS, SETTING_TAXONOMY_CONTENT_TYPES, SETTING_CONTENT_SNIPPETS, SETTING_DATE_FORMAT, SETTING_DASHBOARD_CONTENT_TAGS, SETTING_MEDIA_SUPPORTED_MIMETYPES, SETTING_TAXONOMY_CUSTOM } from "../constants"; +import { CONTEXT, ExtensionState, SETTING_CONTENT_DRAFT_FIELD, SETTING_CONTENT_SORTING, SETTING_CONTENT_SORTING_DEFAULT, SETTING_DASHBOARD_OPENONSTART, SETTING_DATA_FILES, SETTING_DATA_FOLDERS, SETTING_DATA_TYPES, SETTING_FRAMEWORK_ID, SETTING_MEDIA_SORTING_DEFAULT, SETTING_CUSTOM_SCRIPTS, SETTING_TAXONOMY_CONTENT_TYPES, SETTING_CONTENT_SNIPPETS, SETTING_DATE_FORMAT, SETTING_DASHBOARD_CONTENT_TAGS, SETTING_MEDIA_SUPPORTED_MIMETYPES, SETTING_TAXONOMY_CUSTOM, SETTING_TEMPLATES_ENABLED } from "../constants"; import { DashboardViewType, SortingOption, Settings as ISettings } from "../dashboardWebView/models"; import { CustomScript, DraftField, Snippets, SortingSetting, TaxonomyType } from "../models"; import { DataFile } from "../models/DataFile"; @@ -46,6 +46,7 @@ export class DashboardSettings { sorting: await ext.getState(ExtensionState.Dashboard.Contents.Sorting, "workspace"), defaultSorting: Settings.get(SETTING_CONTENT_SORTING_DEFAULT), tags: Settings.get(SETTING_DASHBOARD_CONTENT_TAGS), + templatesEnabled: Settings.get(SETTING_TEMPLATES_ENABLED) }, media: { sorting: await ext.getState(ExtensionState.Dashboard.Media.Sorting, "workspace"),