@@ -51,6 +51,7 @@ import { HttpStart } from '../../../http';
51
51
import { OnIsLockedUpdate } from './' ;
52
52
import { createEuiListItem , createRecentNavLink , isModifiedOrPrevented } from './nav_link' ;
53
53
import { ChromeBranding } from '../../chrome_service' ;
54
+ import { WorkspaceAttribute } from '../../../workspace' ;
54
55
55
56
function getAllCategories ( allCategorizedLinks : Record < string , ChromeNavLink [ ] > ) {
56
57
const allCategories = { } as Record < string , AppCategory | undefined > ;
@@ -102,6 +103,7 @@ interface Props {
102
103
navigateToUrl : InternalApplicationStart [ 'navigateToUrl' ] ;
103
104
customNavLink$ : Rx . Observable < ChromeNavLink | undefined > ;
104
105
branding : ChromeBranding ;
106
+ currentWorkspace$ : Rx . BehaviorSubject < WorkspaceAttribute | null > ;
105
107
}
106
108
107
109
export function CollapsibleNav ( {
@@ -122,11 +124,14 @@ export function CollapsibleNav({
122
124
const recentlyAccessed = useObservable ( observables . recentlyAccessed$ , [ ] ) ;
123
125
const customNavLink = useObservable ( observables . customNavLink$ , undefined ) ;
124
126
const appId = useObservable ( observables . appId$ , '' ) ;
127
+ const currentWorkspace = useObservable ( observables . currentWorkspace$ ) ;
125
128
const lockRef = useRef < HTMLButtonElement > ( null ) ;
126
129
const groupedNavLinks = groupBy ( navLinks , ( link ) => link ?. category ?. id ) ;
127
130
const { undefined : unknowns = [ ] , ...allCategorizedLinks } = groupedNavLinks ;
128
- const categoryDictionary = getAllCategories ( allCategorizedLinks ) ;
129
- const orderedCategories = getOrderedCategories ( allCategorizedLinks , categoryDictionary ) ;
131
+ const filterdLinks = getFilterLinks ( currentWorkspace , allCategorizedLinks ) ;
132
+ const categoryDictionary = getAllCategories ( filterdLinks ) ;
133
+ const orderedCategories = getOrderedCategories ( filterdLinks , categoryDictionary ) ;
134
+
130
135
const readyForEUI = ( link : ChromeNavLink , needsIcon : boolean = false ) => {
131
136
return createEuiListItem ( {
132
137
link,
@@ -145,6 +150,24 @@ export function CollapsibleNav({
145
150
const markDefault = branding . mark ?. defaultUrl ;
146
151
const markDarkMode = branding . mark ?. darkModeUrl ;
147
152
153
+ function getFilterLinks (
154
+ workspace : WorkspaceAttribute | null | undefined ,
155
+ categorizedLinks : Record < string , ChromeNavLink [ ] >
156
+ ) {
157
+ // plugins are in this dictionary
158
+ const pluginsDictionary = categorizedLinks . opensearch ;
159
+ if ( ! pluginsDictionary ) return categorizedLinks ;
160
+
161
+ const features = workspace ?. features ?? [ ] ;
162
+ const newPluginsDictionary = pluginsDictionary . filter ( ( item ) => features . indexOf ( item . id ) > - 1 ) ;
163
+ if ( newPluginsDictionary . length === 0 ) {
164
+ delete categorizedLinks . opensearch ;
165
+ } else {
166
+ categorizedLinks . opensearch = newPluginsDictionary ;
167
+ }
168
+ return categorizedLinks ;
169
+ }
170
+
148
171
/**
149
172
* Use branding configurations to check which URL to use for rendering
150
173
* side menu opensearch logo in default mode
0 commit comments