Skip to content

Commit

Permalink
feat: introduce dynamic navItems extension points and remove scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Apr 24, 2024
1 parent 07e75e4 commit a043097
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -14,7 +14,6 @@ export const useExtensionRegistry = defineStore('extensionRegistry', () => {
const requestExtensions = <T extends Extension>(
type: ExtensionType,
options?: {
scopes?: ExtensionScope[]
extensionPointIds?: string[]
}
) => {
Expand All @@ -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)))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 8 additions & 1 deletion packages/web-runtime/src/container/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion packages/web-runtime/src/helpers/navItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const getExtensionNavItems = ({
appId: string
}) =>
extensionRegistry
.requestExtensions<SidebarNavExtension>('sidebarNav', { scopes: [`app.${appId}`] })
.requestExtensions<SidebarNavExtension>('sidebarNav', {
extensionPointIds: [`app.${appId}.navItems`]
})
.map(({ navItem }) => navItem)
.filter((n) => !Object.hasOwn(n, 'isVisible') || n.isVisible())

0 comments on commit a043097

Please sign in to comment.