From 8c7526981fabd03dc118db79d987da5cc29b3034 Mon Sep 17 00:00:00 2001 From: Martyn Janes Date: Mon, 8 Jan 2024 09:55:37 +0200 Subject: [PATCH] Allow recursive submenus --- .../client/src/framework/workspace/dock.ts | 18 +++++++++++---- .../public/manifest.fin.json | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/how-to/workspace-platform-starter/client/src/framework/workspace/dock.ts b/how-to/workspace-platform-starter/client/src/framework/workspace/dock.ts index 692e772e28..26482ad0ad 100644 --- a/how-to/workspace-platform-starter/client/src/framework/workspace/dock.ts +++ b/how-to/workspace-platform-starter/client/src/framework/workspace/dock.ts @@ -227,7 +227,7 @@ async function buildButtonsFromEntries( } else if ("action" in entry) { await addEntryAsAction(buttons, entry, iconFolder, colorSchemeMode, isTopLevel); } else if ("options" in entry) { - await addEntriesAsDropdown(buttons, entry, iconFolder, colorSchemeMode, platform); + await addEntriesAsDropdown(buttons, entry, iconFolder, colorSchemeMode, isTopLevel, platform); } else if ("tags" in entry) { await addEntriesByAppTag(buttons, entry, iconFolder, colorSchemeMode); } @@ -319,6 +319,7 @@ async function addEntryAsAction( * @param entry The entry details. * @param iconFolder The folder for icons. * @param colorSchemeMode The color scheme + * @param isTopLevel Is this a top level entry. * @param platform The workspace platform for checking conditions. */ async function addEntriesAsDropdown( @@ -326,12 +327,15 @@ async function addEntriesAsDropdown( entry: DockButtonDropdown, iconFolder: string, colorSchemeMode: ColorSchemeMode, + isTopLevel: boolean, platform: WorkspacePlatformModule ): Promise { // Options are present so this is a drop down // The items in the drop down can be an appId or a custom action - if (!isStringValue(entry.tooltip) || !isStringValue(entry.iconUrl)) { - logger.error("You must specify the tooltip and iconUrl for a DockButtonDropdown"); + if (!isStringValue(entry.tooltip)) { + logger.error("You must specify the tooltip for a DockButtonDropdown"); + } else if (isTopLevel && !isStringValue(entry.iconUrl)) { + logger.error("You must specify the iconUrl for a DockButtonDropdown"); } else { const opts: (CustomButtonConfig | CustomDropdownConfig)[] = []; @@ -351,7 +355,7 @@ async function addEntriesAsDropdown( let optionTooltip = option.tooltip; let action: CustomActionSpecifier | undefined; let iconUrl; - let subOptions: CustomButtonConfig[] | undefined; + let subOptions: (CustomButtonConfig | CustomDropdownConfig)[] | undefined; // If there are options this is a submenu if ("options" in option) { @@ -367,7 +371,11 @@ async function addEntriesAsDropdown( action: dockButton.action }); } else if (dockButton.type === DockButtonNames.DropdownButton) { - // Only single level of nesting supported + subOptions.push({ + tooltip: dockButton.tooltip, + iconUrl: dockButton.iconUrl, + options: dockButton.options + }); } } } else if ("appId" in option) { diff --git a/how-to/workspace-platform-starter/public/manifest.fin.json b/how-to/workspace-platform-starter/public/manifest.fin.json index d35cf8a439..d2cdbafedc 100644 --- a/how-to/workspace-platform-starter/public/manifest.fin.json +++ b/how-to/workspace-platform-starter/public/manifest.fin.json @@ -989,6 +989,29 @@ "url": "https://github.com/openfin" } } + }, + { + "tooltip": "Search", + "options": [ + { + "tooltip": "Google", + "action": { + "id": "launch-view", + "customData": { + "url": "https://www.google.com/search?q=openfin" + } + } + }, + { + "tooltip": "Bing", + "action": { + "id": "launch-view", + "customData": { + "url": "https://www.bing.com/search?q=openfin" + } + } + } + ] } ] }