From 34c152c08ac75def661e28012cdcd02823ebe3bf Mon Sep 17 00:00:00 2001 From: Patrick Rodacker Date: Tue, 19 Mar 2019 14:07:50 +0100 Subject: [PATCH] inject options into Group model, do not expand groups that have the option collapseTagGroups set to true and allow to collapse groups with that option --- src/services/MenuBuilder.ts | 6 +++--- src/services/models/Group.model.ts | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/services/MenuBuilder.ts b/src/services/MenuBuilder.ts index 6dab0cb8..407271fb 100644 --- a/src/services/MenuBuilder.ts +++ b/src/services/MenuBuilder.ts @@ -66,7 +66,7 @@ export class MenuBuilder { const mapHeadingsDeep = (parent, items, depth = 1) => items.map(heading => { - const group = new GroupModel('section', heading, parent); + const group = new GroupModel('section', heading, options, parent); group.depth = depth; if (heading.items) { group.items = mapHeadingsDeep(group, heading.items, depth + 1); @@ -98,7 +98,7 @@ export class MenuBuilder { ): GroupModel[] { const res: GroupModel[] = []; for (const group of groups) { - const item = new GroupModel('group', group, parent); + const item = new GroupModel('group', group, options, parent); item.depth = GROUP_DEPTH; item.items = MenuBuilder.getTagsItems(parser, tags, item, group, options); res.push(item); @@ -142,7 +142,7 @@ export class MenuBuilder { if (!tag) { continue; } - const item = new GroupModel('tag', tag, parent); + const item = new GroupModel('tag', tag, options, parent); item.depth = GROUP_DEPTH + 1; item.items = this.getOperationsItems(parser, item, tag, item.depth + 1, options); diff --git a/src/services/models/Group.model.ts b/src/services/models/Group.model.ts index c1aaa246..358f6111 100644 --- a/src/services/models/Group.model.ts +++ b/src/services/models/Group.model.ts @@ -5,6 +5,7 @@ import { safeSlugify } from '../../utils'; import { MarkdownHeading } from '../MarkdownRenderer'; import { ContentItemModel } from '../MenuBuilder'; import { IMenuItem, MenuItemGroupType } from '../MenuStore'; +import { RedocNormalizedOptions } from "../RedocNormalizedOptions"; /** * Operations Group model ready to be used by components @@ -18,6 +19,7 @@ export class GroupModel implements IMenuItem { type: MenuItemGroupType; items: ContentItemModel[] = []; + options: RedocNormalizedOptions; parent?: GroupModel; externalDocs?: OpenAPIExternalDocumentation; @@ -33,6 +35,7 @@ export class GroupModel implements IMenuItem { constructor( type: MenuItemGroupType, tagOrGroup: OpenAPITag | MarkdownHeading, + options: RedocNormalizedOptions, parent?: GroupModel, ) { // markdown headings already have ids calculated as they are needed for heading anchors @@ -41,11 +44,12 @@ export class GroupModel implements IMenuItem { this.name = tagOrGroup['x-displayName'] || tagOrGroup.name; this.level = (tagOrGroup as MarkdownHeading).level || 1; this.description = tagOrGroup.description || ''; + this.options = options; this.parent = parent; this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs; - // groups are active (expanded) by default - if (this.type === 'group') { + // groups are active (expanded) by default, unless collapsed by configuration + if (this.type === 'group' && !this.options.collapseTagGroups) { this.expanded = true; } } @@ -65,8 +69,8 @@ export class GroupModel implements IMenuItem { @action collapse() { - // disallow collapsing groups - if (this.type === 'group') { + // disallow collapsing groups by default, unless tag groups are configured to be collapsible + if (this.type === 'group' && !this.options.collapseTagGroups) { return; } this.expanded = false;