import type { Transition } from '@uirouter/core'; import { UISref, UIView } from '@uirouter/react'; import '@uirouter/rx'; import React from 'react'; import { Dropdown, MenuItem } from 'react-bootstrap'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { ConfigureProjectModal } from './configure/ConfigureProjectModal'; import type { IProject } from '../domain'; import { Overridable } from '../overrideRegistry'; import { SpanDropdownTrigger } from '../presentation'; import './project.less'; export interface IProjectHeaderProps { projectConfiguration: IProject; transition: Transition; } export interface IProjectHeaderState { state: string; application?: string; isOpen: boolean; } @Overridable('createProjectHeader') export class ProjectHeader extends React.Component { public state: IProjectHeaderState = { state: null, application: null, isOpen: false }; private destroy$ = new Subject(); public componentDidMount() { const { success$ } = this.props.transition.router.globals; success$.pipe(takeUntil(this.destroy$)).subscribe((success) => { const state = success.to().name; const application = success.params().application; this.setState({ state, application }); }); } public componentWillUnmount() { this.destroy$.next(); } private handleDropdownToggle = (isOpen: boolean) => this.setState({ isOpen }); private configureProject = () => { const { projectConfiguration } = this.props; const $state = this.props.transition.router.stateService; const title = 'Configure project'; ConfigureProjectModal.show({ title, projectConfiguration }) .then((result) => { if (result.action === 'delete') { $state.go('home.infrastructure'); } else if (result.action === 'upsert') { $state.go($state.current, { project: result.name }, { location: 'replace', reload: true }); } }) .catch((err) => { console.error(err); }); }; public render() { const { projectConfiguration: project } = this.props; const { application, state } = this.state; const config = project.config; const isDashboard = state === 'home.project.dashboard'; const title = isDashboard ? 'Project Dashboard' : application; if (project.notFound) { return (

<404>

Please check your URL - we can't find any data for the project {project.name}.

); } const chevronStyle = { transition: 'transform 0.15s ease', transform: `rotate(${this.state.isOpen ? 180 : 0}deg)`, }; // heh. const closeDropdown = () => document.body.click(); const projectConfiguration = (
); return (

{project.name} /
{title} Project Dashboard {config.applications && config.applications.sort().map((app) => ( {app} ))}

{isDashboard && projectConfiguration}
); } }