2017-10-12 00:01:37 +03:00
|
|
|
import { observer } from 'mobx-react';
|
2018-01-22 21:30:53 +03:00
|
|
|
import * as React from 'react';
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2018-08-16 09:56:47 +03:00
|
|
|
import { AdvancedMarkdown } from '../Markdown/AdvancedMarkdown';
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2018-08-16 09:56:47 +03:00
|
|
|
import { H1, H2, MiddlePanel, Row, Section, ShareLink } from '../../common-elements';
|
2017-10-12 00:01:37 +03:00
|
|
|
import { ContentItemModel } from '../../services/MenuBuilder';
|
2018-08-08 11:37:48 +03:00
|
|
|
import { GroupModel, OperationModel } from '../../services/models';
|
2018-01-22 21:30:53 +03:00
|
|
|
import { Operation } from '../Operation/Operation';
|
2018-08-16 09:56:47 +03:00
|
|
|
|
2017-10-12 00:01:37 +03:00
|
|
|
@observer
|
|
|
|
export class ContentItems extends React.Component<{
|
|
|
|
items: ContentItemModel[];
|
|
|
|
}> {
|
|
|
|
render() {
|
|
|
|
const items = this.props.items;
|
2018-01-22 21:30:53 +03:00
|
|
|
if (items.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-08-17 14:41:22 +03:00
|
|
|
return items.map(item => <ContentItem item={item} key={item.id} />);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-16 12:44:36 +03:00
|
|
|
export interface ContentItemProps {
|
2017-10-12 00:01:37 +03:00
|
|
|
item: ContentItemModel;
|
2018-01-22 21:30:53 +03:00
|
|
|
}
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
@observer
|
|
|
|
export class ContentItem extends React.Component<ContentItemProps> {
|
|
|
|
render() {
|
|
|
|
const item = this.props.item;
|
|
|
|
let content;
|
|
|
|
const { type } = item;
|
|
|
|
switch (type) {
|
|
|
|
case 'group':
|
|
|
|
content = null;
|
|
|
|
break;
|
|
|
|
case 'tag':
|
2018-07-30 13:04:27 +03:00
|
|
|
content = <SectionItem {...this.props} />;
|
2017-10-12 00:01:37 +03:00
|
|
|
break;
|
|
|
|
case 'section':
|
2018-07-30 13:04:27 +03:00
|
|
|
content = <SectionItem {...this.props} />;
|
|
|
|
break;
|
2017-10-12 00:01:37 +03:00
|
|
|
case 'operation':
|
|
|
|
content = <OperationItem item={item as any} />;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error('Unknown item type');
|
|
|
|
}
|
|
|
|
|
2018-08-16 09:56:47 +03:00
|
|
|
return (
|
|
|
|
<>
|
2018-08-16 12:36:51 +03:00
|
|
|
<Section id={item.id} underlined={item.type === 'operation'}>
|
2018-08-16 09:56:47 +03:00
|
|
|
{content}
|
|
|
|
</Section>
|
2018-08-17 14:41:22 +03:00
|
|
|
{item.items && <ContentItems items={item.items} />}
|
2018-08-16 09:56:47 +03:00
|
|
|
</>
|
|
|
|
);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 09:56:47 +03:00
|
|
|
const middlePanelWrap = component => <MiddlePanel>{component}</MiddlePanel>;
|
|
|
|
|
2017-10-12 00:01:37 +03:00
|
|
|
@observer
|
2018-07-30 13:04:27 +03:00
|
|
|
export class SectionItem extends React.Component<ContentItemProps> {
|
2017-10-12 00:01:37 +03:00
|
|
|
render() {
|
2018-08-08 11:37:48 +03:00
|
|
|
const { name, description, level } = this.props.item as GroupModel;
|
2018-08-16 12:36:51 +03:00
|
|
|
|
2018-08-08 11:37:48 +03:00
|
|
|
const Header = level === 2 ? H2 : H1;
|
2017-10-12 00:01:37 +03:00
|
|
|
return (
|
2018-08-16 09:56:47 +03:00
|
|
|
<>
|
|
|
|
<Row>
|
|
|
|
<MiddlePanel>
|
|
|
|
<Header>
|
|
|
|
<ShareLink href={'#' + this.props.item.id} />
|
|
|
|
{name}
|
|
|
|
</Header>
|
|
|
|
</MiddlePanel>
|
|
|
|
</Row>
|
2018-08-17 14:41:22 +03:00
|
|
|
<AdvancedMarkdown source={description || ''} htmlWrap={middlePanelWrap} />
|
2018-08-16 09:56:47 +03:00
|
|
|
</>
|
2017-10-12 00:01:37 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@observer
|
|
|
|
export class OperationItem extends React.Component<{
|
|
|
|
item: OperationModel;
|
|
|
|
}> {
|
|
|
|
render() {
|
|
|
|
return <Operation operation={this.props.item} />;
|
|
|
|
}
|
|
|
|
}
|