2021-05-12 06:35:00 +00:00
|
|
|
import React, { Fragment, FunctionComponent, ReactNode, useCallback } from 'react';
|
|
|
|
import { ACTIVITY_HOME, GlobalActivity } from '../../common/constants';
|
2021-02-02 23:19:22 +00:00
|
|
|
import coreLogo from '../images/insomnia-core-logo.png';
|
2021-03-01 21:32:32 +00:00
|
|
|
import { strings } from '../../common/strings';
|
2021-02-02 23:19:22 +00:00
|
|
|
import WorkspaceDropdown from './dropdowns/workspace-dropdown';
|
|
|
|
import ActivityToggle from './activity-toggle';
|
|
|
|
import type { WrapperProps } from './wrapper';
|
|
|
|
import { Header, Breadcrumb } from 'insomnia-components';
|
2021-02-12 02:20:35 +00:00
|
|
|
import AccountDropdown from './dropdowns/account-dropdown';
|
|
|
|
import SettingsButton from './buttons/settings-button';
|
2021-06-16 19:19:00 +00:00
|
|
|
import { isCollection, isDesign } from '../../models/workspace';
|
2021-02-02 23:19:22 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
interface Props {
|
|
|
|
wrapperProps: WrapperProps;
|
|
|
|
handleActivityChange: (workspaceId: string, activity: GlobalActivity) => Promise<void>;
|
|
|
|
gridRight: ReactNode;
|
|
|
|
}
|
2021-02-02 23:19:22 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
const WorkspacePageHeader: FunctionComponent<Props> = ({
|
2021-02-02 23:19:22 +00:00
|
|
|
gridRight,
|
|
|
|
handleActivityChange,
|
|
|
|
wrapperProps: {
|
|
|
|
activeApiSpec,
|
|
|
|
activeWorkspace,
|
|
|
|
activeEnvironment,
|
|
|
|
settings,
|
|
|
|
activity,
|
|
|
|
isLoading,
|
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
}) => {
|
2021-03-17 22:37:32 +00:00
|
|
|
const collection = isCollection(activeWorkspace);
|
|
|
|
const design = isDesign(activeWorkspace);
|
2021-05-12 06:35:00 +00:00
|
|
|
const homeCallback = useCallback(
|
2021-02-02 23:19:22 +00:00
|
|
|
() => handleActivityChange(activeWorkspace._id, ACTIVITY_HOME),
|
|
|
|
[activeWorkspace._id, handleActivityChange],
|
|
|
|
);
|
2021-05-27 20:02:16 +00:00
|
|
|
|
2021-02-02 23:19:22 +00:00
|
|
|
const workspace = (
|
|
|
|
<WorkspaceDropdown
|
|
|
|
displayName={collection ? activeWorkspace.name : activeApiSpec.fileName}
|
|
|
|
activeEnvironment={activeEnvironment}
|
|
|
|
activeWorkspace={activeWorkspace}
|
2021-02-16 02:16:45 +00:00
|
|
|
activeApiSpec={activeApiSpec}
|
2021-02-02 23:19:22 +00:00
|
|
|
hotKeyRegistry={settings.hotKeyRegistry}
|
|
|
|
isLoading={isLoading}
|
|
|
|
/>
|
|
|
|
);
|
2021-05-27 20:02:16 +00:00
|
|
|
|
2021-02-02 23:19:22 +00:00
|
|
|
return (
|
|
|
|
<Header
|
2021-03-02 16:14:19 +00:00
|
|
|
className="app-header theme--app-header"
|
2021-02-02 23:19:22 +00:00
|
|
|
gridLeft={
|
2021-05-12 06:35:00 +00:00
|
|
|
<Fragment>
|
2021-02-10 23:37:10 +00:00
|
|
|
<img src={coreLogo} alt="Insomnia" width="24" height="24" />
|
2021-02-02 23:19:22 +00:00
|
|
|
<Breadcrumb
|
2021-06-01 12:52:41 +00:00
|
|
|
crumbs={[{ id: 'home', node: strings.home.singular, onClick: homeCallback },
|
2021-05-27 20:02:16 +00:00
|
|
|
{ id: 'workspace', node: <Fragment key="workspace-dd">{workspace}</Fragment> }]}/>
|
2021-05-12 06:35:00 +00:00
|
|
|
</Fragment>
|
2021-02-02 23:19:22 +00:00
|
|
|
}
|
|
|
|
gridCenter={
|
2021-03-16 23:28:12 +00:00
|
|
|
design && (
|
2021-02-02 23:19:22 +00:00
|
|
|
<ActivityToggle
|
|
|
|
activity={activity}
|
|
|
|
handleActivityChange={handleActivityChange}
|
|
|
|
workspace={activeWorkspace}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2021-02-12 02:20:35 +00:00
|
|
|
gridRight={
|
|
|
|
<>
|
|
|
|
{gridRight}
|
|
|
|
<SettingsButton className="margin-left" />
|
|
|
|
<AccountDropdown className="margin-left" />
|
|
|
|
</>
|
|
|
|
}
|
2021-02-02 23:19:22 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WorkspacePageHeader;
|