Skip to content

Commit

Permalink
navigates to use case overview page
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Aug 17, 2024
1 parent 389ad1b commit 0525ec8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import {
import { i18n } from '@osd/i18n';
import moment from 'moment';
import { orderBy } from 'lodash';
import { CoreStart, WorkspaceObject } from '../../../../../core/public';
import { navigateToWorkspaceDetail } from '../utils/workspace';
import { useObservable } from 'react-use';
import { CoreStart, WorkspaceAvailability, WorkspaceObject } from '../../../../../core/public';

import { WORKSPACE_CREATE_APP_ID, WORKSPACE_LIST_APP_ID } from '../../../common/constants';
import { recentWorkspaceManager } from '../../recent_workspace_manager';
import { getFirstUseCaseOfFeatureConfigs } from '../../utils';
import { navigateToAppWithinWorkspace } from '../utils/workspace';

const WORKSPACE_LIST_CARD_DESCRIPTION = i18n.translate('workspace.list.card.description', {
defaultMessage:
Expand All @@ -42,6 +44,7 @@ export interface WorkspaceListCardProps {
export const WorkspaceListCard = (props: WorkspaceListCardProps) => {
const [availableWorkspaces, setAvailableWorkspaces] = useState<WorkspaceObject[]>([]);
const [filter, setFilter] = useState('viewed');
const navGroups = useObservable(props.core.chrome.navGroup.getNavGroupsMap$());

useEffect(() => {
const workspaceSub = props.core.workspaces.workspaceList$.subscribe((list) => {
Expand Down Expand Up @@ -77,8 +80,15 @@ export const WorkspaceListCard = (props: WorkspaceListCardProps) => {

const handleSwitchWorkspace = (id: string) => {
const { application, http } = props.core;
if (application && http) {
navigateToWorkspaceDetail({ application, http }, id);
const workspaceObj = availableWorkspaces.find((item) => item.id === id);
const useCase = getFirstUseCaseOfFeatureConfigs(workspaceObj?.features || []);
if (useCase && navGroups) {
// should be workspace use case overview page
const availableLinks = navGroups[useCase].navLinks?.filter(
(navLink) => navLink.workspaceAvailability !== WorkspaceAvailability.outsideWorkspace
);
const appId = availableLinks?.[0].id;
navigateToAppWithinWorkspace({ application, http }, id, appId);
}
};

Expand Down
22 changes: 19 additions & 3 deletions src/plugins/workspace/public/components/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,33 @@ export const navigateToWorkspaceDetail = (
{ application, http }: Core,
id: string,
tabId: string = DetailTab.Details
) => {
navigateToAppWithinWorkspace(
{ application, http },
id,
WORKSPACE_DETAIL_APP_ID,
`/?tab=${tabId}`
);
};

export const navigateToAppWithinWorkspace = (
{ application, http }: Core,
workspaceId: string,
appId: string,
hash?: string
) => {
const newUrl = formatUrlWithWorkspaceId(
application.getUrlForApp(WORKSPACE_DETAIL_APP_ID, {
application.getUrlForApp(appId, {
absolute: true,
}),
id,
workspaceId,
http.basePath
);
if (newUrl) {
const url = new URL(newUrl);
url.hash = `/?tab=${tabId}`;
if (hash) {
url.hash = hash;
}
application.navigateToUrl(url.toString());
}
};

0 comments on commit 0525ec8

Please sign in to comment.