Skip to content

Commit

Permalink
navigate to create workspace/workspaces list page without refreshing (o…
Browse files Browse the repository at this point in the history
…pensearch-project#220)

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
  • Loading branch information
ruanyl committed Oct 12, 2023
1 parent e36a7b6 commit a74a6ee
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ interface StartDeps {
type CollapsibleNavHeaderRender = (context: {
basePath: HttpStart['basePath'];
getUrlForApp: InternalApplicationStart['getUrlForApp'];
navigateToUrl: InternalApplicationStart['navigateToUrl'];
workspaces: WorkspacesStart;
}) => JSX.Element | null;

Expand Down Expand Up @@ -202,6 +203,7 @@ export class ChromeService {
basePath: http.basePath,
workspaces,
getUrlForApp: application.getUrlForApp,
navigateToUrl: application.navigateToUrl,
})
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EuiPopover,
EuiText,
} from '@elastic/eui';
import type { EuiContextMenuPanelItemDescriptor } from '@elastic/eui';

import {
ApplicationStart,
Expand All @@ -32,6 +33,7 @@ import { formatUrlWithWorkspaceId } from '../../utils';

interface Props {
getUrlForApp: ApplicationStart['getUrlForApp'];
navigateToUrl: ApplicationStart['navigateToUrl'];
basePath: HttpSetup['basePath'];
workspaces: WorkspacesStart;
}
Expand All @@ -50,7 +52,7 @@ function getFilteredWorkspaceList(
].slice(0, 5);
}

export const WorkspaceMenu = ({ basePath, getUrlForApp, workspaces }: Props) => {
export const WorkspaceMenu = ({ basePath, getUrlForApp, workspaces, navigateToUrl }: Props) => {
const [isPopoverOpen, setPopover] = useState(false);
const currentWorkspace = useObservable(workspaces.currentWorkspace$, null);
const workspaceList = useObservable(workspaces.workspaceList$, []);
Expand Down Expand Up @@ -103,8 +105,8 @@ export const WorkspaceMenu = ({ basePath, getUrlForApp, workspaces }: Props) =>
};

const getWorkspaceListItems = () => {
const workspaceListItems = filteredWorkspaceList.map((workspace, index) =>
workspaceToItem(workspace, index)
const workspaceListItems: EuiContextMenuPanelItemDescriptor[] = filteredWorkspaceList.map(
(workspace, index) => workspaceToItem(workspace, index)
);
const length = workspaceListItems.length;
workspaceListItems.push({
Expand All @@ -113,27 +115,37 @@ export const WorkspaceMenu = ({ basePath, getUrlForApp, workspaces }: Props) =>
defaultMessage: 'Create workspace',
}),
key: length.toString(),
href: formatUrlWithWorkspaceId(
getUrlForApp(WORKSPACE_CREATE_APP_ID, {
absolute: false,
}),
currentWorkspace?.id ?? '',
basePath
),
onClick: () => {
navigateToUrl(
formatUrlWithWorkspaceId(
getUrlForApp(WORKSPACE_CREATE_APP_ID, {
absolute: false,
}),
currentWorkspace?.id ?? '',
basePath
)
);
setPopover(false);
},
});
workspaceListItems.push({
icon: <EuiIcon type="folderClosed" />,
name: i18n.translate('core.ui.primaryNav.workspaceContextMenu.allWorkspace', {
defaultMessage: 'All workspaces',
}),
key: (length + 1).toString(),
href: formatUrlWithWorkspaceId(
getUrlForApp(WORKSPACE_LIST_APP_ID, {
absolute: false,
}),
currentWorkspace?.id ?? '',
basePath
),
onClick: () => {
navigateToUrl(
formatUrlWithWorkspaceId(
getUrlForApp(WORKSPACE_LIST_APP_ID, {
absolute: false,
}),
currentWorkspace?.id ?? '',
basePath
)
);
setPopover(false);
},
});
return workspaceListItems;
};
Expand Down
11 changes: 10 additions & 1 deletion src/plugins/workspace/public/render_workspace_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ export function renderWorkspaceMenu({
basePath,
getUrlForApp,
workspaces,
navigateToUrl,
}: {
getUrlForApp: ApplicationStart['getUrlForApp'];
basePath: HttpSetup['basePath'];
workspaces: WorkspacesStart;
navigateToUrl: ApplicationStart['navigateToUrl'];
}) {
return <WorkspaceMenu basePath={basePath} getUrlForApp={getUrlForApp} workspaces={workspaces} />;
return (
<WorkspaceMenu
basePath={basePath}
getUrlForApp={getUrlForApp}
workspaces={workspaces}
navigateToUrl={navigateToUrl}
/>
);
}

0 comments on commit a74a6ee

Please sign in to comment.