mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-10 07:04:51 +03:00
Add options to sort tags,operations and groups alphabetically
This commit is contained in:
parent
755a9095f5
commit
5b37959a73
|
@ -253,6 +253,9 @@ You can use all of the following options with standalone version on <redoc> tag
|
||||||
* **function**: A getter function. Must return a number representing the offset (in pixels).
|
* **function**: A getter function. Must return a number representing the offset (in pixels).
|
||||||
* `showExtensions` - show vendor extensions ("x-" fields). Extensions used by ReDoc are ignored. Can be boolean or an array of `string` with names of extensions to display.
|
* `showExtensions` - show vendor extensions ("x-" fields). Extensions used by ReDoc are ignored. Can be boolean or an array of `string` with names of extensions to display.
|
||||||
* `sortPropsAlphabetically` - sort properties alphabetically.
|
* `sortPropsAlphabetically` - sort properties alphabetically.
|
||||||
|
* `sortTagsAlphabetically` - sort tags alphabetically.
|
||||||
|
* `sortOperationsAlphabetically` - sort operations alphabetically.
|
||||||
|
* `sortTagGroupsAlphabetically` - sort tag groups alphabetically.
|
||||||
* `suppressWarnings` - if set, warnings are not rendered at the top of documentation (they still are logged to the console).
|
* `suppressWarnings` - if set, warnings are not rendered at the top of documentation (they still are logged to the console).
|
||||||
* `payloadSampleIdx` - if set, payload sample will be inserted at this index or last. Indexes start from 0.
|
* `payloadSampleIdx` - if set, payload sample will be inserted at this index or last. Indexes start from 0.
|
||||||
* `theme` - ReDoc theme. For details check [theme docs](#redoc-theme-object).
|
* `theme` - ReDoc theme. For details check [theme docs](#redoc-theme-object).
|
||||||
|
|
|
@ -81,7 +81,7 @@ export class AppStore {
|
||||||
MenuStore.updateOnHistory(history.currentId, this.scroll);
|
MenuStore.updateOnHistory(history.currentId, this.scroll);
|
||||||
|
|
||||||
this.spec = new SpecStore(spec, specUrl, this.options);
|
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) {
|
if (!this.options.disableSearch) {
|
||||||
this.search = new SearchStore();
|
this.search = new SearchStore();
|
||||||
|
|
|
@ -8,6 +8,8 @@ import { ScrollService } from './ScrollService';
|
||||||
import { flattenByProp, SECURITY_SCHEMES_SECTION_PREFIX } from '../utils';
|
import { flattenByProp, SECURITY_SCHEMES_SECTION_PREFIX } from '../utils';
|
||||||
import { GROUP_DEPTH } from './MenuBuilder';
|
import { GROUP_DEPTH } from './MenuBuilder';
|
||||||
|
|
||||||
|
import {RedocNormalizedOptions} from "./RedocNormalizedOptions";
|
||||||
|
|
||||||
export type MenuItemGroupType = 'group' | 'tag' | 'section';
|
export type MenuItemGroupType = 'group' | 'tag' | 'section';
|
||||||
export type MenuItemType = MenuItemGroupType | 'operation';
|
export type MenuItemType = MenuItemGroupType | 'operation';
|
||||||
|
|
||||||
|
@ -74,12 +76,45 @@ export class MenuStore {
|
||||||
*
|
*
|
||||||
* @param spec [SpecStore](#SpecStore) which contains page content structure
|
* @param spec [SpecStore](#SpecStore) which contains page content structure
|
||||||
* @param scroll scroll service instance used by this menu
|
* @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) {
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
|
const alphaSort = items => items.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
|
||||||
this.items = spec.contentItems;
|
this.items = spec.contentItems;
|
||||||
|
|
||||||
|
if (this.options.sortTagGroupsAlphabetically) {
|
||||||
|
const groups = this.items.filter(item => item.type === "group");
|
||||||
|
alphaSort(groups);
|
||||||
|
this.items = this.items.filter(item => item.type !== "group").concat(groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.sortTagsAlphabetically) {
|
||||||
|
const tags = this.items.filter(item => item.type === "tag");
|
||||||
|
alphaSort(tags);
|
||||||
|
this.items = this.items.filter(item => item.type !== "tag").concat(tags);
|
||||||
|
this.items.map(item => {
|
||||||
|
if(item.type === "group") {
|
||||||
|
alphaSort(item.items);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.sortOperationsAlphabetically) {
|
||||||
|
this.items.map(item => {
|
||||||
|
if(item.type === "tag") {
|
||||||
|
alphaSort(item.items);
|
||||||
|
} else if (item.type === "group") {
|
||||||
|
item.items.map(groupItem => {
|
||||||
|
if(groupItem.type === "tag") {
|
||||||
|
alphaSort(item.items);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.flatItems = flattenByProp(this.items || [], 'items');
|
this.flatItems = flattenByProp(this.items || [], 'items');
|
||||||
this.flatItems.forEach((item, idx) => (item.absoluteIdx = idx));
|
this.flatItems.forEach((item, idx) => (item.absoluteIdx = idx));
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,9 @@ export interface RedocRawOptions {
|
||||||
requiredPropsFirst?: boolean | string;
|
requiredPropsFirst?: boolean | string;
|
||||||
sortPropsAlphabetically?: boolean | string;
|
sortPropsAlphabetically?: boolean | string;
|
||||||
sortEnumValuesAlphabetically?: boolean | string;
|
sortEnumValuesAlphabetically?: boolean | string;
|
||||||
|
sortTagGroupsAlphabetically?: boolean | string;
|
||||||
|
sortTagsAlphabetically?: boolean | string;
|
||||||
|
sortOperationsAlphabetically?: boolean | string;
|
||||||
noAutoAuth?: boolean | string;
|
noAutoAuth?: boolean | string;
|
||||||
nativeScrollbars?: boolean | string;
|
nativeScrollbars?: boolean | string;
|
||||||
pathInMiddlePanel?: boolean | string;
|
pathInMiddlePanel?: boolean | string;
|
||||||
|
@ -170,6 +173,9 @@ export class RedocNormalizedOptions {
|
||||||
requiredPropsFirst: boolean;
|
requiredPropsFirst: boolean;
|
||||||
sortPropsAlphabetically: boolean;
|
sortPropsAlphabetically: boolean;
|
||||||
sortEnumValuesAlphabetically: boolean;
|
sortEnumValuesAlphabetically: boolean;
|
||||||
|
sortTagGroupsAlphabetically: boolean;
|
||||||
|
sortTagsAlphabetically: boolean;
|
||||||
|
sortOperationsAlphabetically: boolean;
|
||||||
noAutoAuth: boolean;
|
noAutoAuth: boolean;
|
||||||
nativeScrollbars: boolean;
|
nativeScrollbars: boolean;
|
||||||
pathInMiddlePanel: boolean;
|
pathInMiddlePanel: boolean;
|
||||||
|
@ -227,6 +233,9 @@ export class RedocNormalizedOptions {
|
||||||
this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
|
this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
|
||||||
this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
|
this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
|
||||||
this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
|
this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
|
||||||
|
this.sortTagGroupsAlphabetically = argValueToBoolean(raw.sortTagGroupsAlphabetically);
|
||||||
|
this.sortTagsAlphabetically = argValueToBoolean(raw.sortTagsAlphabetically);
|
||||||
|
this.sortOperationsAlphabetically = argValueToBoolean(raw.sortOperationsAlphabetically);
|
||||||
this.noAutoAuth = argValueToBoolean(raw.noAutoAuth);
|
this.noAutoAuth = argValueToBoolean(raw.noAutoAuth);
|
||||||
this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
|
this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
|
||||||
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
|
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user