Load things into DOM when visiting tag or operation link.

This commit is contained in:
Chris Bojemski 2020-02-25 11:59:59 -08:00
parent 4a9c3b6763
commit e84a6cd9a0

View File

@ -36,11 +36,9 @@ export class Redoc extends React.Component<RedocProps, AppState> {
state = { activeSelection: undefined }; state = { activeSelection: undefined };
/* /*
PROBLEM! This will never be true during testing. Developing locally? Change to ':9090/'
Let's at least test to see if current URL endsWith
/admin/api/docs/ (trailing slash required).
*/ */
HOMEPAGE_ENDING = "/admin/api/docs/" HOMEPAGE_ENDING = "/admin/api/docs/";
getTagByName(tagName: string): IMenuItem | undefined { getTagByName(tagName: string): IMenuItem | undefined {
const menu = this.props.store.menu; const menu = this.props.store.menu;
@ -50,10 +48,11 @@ export class Redoc extends React.Component<RedocProps, AppState> {
getTagFromSitePath(sitePath: string): InitializeWithSelection { getTagFromSitePath(sitePath: string): InitializeWithSelection {
const menu = this.props.store.menu const menu = this.props.store.menu
const matched: InitializeWithSelection = { tag: undefined, operation: undefined }; const matched: InitializeWithSelection = { tag: undefined, operation: undefined };
//debugger;
menu.items.filter(item => item.type === 'tag').forEach(tag => { menu.items.filter(item => item.type === 'tag').forEach(tag => {
tag.items.forEach(operation => { tag.items.forEach(operation => {
// @ts-ignore // @ts-ignore
if (operation.operationId === sitePath.split('/#operation/')[1]) { if (operation.operationId === sitePath.split('#operation/')[1]) {
matched.tag = operation.parent!; matched.tag = operation.parent!;
matched.operation = operation; matched.operation = operation;
} }
@ -92,7 +91,7 @@ export class Redoc extends React.Component<RedocProps, AppState> {
nonHomepageLocationIsOperation(sitePath: string) { nonHomepageLocationIsOperation(sitePath: string) {
const parsed: InitializeWithSelection = this.getTagFromSitePath(sitePath); const parsed: InitializeWithSelection = this.getTagFromSitePath(sitePath);
if (parsed.tag && parsed.operation) { if (parsed.tag && parsed.operation) {
this.setActiveSelection(parsed.tag); this.setActiveSelection(parsed.tag, this.props.store.menu.activateAndScroll(parsed.operation, true));
} }
} }
@ -112,14 +111,6 @@ export class Redoc extends React.Component<RedocProps, AppState> {
this.nonHomepageLocationSetup(); this.nonHomepageLocationSetup();
} }
componentDidUpdate() {
if (this.shouldInitializeWithActiveSelection && this.sitePathIsOperation) {
const sitePath = this.parseSitePath(window.location.href);
const tags = this.getTagFromSitePath(sitePath);
this.props.store.menu.activateAndScroll(tags.operation);
}
}
componentWillUnmount() { componentWillUnmount() {
this.props.store.dispose(); this.props.store.dispose();
} }