import ActionChangelog from './ActionChangelog';
import DeprecatedBadge from './DeprecatedBadge';
import InternalBadge from './InternalBadge';
-import { getActionKey } from '../utils';
+import { getActionKey, serializeQuery } from '../utils';
import LinkIcon from '../../../components/icons-components/LinkIcon';
import { translate, translateWithParameters } from '../../../helpers/l10n';
<header className="web-api-action-header boxed-group-header">
<Link
className="spacer-right link-no-underline"
- to={{ pathname: '/web_api/' + actionKey }}>
+ to={{
+ pathname: '/web_api/' + actionKey,
+ query: serializeQuery({
+ deprecated: Boolean(action.deprecatedSince),
+ internal: Boolean(action.internal)
+ })
+ }}>
<LinkIcon />
</Link>
}
componentDidUpdate() {
- this.toggleInternalInitially();
+ this.enforceFlags();
this.scrollToAction();
}
this.props.router.push({ pathname: this.props.location.pathname, query });
};
- toggleInternalInitially() {
+ enforceFlags() {
const splat = this.props.params.splat || '';
const { domains } = this.state;
const query = parseQuery(this.props.location.query);
- if (!query.internal && splat) {
- const domain = domains.find(domain => domain.path.startsWith(splat));
- if (domain) {
- let action;
- if (domain.path !== splat) {
- action = domain.actions.find(action => getActionKey(domain.path, action.key) === splat);
- }
- if (domain.internal || (action && action.internal)) {
- this.updateQuery({ internal: true });
- }
+ const domain = domains.find(domain => splat.startsWith(domain.path));
+ if (domain) {
+ const action = domain.actions.find(action => getActionKey(domain.path, action.key) === splat);
+ const internal = Boolean(!query.internal && (domain.internal || (action && action.internal)));
+ const deprecated = Boolean(
+ !query.deprecated && (domain.deprecatedSince || (action && action.deprecatedSince))
+ );
+ if (internal || deprecated) {
+ this.updateQuery({ internal, deprecated });
}
}
}
this.updateQuery({ search });
};
- handleToggleInternal = () => {
+ toggleFlag(flag: 'deprecated' | 'internal', domainFlag: 'deprecatedSince' | 'internal') {
const splat = this.props.params.splat || '';
const { domains } = this.state;
const domain = domains.find(domain => isDomainPathActive(domain.path, splat));
const query = parseQuery(this.props.location.query);
- const internal = !query.internal;
+ const value = !query[flag];
- if (domain && domain.internal && !internal) {
+ if (domain && domain[domainFlag] && !value) {
this.props.router.push({
pathname: '/web_api',
- query: { ...serializeQuery(query), internal: false }
+ query: serializeQuery({ ...query, [flag]: false })
});
- return;
+ } else {
+ this.updateQuery({ [flag]: value });
}
+ }
- this.updateQuery({ internal });
+ handleToggleInternal = () => {
+ this.toggleFlag('internal', 'internal');
};
handleToggleDeprecated = () => {
- const query = parseQuery(this.props.location.query);
- this.updateQuery({ deprecated: !query.deprecated });
+ this.toggleFlag('deprecated', 'deprecatedSince');
};
render() {
);
const latestDeprecation =
allActionsDeprecated &&
- (maxBy(domain.actions, action => {
+ maxBy(domain.actions, action => {
const version = (action.deprecatedSince && parseVersion(action.deprecatedSince)) || noVersion;
return version.major * 1024 + version.minor;
- }) as T.WebApi.Action);
+ });
return latestDeprecation || undefined;
}