Skip to content

Commit

Permalink
feat: new option disableSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jul 17, 2018
1 parent fec4605 commit d4ab5ad
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ You can use all of the following options with standalone version on <redoc> tag
* `hideLoading` - do not show loading animation. Useful for small docs
* `nativeScrollbars` - use native scrollbar for sidemenu instead of perfect-scroll (scrolling performance optimization for big specs)
* `hideDownloadButton` - do not show "Download" spec button. **THIS DOESN'T MAKE YOUR SPEC PRIVATE**, it just hides the button.
* `disableSearch` - disable search indexing and search box
* `theme` - ReDoc theme. Not documented yet. For details check source code: [theme.ts](https://github.com/Rebilly/ReDoc/blob/master/src/theme.ts)

## Advanced usage of standalone version
Expand Down
15 changes: 9 additions & 6 deletions src/components/Redoc/Redoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ export class Redoc extends React.Component<RedocProps> {
<RedocWrap className="redoc-wrap">
<StickyResponsiveSidebar menu={menu} className="menu-content">
<ApiLogo info={spec.info} />
<SearchBox
search={search}
marker={marker}
getItemById={menu.getItemById}
onActivate={menu.activateAndScroll}
/>
{(!options.disableSearch && (
<SearchBox
search={search!}
marker={marker}
getItemById={menu.getItemById}
onActivate={menu.activateAndScroll}
/>
)) ||
null}
<SideMenu menu={menu} />
</StickyResponsiveSidebar>
<ApiContentWrap className="api-content">
Expand Down
24 changes: 14 additions & 10 deletions src/services/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ export class AppStore {
const inst = new AppStore(state.spec.data, state.spec.url, state.options, false);
inst.menu.activeItemIdx = state.menu.activeItemIdx || 0;
inst.menu.activate(inst.menu.flatItems[inst.menu.activeItemIdx]);
inst.search.load(state.searchIndex);
if (!inst.options.disableSearch) {
inst.search!.load(state.searchIndex);
}
return inst;
}

menu: MenuStore;
spec: SpecStore;
rawOptions: RedocRawOptions;
options: RedocNormalizedOptions;
search: SearchStore<string>;
search?: SearchStore<string>;
marker = new MarkerService();

private scroll: ScrollService;
Expand All @@ -71,14 +73,16 @@ export class AppStore {
this.spec = new SpecStore(spec, specUrl, this.options);
this.menu = new MenuStore(this.spec, this.scroll);

this.search = new SearchStore();
if (createSearchIndex) {
this.search.indexItems(this.menu.items);
}
if (!this.options.disableSearch) {
this.search = new SearchStore();
if (createSearchIndex) {
this.search.indexItems(this.menu.items);
}

this.disposer = observe(this.menu, 'activeItemIdx', change => {
this.updateMarkOnMenu(change.newValue as number);
});
this.disposer = observe(this.menu, 'activeItemIdx', change => {
this.updateMarkOnMenu(change.newValue as number);
});
}
}

onDidMount() {
Expand Down Expand Up @@ -128,7 +132,7 @@ export class AppStore {
url: this.spec.parser.specUrl,
data: this.spec.parser.spec,
},
searchIndex: await this.search.toJS(),
searchIndex: this.search ? await this.search.toJS() : undefined,
options: this.rawOptions,
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/services/RedocNormalizedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface RedocRawOptions {
untrustedSpec?: boolean | string;
hideLoading?: boolean | string;
hideDownloadButton?: boolean | string;
disableSearch?: boolean | string;

unstable_ignoreMimeParameters?: boolean;
}
Expand Down Expand Up @@ -93,6 +94,7 @@ export class RedocNormalizedOptions {
pathInMiddlePanel: boolean;
untrustedSpec: boolean;
hideDownloadButton: boolean;
disableSearch: boolean;

/* tslint:disable-next-line */
unstable_ignoreMimeParameters: boolean;
Expand All @@ -115,6 +117,7 @@ export class RedocNormalizedOptions {
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
this.disableSearch = argValueToBoolean(raw.disableSearch);

this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);
}
Expand Down

0 comments on commit d4ab5ad

Please sign in to comment.