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) =>
|
const mapHeadingsDeep = (parent, items, depth = 1) =>
|
||||||
items.map(heading => {
|
items.map(heading => {
|
||||||
const group = new GroupModel('section', heading, parent);
|
const group = new GroupModel('section', heading, options, parent);
|
||||||
group.depth = depth;
|
group.depth = depth;
|
||||||
if (heading.items) {
|
if (heading.items) {
|
||||||
group.items = mapHeadingsDeep(group, heading.items, depth + 1);
|
group.items = mapHeadingsDeep(group, heading.items, depth + 1);
|
||||||
|
@ -98,7 +98,7 @@ export class MenuBuilder {
|
||||||
): GroupModel[] {
|
): GroupModel[] {
|
||||||
const res: GroupModel[] = [];
|
const res: GroupModel[] = [];
|
||||||
for (const group of groups) {
|
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.depth = GROUP_DEPTH;
|
||||||
item.items = MenuBuilder.getTagsItems(parser, tags, item, group, options);
|
item.items = MenuBuilder.getTagsItems(parser, tags, item, group, options);
|
||||||
res.push(item);
|
res.push(item);
|
||||||
|
@ -142,7 +142,7 @@ export class MenuBuilder {
|
||||||
if (!tag) {
|
if (!tag) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const item = new GroupModel('tag', tag, parent);
|
const item = new GroupModel('tag', tag, options, parent);
|
||||||
item.depth = GROUP_DEPTH + 1;
|
item.depth = GROUP_DEPTH + 1;
|
||||||
item.items = this.getOperationsItems(parser, item, tag, item.depth + 1, options);
|
item.items = this.getOperationsItems(parser, item, tag, item.depth + 1, options);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { safeSlugify } from '../../utils';
|
||||||
import { MarkdownHeading } from '../MarkdownRenderer';
|
import { MarkdownHeading } from '../MarkdownRenderer';
|
||||||
import { ContentItemModel } from '../MenuBuilder';
|
import { ContentItemModel } from '../MenuBuilder';
|
||||||
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
||||||
|
import { RedocNormalizedOptions } from "../RedocNormalizedOptions";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operations Group model ready to be used by components
|
* Operations Group model ready to be used by components
|
||||||
|
@ -18,6 +19,7 @@ export class GroupModel implements IMenuItem {
|
||||||
type: MenuItemGroupType;
|
type: MenuItemGroupType;
|
||||||
|
|
||||||
items: ContentItemModel[] = [];
|
items: ContentItemModel[] = [];
|
||||||
|
options: RedocNormalizedOptions;
|
||||||
parent?: GroupModel;
|
parent?: GroupModel;
|
||||||
externalDocs?: OpenAPIExternalDocumentation;
|
externalDocs?: OpenAPIExternalDocumentation;
|
||||||
|
|
||||||
|
@ -33,6 +35,7 @@ export class GroupModel implements IMenuItem {
|
||||||
constructor(
|
constructor(
|
||||||
type: MenuItemGroupType,
|
type: MenuItemGroupType,
|
||||||
tagOrGroup: OpenAPITag | MarkdownHeading,
|
tagOrGroup: OpenAPITag | MarkdownHeading,
|
||||||
|
options: RedocNormalizedOptions,
|
||||||
parent?: GroupModel,
|
parent?: GroupModel,
|
||||||
) {
|
) {
|
||||||
// markdown headings already have ids calculated as they are needed for heading anchors
|
// 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.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
|
||||||
this.level = (tagOrGroup as MarkdownHeading).level || 1;
|
this.level = (tagOrGroup as MarkdownHeading).level || 1;
|
||||||
this.description = tagOrGroup.description || '';
|
this.description = tagOrGroup.description || '';
|
||||||
|
this.options = options;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs;
|
this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs;
|
||||||
|
|
||||||
// groups are active (expanded) by default
|
// groups are active (expanded) by default, unless collapsed by configuration
|
||||||
if (this.type === 'group') {
|
if (this.type === 'group' && !this.options.collapseTagGroups) {
|
||||||
this.expanded = true;
|
this.expanded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,8 +69,8 @@ export class GroupModel implements IMenuItem {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
collapse() {
|
collapse() {
|
||||||
// disallow collapsing groups
|
// disallow collapsing groups by default, unless tag groups are configured to be collapsible
|
||||||
if (this.type === 'group') {
|
if (this.type === 'group' && !this.options.collapseTagGroups) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.expanded = false;
|
this.expanded = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user