2021-11-02 22:10:53 +00:00
|
|
|
import React, { FunctionComponent, ReactNode, useCallback } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
2021-07-22 23:04:56 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
import { ACTIVITY_HOME, GlobalActivity } from '../../common/constants';
|
2021-10-07 12:38:11 +00:00
|
|
|
import { isDesign } from '../../models/workspace';
|
2021-11-02 22:10:53 +00:00
|
|
|
import { selectActiveProjectName } from '../redux/selectors';
|
2021-09-27 13:47:22 +00:00
|
|
|
import { ActivityToggle } from './activity-toggle';
|
2021-11-02 22:10:53 +00:00
|
|
|
import { AppHeader } from './app-header';
|
2021-09-27 13:47:22 +00:00
|
|
|
import { WorkspaceDropdown } from './dropdowns/workspace-dropdown';
|
2021-07-22 23:04:56 +00:00
|
|
|
import type { WrapperProps } from './wrapper';
|
2021-02-02 23:19:22 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
interface Props {
|
|
|
|
wrapperProps: WrapperProps;
|
2021-09-01 14:50:26 +00:00
|
|
|
handleActivityChange: (options: {workspaceId?: string; nextActivity: GlobalActivity}) => Promise<void>;
|
2021-05-12 06:35:00 +00:00
|
|
|
gridRight: ReactNode;
|
|
|
|
}
|
2021-02-02 23:19:22 +00:00
|
|
|
|
2021-09-27 13:47:22 +00:00
|
|
|
export const WorkspacePageHeader: FunctionComponent<Props> = ({
|
2021-02-02 23:19:22 +00:00
|
|
|
gridRight,
|
|
|
|
handleActivityChange,
|
|
|
|
wrapperProps: {
|
|
|
|
activeApiSpec,
|
|
|
|
activeWorkspace,
|
2021-10-07 12:38:11 +00:00
|
|
|
activeWorkspaceName,
|
2021-08-20 15:12:36 +00:00
|
|
|
activeProject,
|
2021-02-02 23:19:22 +00:00
|
|
|
activeEnvironment,
|
|
|
|
settings,
|
|
|
|
activity,
|
|
|
|
isLoading,
|
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
}) => {
|
|
|
|
const homeCallback = useCallback(
|
2021-06-30 07:47:17 +00:00
|
|
|
() => handleActivityChange({ workspaceId: activeWorkspace?._id, nextActivity: ACTIVITY_HOME }),
|
|
|
|
[activeWorkspace, handleActivityChange],
|
2021-02-02 23:19:22 +00:00
|
|
|
);
|
2021-11-02 22:10:53 +00:00
|
|
|
const activeProjectName = useSelector(selectActiveProjectName);
|
2021-05-27 20:02:16 +00:00
|
|
|
|
2021-11-10 15:11:04 +00:00
|
|
|
if (!activeWorkspace || !activeApiSpec || !activity) {
|
2021-06-30 07:47:17 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-02-02 23:19:22 +00:00
|
|
|
const workspace = (
|
|
|
|
<WorkspaceDropdown
|
2021-11-02 22:10:53 +00:00
|
|
|
key="workspace-dd"
|
2021-02-02 23:19:22 +00:00
|
|
|
activeEnvironment={activeEnvironment}
|
|
|
|
activeWorkspace={activeWorkspace}
|
2021-10-07 12:38:11 +00:00
|
|
|
activeWorkspaceName={activeWorkspaceName}
|
2021-02-16 02:16:45 +00:00
|
|
|
activeApiSpec={activeApiSpec}
|
2021-08-20 15:12:36 +00:00
|
|
|
activeProject={activeProject}
|
2021-02-02 23:19:22 +00:00
|
|
|
hotKeyRegistry={settings.hotKeyRegistry}
|
|
|
|
isLoading={isLoading}
|
|
|
|
/>
|
|
|
|
);
|
2021-05-27 20:02:16 +00:00
|
|
|
|
2021-08-05 23:30:31 +00:00
|
|
|
const crumbs = [
|
2021-11-02 22:10:53 +00:00
|
|
|
{ id: 'project', node: activeProjectName, onClick: homeCallback },
|
|
|
|
{ id: 'workspace', node: workspace },
|
2021-08-05 23:30:31 +00:00
|
|
|
];
|
|
|
|
|
2021-02-02 23:19:22 +00:00
|
|
|
return (
|
2021-11-02 22:10:53 +00:00
|
|
|
<AppHeader
|
|
|
|
breadcrumbProps={{ crumbs }}
|
2021-02-02 23:19:22 +00:00
|
|
|
gridCenter={
|
2021-10-07 12:38:11 +00:00
|
|
|
isDesign(activeWorkspace) && (
|
2021-02-02 23:19:22 +00:00
|
|
|
<ActivityToggle
|
|
|
|
activity={activity}
|
|
|
|
handleActivityChange={handleActivityChange}
|
|
|
|
workspace={activeWorkspace}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2021-11-02 22:10:53 +00:00
|
|
|
gridRight={gridRight}
|
2021-02-02 23:19:22 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|