2018-01-22 21:30:53 +03:00
|
|
|
import { action, observable } from 'mobx';
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
import { OpenAPIExternalDocumentation, OpenAPITag } from '../../types';
|
2018-07-17 15:21:03 +03:00
|
|
|
import { safeSlugify } from '../../utils';
|
2018-06-20 19:29:46 +03:00
|
|
|
import { MarkdownHeading } from '../MarkdownRenderer';
|
2017-10-12 00:01:37 +03:00
|
|
|
import { ContentItemModel } from '../MenuBuilder';
|
|
|
|
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Operations Group model ready to be used by components
|
|
|
|
*/
|
|
|
|
export class GroupModel implements IMenuItem {
|
|
|
|
//#region IMenuItem fields
|
|
|
|
id: string;
|
|
|
|
absoluteIdx?: number;
|
|
|
|
name: string;
|
|
|
|
description?: string;
|
|
|
|
type: MenuItemGroupType;
|
|
|
|
|
2018-01-22 21:30:53 +03:00
|
|
|
items: ContentItemModel[] = [];
|
2017-10-12 00:01:37 +03:00
|
|
|
parent?: GroupModel;
|
|
|
|
externalDocs?: OpenAPIExternalDocumentation;
|
|
|
|
|
|
|
|
@observable active: boolean = false;
|
|
|
|
|
|
|
|
depth: number;
|
|
|
|
//#endregion
|
|
|
|
|
2018-06-20 19:29:46 +03:00
|
|
|
constructor(
|
|
|
|
type: MenuItemGroupType,
|
|
|
|
tagOrGroup: OpenAPITag | MarkdownHeading,
|
|
|
|
parent?: GroupModel,
|
|
|
|
) {
|
|
|
|
// markdown headings already have ids calculated as they are needed for heading anchors
|
2018-07-17 15:21:03 +03:00
|
|
|
this.id = (tagOrGroup as MarkdownHeading).id || type + '/' + safeSlugify(tagOrGroup.name);
|
2017-10-12 00:01:37 +03:00
|
|
|
this.type = type;
|
|
|
|
this.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
|
|
|
|
this.description = tagOrGroup.description || '';
|
|
|
|
this.parent = parent;
|
2018-06-20 19:29:46 +03:00
|
|
|
this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs;
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
// groups are active (expanded) by default
|
|
|
|
if (this.type === 'group') {
|
|
|
|
this.active = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
activate() {
|
|
|
|
this.active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
deactivate() {
|
|
|
|
// disallow deactivating groups
|
2018-01-22 21:30:53 +03:00
|
|
|
if (this.type === 'group') {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-12 00:01:37 +03:00
|
|
|
this.active = false;
|
|
|
|
}
|
|
|
|
}
|