mirror of
https://github.com/Kong/insomnia
synced 2024-11-12 17:26:32 +00:00
5f4c19da35
Co-authored-by: Opender Singh <opender.singh@konghq.com>
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import React, { Fragment, FunctionComponent, ReactNode, useCallback } from 'react';
|
|
import { ACTIVITY_HOME, GlobalActivity } from '../../common/constants';
|
|
import coreLogo from '../images/insomnia-core-logo.png';
|
|
import { strings } from '../../common/strings';
|
|
import WorkspaceDropdown from './dropdowns/workspace-dropdown';
|
|
import ActivityToggle from './activity-toggle';
|
|
import type { WrapperProps } from './wrapper';
|
|
import { Header, Breadcrumb } from 'insomnia-components';
|
|
import AccountDropdown from './dropdowns/account-dropdown';
|
|
import SettingsButton from './buttons/settings-button';
|
|
import { isCollection, isDesign } from '../../models/helpers/is-model';
|
|
|
|
interface Props {
|
|
wrapperProps: WrapperProps;
|
|
handleActivityChange: (workspaceId: string, activity: GlobalActivity) => Promise<void>;
|
|
gridRight: ReactNode;
|
|
}
|
|
|
|
const WorkspacePageHeader: FunctionComponent<Props> = ({
|
|
gridRight,
|
|
handleActivityChange,
|
|
wrapperProps: {
|
|
activeApiSpec,
|
|
activeWorkspace,
|
|
activeEnvironment,
|
|
settings,
|
|
activity,
|
|
isLoading,
|
|
},
|
|
}) => {
|
|
const collection = isCollection(activeWorkspace);
|
|
const design = isDesign(activeWorkspace);
|
|
const homeCallback = useCallback(
|
|
() => handleActivityChange(activeWorkspace._id, ACTIVITY_HOME),
|
|
[activeWorkspace._id, handleActivityChange],
|
|
);
|
|
const workspace = (
|
|
<WorkspaceDropdown
|
|
displayName={collection ? activeWorkspace.name : activeApiSpec.fileName}
|
|
activeEnvironment={activeEnvironment}
|
|
activeWorkspace={activeWorkspace}
|
|
activeApiSpec={activeApiSpec}
|
|
hotKeyRegistry={settings.hotKeyRegistry}
|
|
isLoading={isLoading}
|
|
/>
|
|
);
|
|
return (
|
|
<Header
|
|
className="app-header theme--app-header"
|
|
gridLeft={
|
|
<Fragment>
|
|
<img src={coreLogo} alt="Insomnia" width="24" height="24" />
|
|
<Breadcrumb
|
|
className="breadcrumb"
|
|
// @ts-expect-error -- TSCONVERSION
|
|
crumbs={[strings.home, <Fragment key="workspace-dd">{workspace}</Fragment>]}
|
|
onClick={homeCallback}
|
|
/>
|
|
</Fragment>
|
|
}
|
|
gridCenter={
|
|
design && (
|
|
<ActivityToggle
|
|
activity={activity}
|
|
handleActivityChange={handleActivityChange}
|
|
workspace={activeWorkspace}
|
|
/>
|
|
)
|
|
}
|
|
gridRight={
|
|
<>
|
|
{gridRight}
|
|
<SettingsButton className="margin-left" />
|
|
<AccountDropdown className="margin-left" />
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default WorkspacePageHeader;
|