Added sort navigation tag

This commit is contained in:
andrii 2020-07-22 16:10:23 +02:00
parent 676faa943a
commit 324f8b8df0
3 changed files with 19 additions and 3 deletions

View File

@ -81,7 +81,7 @@ export class AppStore {
MenuStore.updateOnHistory(history.currentId, this.scroll);
this.spec = new SpecStore(spec, specUrl, this.options);
this.menu = new MenuStore(this.spec, this.scroll, history);
this.menu = new MenuStore(this.spec, this.scroll, history, this.options);
if (!this.options.disableSearch) {
this.search = new SearchStore();

View File

@ -8,9 +8,12 @@ import { ScrollService } from './ScrollService';
import { flattenByProp, SECURITY_SCHEMES_SECTION_PREFIX } from '../utils';
import { GROUP_DEPTH } from './MenuBuilder';
import {RedocNormalizedOptions} from "./RedocNormalizedOptions";
export type MenuItemGroupType = 'group' | 'tag' | 'section';
export type MenuItemType = MenuItemGroupType | 'operation';
/** Generic interface for MenuItems */
export interface IMenuItem {
id: string;
@ -74,11 +77,21 @@ export class MenuStore {
*
* @param spec [SpecStore](#SpecStore) which contains page content structure
* @param scroll scroll service instance used by this menu
* @param history
* @param options
*/
constructor(spec: SpecStore, public scroll: ScrollService, public history: HistoryService) {
constructor(spec: SpecStore, public scroll: ScrollService, public history: HistoryService, public options: RedocNormalizedOptions) {
this.items = spec.contentItems;
this.flatItems = flattenByProp(this.items || [], 'items');
if (this.options.sortNavigationTags) {
this.flatItems.map((item) => {
if (item.type === "tag") {
item.items.sort((a, b) => (a.name > b.name) ? 1 : -1)
}
});
this.flatItems = flattenByProp(this.items || [], 'items');
}
this.flatItems.forEach((item, idx) => (item.absoluteIdx = idx));
this.subscribe();

View File

@ -11,6 +11,7 @@ export interface RedocRawOptions {
hideHostname?: boolean | string;
expandResponses?: string | 'all';
requiredPropsFirst?: boolean | string;
sortNavigationTags?: boolean | string;
sortPropsAlphabetically?: boolean | string;
sortEnumValuesAlphabetically?: boolean | string;
noAutoAuth?: boolean | string;
@ -165,6 +166,7 @@ export class RedocNormalizedOptions {
hideHostname: boolean;
expandResponses: { [code: string]: boolean } | 'all';
requiredPropsFirst: boolean;
sortNavigationTags: boolean;
sortPropsAlphabetically: boolean;
sortEnumValuesAlphabetically: boolean;
noAutoAuth: boolean;
@ -220,6 +222,7 @@ export class RedocNormalizedOptions {
this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
this.sortNavigationTags = argValueToBoolean(raw.sortNavigationTags);
this.noAutoAuth = argValueToBoolean(raw.noAutoAuth);
this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);