mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 06:04:56 +03:00
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
This commit is contained in:
parent
6f2d0cf3df
commit
34c152c08a
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user