diff --git a/src/plugins/workspace/public/application.tsx b/src/plugins/workspace/public/application.tsx index 5440d98e6945..83c287357bbe 100644 --- a/src/plugins/workspace/public/application.tsx +++ b/src/plugins/workspace/public/application.tsx @@ -11,12 +11,18 @@ import { WorkspaceFatalError } from './components/workspace_fatal_error'; import { WorkspaceCreatorApp } from './components/workspace_creator_app'; import { WorkspaceUpdaterApp } from './components/workspace_updater_app'; import { WorkspaceListApp } from './components/workspace_list_app'; +import { WorkspaceUpdaterProps } from './components/workspace_updater'; import { Services } from './types'; +import { WorkspaceCreatorProps } from './components/workspace_creator/workspace_creator'; -export const renderCreatorApp = ({ element }: AppMountParameters, services: Services) => { +export const renderCreatorApp = ( + { element }: AppMountParameters, + services: Services, + props: WorkspaceCreatorProps +) => { ReactDOM.render( - + , element ); @@ -26,10 +32,14 @@ export const renderCreatorApp = ({ element }: AppMountParameters, services: Serv }; }; -export const renderUpdaterApp = ({ element }: AppMountParameters, services: Services) => { +export const renderUpdaterApp = ( + { element }: AppMountParameters, + services: Services, + props: WorkspaceUpdaterProps +) => { ReactDOM.render( - + , element ); diff --git a/src/plugins/workspace/public/components/workspace_creator/workspace_creator.test.tsx b/src/plugins/workspace/public/components/workspace_creator/workspace_creator.test.tsx index f5a12df2e43d..1682e24c3025 100644 --- a/src/plugins/workspace/public/components/workspace_creator/workspace_creator.test.tsx +++ b/src/plugins/workspace/public/components/workspace_creator/workspace_creator.test.tsx @@ -94,13 +94,21 @@ describe('WorkspaceCreator', () => { }); it('should not create workspace when name is empty', async () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + ); fireEvent.click(getByTestId('workspaceForm-bottomBar-createButton')); expect(workspaceClientCreate).not.toHaveBeenCalled(); }); it('should not create workspace with invalid name', async () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: '~' }, @@ -109,7 +117,11 @@ describe('WorkspaceCreator', () => { }); it('should not create workspace with invalid description', async () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, @@ -122,7 +134,11 @@ describe('WorkspaceCreator', () => { }); it('cancel create workspace', async () => { - const { findByText, getByTestId } = render(); + const { findByText, getByTestId } = render( + + ); fireEvent.click(getByTestId('workspaceForm-bottomBar-cancelButton')); await findByText('Discard changes?'); fireEvent.click(getByTestId('confirmModalConfirmButton')); @@ -130,7 +146,11 @@ describe('WorkspaceCreator', () => { }); it('create workspace with detailed information', async () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, @@ -162,7 +182,11 @@ describe('WorkspaceCreator', () => { it('create workspace with customized features', async () => { setHrefSpy.mockReset(); - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, @@ -189,7 +213,11 @@ describe('WorkspaceCreator', () => { it('should show danger toasts after create workspace failed', async () => { workspaceClientCreate.mockReturnValueOnce({ result: { id: 'failResult' }, success: false }); - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, @@ -206,7 +234,11 @@ describe('WorkspaceCreator', () => { workspaceClientCreate.mockImplementationOnce(async () => { throw new Error(); }); - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, diff --git a/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx b/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx index 75b598d7aa6d..11d411f6e0d2 100644 --- a/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx +++ b/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx @@ -6,6 +6,10 @@ import React, { useCallback } from 'react'; import { EuiPage, EuiPageBody, EuiPageHeader, EuiPageContent, EuiSpacer } from '@elastic/eui'; import { i18n } from '@osd/i18n'; +import { useObservable } from 'react-use'; +import { BehaviorSubject, of } from 'rxjs'; + +import { PublicAppInfo } from 'opensearch-dashboards/public'; import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public'; import { WorkspaceForm, WorkspaceFormSubmitData, WorkspaceOperationType } from '../workspace_form'; import { WORKSPACE_OVERVIEW_APP_ID } from '../../../common/constants'; @@ -13,10 +17,17 @@ import { formatUrlWithWorkspaceId } from '../../../../../core/public/utils'; import { WorkspaceClient } from '../../workspace_client'; import { convertPermissionSettingsToPermissions } from '../workspace_form'; -export const WorkspaceCreator = () => { +export interface WorkspaceCreatorProps { + workspaceConfigurableApps$?: BehaviorSubject; +} + +export const WorkspaceCreator = (props: WorkspaceCreatorProps) => { const { services: { application, notifications, http, workspaceClient }, } = useOpenSearchDashboards<{ workspaceClient: WorkspaceClient }>(); + const workspaceConfigurableApps = useObservable( + props.workspaceConfigurableApps$ ?? of(undefined) + ); const isPermissionEnabled = application?.capabilities.workspaces.permissionEnabled; const handleWorkspaceFormSubmit = useCallback( @@ -86,6 +97,7 @@ export const WorkspaceCreator = () => { application={application} onSubmit={handleWorkspaceFormSubmit} operationType={WorkspaceOperationType.Create} + workspaceConfigurableApps={workspaceConfigurableApps} permissionEnabled={isPermissionEnabled} permissionLastAdminItemDeletable /> diff --git a/src/plugins/workspace/public/components/workspace_creator_app.tsx b/src/plugins/workspace/public/components/workspace_creator_app.tsx index b74359929352..e384f5d5bfed 100644 --- a/src/plugins/workspace/public/components/workspace_creator_app.tsx +++ b/src/plugins/workspace/public/components/workspace_creator_app.tsx @@ -8,8 +8,9 @@ import { I18nProvider } from '@osd/i18n/react'; import { i18n } from '@osd/i18n'; import { useOpenSearchDashboards } from '../../../opensearch_dashboards_react/public'; import { WorkspaceCreator } from './workspace_creator'; +import { WorkspaceCreatorProps } from './workspace_creator/workspace_creator'; -export const WorkspaceCreatorApp = () => { +export const WorkspaceCreatorApp = (props: WorkspaceCreatorProps) => { const { services: { chrome }, } = useOpenSearchDashboards(); @@ -29,7 +30,7 @@ export const WorkspaceCreatorApp = () => { return ( - + ); }; diff --git a/src/plugins/workspace/public/components/workspace_form/types.ts b/src/plugins/workspace/public/components/workspace_form/types.ts index 95c96fa3e353..33521cc8dcb9 100644 --- a/src/plugins/workspace/public/components/workspace_form/types.ts +++ b/src/plugins/workspace/public/components/workspace_form/types.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import type { ApplicationStart } from '../../../../../core/public'; +import type { ApplicationStart, PublicAppInfo } from '../../../../../core/public'; import type { WorkspacePermissionMode } from '../../../common/constants'; import type { WorkspaceOperationType, WorkspacePermissionItemType } from './constants'; @@ -55,6 +55,7 @@ export interface WorkspaceFormProps { onSubmit?: (formData: WorkspaceFormSubmitData) => void; defaultValues?: WorkspaceFormData; operationType?: WorkspaceOperationType; + workspaceConfigurableApps?: PublicAppInfo[]; permissionEnabled?: boolean; permissionLastAdminItemDeletable?: boolean; } diff --git a/src/plugins/workspace/public/components/workspace_form/utils.test.ts b/src/plugins/workspace/public/components/workspace_form/utils.test.ts index 4531b2979bc1..c2cf46fcf292 100644 --- a/src/plugins/workspace/public/components/workspace_form/utils.test.ts +++ b/src/plugins/workspace/public/components/workspace_form/utils.test.ts @@ -14,35 +14,6 @@ import { WorkspacePermissionMode } from '../../../common/constants'; import { WorkspacePermissionItemType } from './constants'; describe('convertApplicationsToFeaturesOrGroups', () => { - it('should filter out invisible features', () => { - expect( - convertApplicationsToFeaturesOrGroups([ - { id: 'foo1', title: 'Foo 1', navLinkStatus: AppNavLinkStatus.hidden }, - { id: 'foo2', title: 'Foo 2', navLinkStatus: AppNavLinkStatus.visible, chromeless: true }, - { - id: 'foo3', - title: 'Foo 3', - navLinkStatus: AppNavLinkStatus.visible, - category: DEFAULT_APP_CATEGORIES.management, - }, - { - id: 'workspace_overview', - title: 'Workspace Overview', - navLinkStatus: AppNavLinkStatus.visible, - }, - { - id: 'bar', - title: 'Bar', - navLinkStatus: AppNavLinkStatus.visible, - }, - ]) - ).toEqual([ - { - id: 'bar', - name: 'Bar', - }, - ]); - }); it('should group same category applications in same feature group', () => { expect( convertApplicationsToFeaturesOrGroups([ diff --git a/src/plugins/workspace/public/components/workspace_form/utils.ts b/src/plugins/workspace/public/components/workspace_form/utils.ts index a00be1ceaa4e..404314cc652a 100644 --- a/src/plugins/workspace/public/components/workspace_form/utils.ts +++ b/src/plugins/workspace/public/components/workspace_form/utils.ts @@ -5,11 +5,7 @@ import { i18n } from '@osd/i18n'; -import { - AppNavLinkStatus, - DEFAULT_APP_CATEGORIES, - PublicAppInfo, -} from '../../../../../core/public'; +import { PublicAppInfo } from '../../../../../core/public'; import type { SavedObjectPermissions } from '../../../../../core/types'; import { DEFAULT_SELECTED_FEATURES_IDS, WorkspacePermissionMode } from '../../../common/constants'; import { @@ -65,15 +61,6 @@ export const convertApplicationsToFeaturesOrGroups = ( ) => { const UNDEFINED = 'undefined'; - // Filter out all hidden applications and management applications and default selected features - const visibleApplications = applications.filter( - ({ navLinkStatus, chromeless, category, id }) => - navLinkStatus !== AppNavLinkStatus.hidden && - !chromeless && - !DEFAULT_SELECTED_FEATURES_IDS.includes(id) && - category?.id !== DEFAULT_APP_CATEGORIES.management.id - ); - /** * * Convert applications to features map, the map use category label as @@ -81,7 +68,7 @@ export const convertApplicationsToFeaturesOrGroups = ( * transfer application to feature. * **/ - const categoryLabel2Features = visibleApplications.reduce<{ + const categoryLabel2Features = applications.reduce<{ [key: string]: WorkspaceFeature[]; }>((previousValue, application) => { const label = application.category?.label || UNDEFINED; diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.test.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.test.tsx index 0875b0d1ff10..313d459b6018 100644 --- a/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.test.tsx +++ b/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.test.tsx @@ -9,7 +9,7 @@ import { WorkspaceFeatureSelector, WorkspaceFeatureSelectorProps, } from './workspace_feature_selector'; -import { AppNavLinkStatus } from '../../../../../core/public'; +import { AppNavLinkStatus, AppStatus } from '../../../../../core/public'; const setup = (options?: Partial) => { const onChangeMock = jest.fn(); @@ -19,28 +19,36 @@ const setup = (options?: Partial) => { title: 'App 1', category: { id: 'category-1', label: 'Category 1' }, navLinkStatus: AppNavLinkStatus.visible, + status: AppStatus.accessible, + appRoute: '/app-1', }, { id: 'app-2', title: 'App 2', category: { id: 'category-1', label: 'Category 1' }, navLinkStatus: AppNavLinkStatus.visible, + status: AppStatus.accessible, + appRoute: '/app-2', }, { id: 'app-3', title: 'App 3', category: { id: 'category-2', label: 'Category 2' }, navLinkStatus: AppNavLinkStatus.visible, + status: AppStatus.accessible, + appRoute: '/app-3', }, { id: 'app-4', title: 'App 4', navLinkStatus: AppNavLinkStatus.visible, + status: AppStatus.accessible, + appRoute: '/app-4', }, ]; const renderResult = render( - >; selectedFeatures: string[]; onChange: (newFeatures: string[]) => void; + workspaceConfigurableApps?: PublicAppInfo[]; } export const WorkspaceFeatureSelector = ({ - applications, selectedFeatures, onChange, + workspaceConfigurableApps, }: WorkspaceFeatureSelectorProps) => { - const featuresOrGroups = useMemo(() => convertApplicationsToFeaturesOrGroups(applications), [ - applications, - ]); + const featuresOrGroups = useMemo( + () => convertApplicationsToFeaturesOrGroups(workspaceConfigurableApps ?? []), + [workspaceConfigurableApps] + ); const handleFeatureChange = useCallback( (featureId) => { diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_form.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_form.tsx index 274cee6d07d3..de841b09c60e 100644 --- a/src/plugins/workspace/public/components/workspace_form/workspace_form.tsx +++ b/src/plugins/workspace/public/components/workspace_form/workspace_form.tsx @@ -39,7 +39,6 @@ export const WorkspaceForm = (props: WorkspaceFormProps) => { formData, formErrors, selectedTab, - applications, numberOfErrors, handleFormSubmit, handleColorChange, @@ -153,9 +152,9 @@ export const WorkspaceForm = (props: WorkspaceFormProps) => { )} diff --git a/src/plugins/workspace/public/components/workspace_updater/index.tsx b/src/plugins/workspace/public/components/workspace_updater/index.tsx index 711f19fd25f6..b00065a00f64 100644 --- a/src/plugins/workspace/public/components/workspace_updater/index.tsx +++ b/src/plugins/workspace/public/components/workspace_updater/index.tsx @@ -3,4 +3,4 @@ * SPDX-License-Identifier: Apache-2.0 */ -export { WorkspaceUpdater } from './workspace_updater'; +export { WorkspaceUpdater, WorkspaceUpdaterProps } from './workspace_updater'; diff --git a/src/plugins/workspace/public/components/workspace_updater/workspace_updater.test.tsx b/src/plugins/workspace/public/components/workspace_updater/workspace_updater.test.tsx index 142fcfaa61ea..450dfc357db3 100644 --- a/src/plugins/workspace/public/components/workspace_updater/workspace_updater.test.tsx +++ b/src/plugins/workspace/public/components/workspace_updater/workspace_updater.test.tsx @@ -116,12 +116,21 @@ describe('WorkspaceUpdater', () => { it('cannot render when the name of the current workspace is empty', async () => { const mockedWorkspacesService = workspacesServiceMock.createSetupContract(); - const { container } = render(); + const { container } = render( + + ); expect(container).toMatchInlineSnapshot(`
`); }); it('cannot update workspace with invalid name', async () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: '~' }, @@ -130,7 +139,11 @@ describe('WorkspaceUpdater', () => { }); it('cannot update workspace with invalid description', async () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, @@ -143,7 +156,11 @@ describe('WorkspaceUpdater', () => { }); it('cancel update workspace', async () => { - const { findByText, getByTestId } = render(); + const { findByText, getByTestId } = render( + + ); fireEvent.click(getByTestId('workspaceForm-bottomBar-cancelButton')); await findByText('Discard changes?'); fireEvent.click(getByTestId('confirmModalConfirmButton')); @@ -151,7 +168,11 @@ describe('WorkspaceUpdater', () => { }); it('update workspace successfully', async () => { - const { getByTestId, getByText, getAllByText } = render(); + const { getByTestId, getByText, getAllByText } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, @@ -210,7 +231,11 @@ describe('WorkspaceUpdater', () => { it('should show danger toasts after update workspace failed', async () => { workspaceClientUpdate.mockReturnValue({ result: false, success: false }); - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, @@ -227,7 +252,11 @@ describe('WorkspaceUpdater', () => { workspaceClientUpdate.mockImplementation(() => { throw new Error('update workspace failed'); }); - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { target: { value: 'test workspace name' }, @@ -242,7 +271,12 @@ describe('WorkspaceUpdater', () => { it('should show danger toasts when currentWorkspace is missing after click update button', async () => { const mockedWorkspacesService = workspacesServiceMock.createSetupContract(); - const { getByTestId } = render(); + const { getByTestId } = render( + + ); const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText'); fireEvent.input(nameInput, { diff --git a/src/plugins/workspace/public/components/workspace_updater/workspace_updater.tsx b/src/plugins/workspace/public/components/workspace_updater/workspace_updater.tsx index 201175c11c8e..950d778fff96 100644 --- a/src/plugins/workspace/public/components/workspace_updater/workspace_updater.tsx +++ b/src/plugins/workspace/public/components/workspace_updater/workspace_updater.tsx @@ -6,8 +6,9 @@ import React, { useCallback, useEffect, useState } from 'react'; import { EuiPage, EuiPageBody, EuiPageHeader, EuiPageContent } from '@elastic/eui'; import { i18n } from '@osd/i18n'; +import { PublicAppInfo } from 'opensearch-dashboards/public'; import { useObservable } from 'react-use'; -import { of } from 'rxjs'; +import { BehaviorSubject, of } from 'rxjs'; import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public'; import { WORKSPACE_OVERVIEW_APP_ID } from '../../../common/constants'; import { formatUrlWithWorkspaceId } from '../../../../../core/public/utils'; @@ -21,6 +22,10 @@ import { convertPermissionSettingsToPermissions, } from '../workspace_form'; +export interface WorkspaceUpdaterProps { + workspaceConfigurableApps$?: BehaviorSubject; +} + function getFormDataFromWorkspace( currentWorkspace: WorkspaceAttributeWithPermission | null | undefined ) { @@ -35,13 +40,16 @@ function getFormDataFromWorkspace( }; } -export const WorkspaceUpdater = () => { +export const WorkspaceUpdater = (props: WorkspaceUpdaterProps) => { const { services: { application, workspaces, notifications, http, workspaceClient }, } = useOpenSearchDashboards<{ workspaceClient: WorkspaceClient }>(); const isPermissionEnabled = application?.capabilities.workspaces.permissionEnabled; const currentWorkspace = useObservable(workspaces ? workspaces.currentWorkspace$ : of(null)); + const workspaceConfigurableApps = useObservable( + props.workspaceConfigurableApps$ ?? of(undefined) + ); const [currentWorkspaceFormData, setCurrentWorkspaceFormData] = useState( getFormDataFromWorkspace(currentWorkspace) ); @@ -126,6 +134,7 @@ export const WorkspaceUpdater = () => { defaultValues={currentWorkspaceFormData} onSubmit={handleWorkspaceFormSubmit} operationType={WorkspaceOperationType.Update} + workspaceConfigurableApps={workspaceConfigurableApps} permissionEnabled={isPermissionEnabled} permissionLastAdminItemDeletable={false} /> diff --git a/src/plugins/workspace/public/components/workspace_updater_app.tsx b/src/plugins/workspace/public/components/workspace_updater_app.tsx index e16c9ad72e0f..ab106b5c4b7a 100644 --- a/src/plugins/workspace/public/components/workspace_updater_app.tsx +++ b/src/plugins/workspace/public/components/workspace_updater_app.tsx @@ -7,9 +7,9 @@ import React, { useEffect } from 'react'; import { I18nProvider } from '@osd/i18n/react'; import { i18n } from '@osd/i18n'; import { useOpenSearchDashboards } from '../../../opensearch_dashboards_react/public'; -import { WorkspaceUpdater } from './workspace_updater'; +import { WorkspaceUpdater, WorkspaceUpdaterProps } from './workspace_updater'; -export const WorkspaceUpdaterApp = () => { +export const WorkspaceUpdaterApp = (props: WorkspaceUpdaterProps) => { const { services: { chrome }, } = useOpenSearchDashboards(); @@ -29,7 +29,7 @@ export const WorkspaceUpdaterApp = () => { return ( - + ); }; diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 2155eabea84b..abd5fdadbabc 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -6,6 +6,7 @@ import { BehaviorSubject, Subscription } from 'rxjs'; import React from 'react'; import { i18n } from '@osd/i18n'; +import { first } from 'rxjs/operators'; import { Plugin, CoreStart, @@ -14,6 +15,7 @@ import { AppNavLinkStatus, AppUpdater, AppStatus, + PublicAppInfo, } from '../../../core/public'; import { WORKSPACE_FATAL_ERROR_APP_ID, @@ -29,9 +31,13 @@ import { SavedObjectsManagementPluginSetup } from '../../../plugins/saved_object import { ManagementSetup } from '../../../plugins/management/public'; import { WorkspaceMenu } from './components/workspace_menu/workspace_menu'; import { getWorkspaceColumn } from './components/workspace_column'; -import { isAppAccessibleInWorkspace } from './utils'; +import { filterWorkspaceConfigurableApps, isAppAccessibleInWorkspace } from './utils'; -type WorkspaceAppType = (params: AppMountParameters, services: Services) => () => void; +type WorkspaceAppType = ( + params: AppMountParameters, + services: Services, + props: Record +) => () => void; interface WorkspacePluginSetupDeps { savedObjectsManagement?: SavedObjectsManagementPluginSetup; @@ -44,6 +50,7 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> private currentWorkspaceIdSubscription?: Subscription; private managementCurrentWorkspaceIdSubscription?: Subscription; private appUpdater$ = new BehaviorSubject(() => undefined); + private workspaceConfigurableApps$ = new BehaviorSubject([]); private _changeSavedObjectCurrentWorkspace() { if (this.coreStart) { return this.coreStart.workspaces.currentWorkspaceId$.subscribe((currentWorkspaceId) => { @@ -58,7 +65,7 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> * Filter nav links by the current workspace, once the current workspace change, the nav links(left nav bar) * should also be updated according to the configured features of the current workspace */ - private filterNavLinks(core: CoreStart) { + private filterNavLinks = (core: CoreStart) => { const currentWorkspace$ = core.workspaces.currentWorkspace$; this.currentWorkspaceSubscription?.unsubscribe(); @@ -68,6 +75,11 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> if (isAppAccessibleInWorkspace(app, currentWorkspace)) { return; } + + if (app.status === AppStatus.inaccessible) { + return; + } + /** * Change the app to `inaccessible` if it is not configured in the workspace * If trying to access such app, an "Application Not Found" page will be displayed @@ -76,7 +88,20 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> }); } }); - } + }; + + /** + * Initiate an observable with the value of all applications which can be configured by workspace + */ + private setWorkspaceConfigurableApps = async (core: CoreStart) => { + const allApps = await new Promise((resolve) => { + core.application.applications$.pipe(first()).subscribe((apps) => { + resolve([...apps.values()]); + }); + }); + const availableApps = filterWorkspaceConfigurableApps(allApps); + this.workspaceConfigurableApps$.next(availableApps); + }; /** * If workspace is enabled and user has entered workspace, hide advance settings and dataSource menu by disabling the corresponding apps. @@ -158,7 +183,9 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> workspaceClient, }; - return renderApp(params, services); + return renderApp(params, services, { + workspaceConfigurableApps$: this.workspaceConfigurableApps$, + }); }; // create @@ -232,8 +259,10 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> this.currentWorkspaceIdSubscription = this._changeSavedObjectCurrentWorkspace(); - // When starts, filter the nav links based on the current workspace - this.filterNavLinks(core); + this.setWorkspaceConfigurableApps(core).then(() => { + // filter the nav links based on the current workspace + this.filterNavLinks(core); + }); return {}; } diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index e70a26028525..dd0cb8275469 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -3,7 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { App, AppCategory, AppNavLinkStatus, WorkspaceObject } from '../../../core/public'; +import { + App, + AppCategory, + AppNavLinkStatus, + DEFAULT_APP_CATEGORIES, + PublicAppInfo, + WorkspaceObject, +} from '../../../core/public'; +import { DEFAULT_SELECTED_FEATURES_IDS } from '../common/constants'; /** * Checks if a given feature matches the provided feature configuration. @@ -99,3 +107,16 @@ export function isAppAccessibleInWorkspace(app: App, workspace: WorkspaceObject) } return false; } + +export const filterWorkspaceConfigurableApps = (applications: PublicAppInfo[]) => { + const visibleApplications = applications.filter(({ navLinkStatus, chromeless, category, id }) => { + return ( + navLinkStatus !== AppNavLinkStatus.hidden && + !chromeless && + !DEFAULT_SELECTED_FEATURES_IDS.includes(id) && + category?.id !== DEFAULT_APP_CATEGORIES.management.id + ); + }); + + return visibleApplications; +};