From 4167ce59384f8bfcfe004d984ddef2892a40995a Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 19 Dec 2018 11:52:49 +0100 Subject: [PATCH] SONAR-10853 align ux for deprecated and internal flags on web api page --- .../js/apps/web-api/components/Action.tsx | 10 ++++- .../js/apps/web-api/components/WebApiApp.tsx | 45 ++++++++++--------- .../__snapshots__/Action-test.tsx.snap | 1 + .../src/main/js/apps/web-api/utils.ts | 2 +- .../resources/org/sonar/l10n/core.properties | 1 + 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Action.tsx b/server/sonar-web/src/main/js/apps/web-api/components/Action.tsx index c0e65191ee8..fb7baf5f0a7 100644 --- a/server/sonar-web/src/main/js/apps/web-api/components/Action.tsx +++ b/server/sonar-web/src/main/js/apps/web-api/components/Action.tsx @@ -25,7 +25,7 @@ import ResponseExample from './ResponseExample'; 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'; @@ -133,7 +133,13 @@ export default class Action extends React.PureComponent {
+ to={{ + pathname: '/web_api/' + actionKey, + query: serializeQuery({ + deprecated: Boolean(action.deprecatedSince), + internal: Boolean(action.internal) + }) + }}> diff --git a/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx b/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx index 8cb09db5f21..ce164dd22b3 100644 --- a/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx +++ b/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx @@ -57,7 +57,7 @@ class WebApiApp extends React.PureComponent { } componentDidUpdate() { - this.toggleInternalInitially(); + this.enforceFlags(); this.scrollToAction(); } @@ -100,21 +100,20 @@ class WebApiApp extends React.PureComponent { 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 }); } } } @@ -123,27 +122,29 @@ class WebApiApp extends React.PureComponent { 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() { @@ -202,9 +203,9 @@ function getLatestDeprecatedAction(domain: Pick) { ); 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; } diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Action-test.tsx.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Action-test.tsx.snap index ac543cd86e3..5d5142d1c66 100644 --- a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Action-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Action-test.tsx.snap @@ -104,6 +104,7 @@ exports[`should render correctly 1`] = ` to={ Object { "pathname": "/web_api/foo/foo", + "query": Object {}, } } > diff --git a/server/sonar-web/src/main/js/apps/web-api/utils.ts b/server/sonar-web/src/main/js/apps/web-api/utils.ts index c4058d5c27d..e060cd557dd 100644 --- a/server/sonar-web/src/main/js/apps/web-api/utils.ts +++ b/server/sonar-web/src/main/js/apps/web-api/utils.ts @@ -72,7 +72,7 @@ export const parseQuery = memoize( ); export const serializeQuery = memoize( - (query: Query): RawQuery => + (query: Partial): RawQuery => cleanQuery({ query: query.search ? serializeString(query.search) : undefined, deprecated: query.deprecated || undefined, diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 4048b410921..5d9e42082a1 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -81,6 +81,7 @@ info=Info issue=Issue issues=Issues inheritance=Inheritance +internal=internal key=Key language=Language last_analysis=Last Analysis -- 2.39.5