From a04309771727e8789375cae295149cee1c140693 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Wed, 24 Apr 2024 05:46:02 +0200 Subject: [PATCH] feat: introduce dynamic navItems extension points and remove scopes --- .../piniaStores/extensionRegistry/extensionRegistry.ts | 4 +--- .../composables/piniaStores/extensionRegistry/types.ts | 3 --- packages/web-runtime/src/container/api.ts | 9 ++++++++- packages/web-runtime/src/helpers/navItems.ts | 4 +++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/web-pkg/src/composables/piniaStores/extensionRegistry/extensionRegistry.ts b/packages/web-pkg/src/composables/piniaStores/extensionRegistry/extensionRegistry.ts index eaa888b3a73..2ced890ef3a 100644 --- a/packages/web-pkg/src/composables/piniaStores/extensionRegistry/extensionRegistry.ts +++ b/packages/web-pkg/src/composables/piniaStores/extensionRegistry/extensionRegistry.ts @@ -1,7 +1,7 @@ import { defineStore } from 'pinia' import { ref, Ref, unref } from 'vue' import { useConfigStore } from '../config' -import { Extension, ExtensionPoint, ExtensionScope, ExtensionType } from './types' +import { Extension, ExtensionPoint, ExtensionType } from './types' export const useExtensionRegistry = defineStore('extensionRegistry', () => { const configStore = useConfigStore() @@ -14,7 +14,6 @@ export const useExtensionRegistry = defineStore('extensionRegistry', () => { const requestExtensions = ( type: ExtensionType, options?: { - scopes?: ExtensionScope[] extensionPointIds?: string[] } ) => { @@ -23,7 +22,6 @@ export const useExtensionRegistry = defineStore('extensionRegistry', () => { (e) => e.type === type && !configStore.options.disabledExtensions.includes(e.id) && - (!options?.scopes || e.scopes?.some((s) => options?.scopes.includes(s))) && (!options?.extensionPointIds || e.extensionPointIds?.some((id) => options?.extensionPointIds.includes(id))) ) diff --git a/packages/web-pkg/src/composables/piniaStores/extensionRegistry/types.ts b/packages/web-pkg/src/composables/piniaStores/extensionRegistry/types.ts index 45e21c34f6d..0cc0e4bae25 100644 --- a/packages/web-pkg/src/composables/piniaStores/extensionRegistry/types.ts +++ b/packages/web-pkg/src/composables/piniaStores/extensionRegistry/types.ts @@ -10,13 +10,10 @@ export type ExtensionType = StringUnionOrAnyString< 'action' | 'customComponent' | 'folderView' | 'search' | 'sidebarNav' | 'sidebarPanel' > -export type ExtensionScope = StringUnionOrAnyString<'resource' | 'user' | 'group'> - export type BaseExtension = { id: string type: ExtensionType extensionPointIds?: string[] - scopes?: ExtensionScope[] // TODO: deprecated userPreference?: { optionLabel?: string } diff --git a/packages/web-runtime/src/container/api.ts b/packages/web-runtime/src/container/api.ts index 7c46d947c2a..8e57f8da2a1 100644 --- a/packages/web-runtime/src/container/api.ts +++ b/packages/web-runtime/src/container/api.ts @@ -72,11 +72,18 @@ const announceNavigationItems = ( throw new ApiError("navigationItems can't be blank") } + const navExtensionPoint = { + id: `app.${applicationId}.navItems`, + extensionType: 'sidebarNav', + multiple: true + } + extensionRegistry.registerExtensionPoint(navExtensionPoint) + const navExtensions = navigationItems.map((navItem) => ({ id: `app.${applicationId}.${navItem.name}`, type: 'sidebarNav', navItem, - scopes: [`app.${applicationId}`] + extensionPointIds: [navExtensionPoint.id] })) as SidebarNavExtension[] extensionRegistry.registerExtensions(computed(() => navExtensions)) diff --git a/packages/web-runtime/src/helpers/navItems.ts b/packages/web-runtime/src/helpers/navItems.ts index 50dba333b09..05a9378253a 100644 --- a/packages/web-runtime/src/helpers/navItems.ts +++ b/packages/web-runtime/src/helpers/navItems.ts @@ -13,6 +13,8 @@ export const getExtensionNavItems = ({ appId: string }) => extensionRegistry - .requestExtensions('sidebarNav', { scopes: [`app.${appId}`] }) + .requestExtensions('sidebarNav', { + extensionPointIds: [`app.${appId}.navItems`] + }) .map(({ navItem }) => navItem) .filter((n) => !Object.hasOwn(n, 'isVisible') || n.isVisible())