From: Grégoire Aubert Date: Thu, 24 Aug 2017 13:08:35 +0000 (+0200) Subject: SONAR-9521 Add sparator between ws descriptions (hum and rewrite to ts) X-Git-Tag: 6.6-RC1~531 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6103fc329f77399dab5fffc8c9688d6285cf67d3;p=sonarqube.git SONAR-9521 Add sparator between ws descriptions (hum and rewrite to ts) --- diff --git a/server/sonar-web/src/main/js/api/web-api.ts b/server/sonar-web/src/main/js/api/web-api.ts index 3bd512e43f9..88c257c4d41 100644 --- a/server/sonar-web/src/main/js/api/web-api.ts +++ b/server/sonar-web/src/main/js/api/web-api.ts @@ -19,6 +19,11 @@ */ import { getJSON } from '../helpers/request'; +export interface Changelog { + description: string; + version: string; +} + export interface Param { key: string; defaultValue?: string; @@ -28,20 +33,22 @@ export interface Param { deprecatedSince?: string; exampleValue?: string; internal: boolean; + maxValuesAllowed?: number; possibleValues?: string[]; required: boolean; + since?: string; } export interface Action { key: string; + changelog: Changelog[]; description: string; deprecatedSince?: string; - since?: string; - internal: boolean; - post: boolean; hasResponseExample: boolean; - changelog: Array<{ version: string; description: string }>; + internal: boolean; params?: Param[]; + post: boolean; + since?: string; } export interface Domain { @@ -50,6 +57,12 @@ export interface Domain { deprecated: boolean; internal: boolean; path: string; + since?: string; +} + +export interface Example { + example: string; + format: string; } export function fetchWebApi(showInternal: boolean = true): Promise> { @@ -62,6 +75,6 @@ export function fetchWebApi(showInternal: boolean = true): Promise ); } -export function fetchResponseExample(domain: string, action: string): Promise<{ example: string }> { +export function fetchResponseExample(domain: string, action: string): Promise { return getJSON('/api/webservices/response_example', { controller: domain, action }); } diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Action.js b/server/sonar-web/src/main/js/apps/web-api/components/Action.js deleted file mode 100644 index 6e84e8a8a5b..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/Action.js +++ /dev/null @@ -1,178 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import { Link } from 'react-router'; -import classNames from 'classnames'; -import { getActionKey } from '../utils'; -import Params from './Params'; -import ResponseExample from './ResponseExample'; -import ActionChangelog from './ActionChangelog'; -import DeprecatedBadge from './DeprecatedBadge'; -import InternalBadge from './InternalBadge'; -import LinkIcon from '../../../components/icons-components/LinkIcon'; -import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin'; -/*:: import type { Action as ActionType, Domain as DomainType } from '../../../api/web-api'; */ - -/*:: -type Props = { - action: ActionType, - domain: DomainType, - showDeprecated: boolean, - showInternal: boolean -}; -*/ - -/*:: -type State = { - showChangelog: boolean, - showParams: boolean, - showResponse: boolean -}; -*/ - -export default class Action extends React.PureComponent { - /*:: props: Props; */ - - state /*: State */ = { - showChangelog: false, - showParams: false, - showResponse: false - }; - - handleShowParamsClick = (e /*: SyntheticInputEvent */) => { - e.preventDefault(); - this.setState({ - showChangelog: false, - showResponse: false, - showParams: !this.state.showParams - }); - }; - - handleShowResponseClick = (e /*: SyntheticInputEvent */) => { - e.preventDefault(); - this.setState({ - showChangelog: false, - showParams: false, - showResponse: !this.state.showResponse - }); - }; - - handleChangelogClick = (e /*: SyntheticInputEvent */) => { - e.preventDefault(); - this.setState({ - showChangelog: !this.state.showChangelog, - showParams: false, - showResponse: false - }); - }; - - render() { - const { action, domain } = this.props; - const { showChangelog, showParams, showResponse } = this.state; - const verb = action.post ? 'POST' : 'GET'; - const actionKey = getActionKey(domain.path, action.key); - - return ( -
- -
- - - - -

- {verb} {actionKey} -

- - {action.internal && - - - } - - {action.since && - - since {action.since} - } - - {action.deprecatedSince && - - - } -
-
- -
- - {(action.params || action.hasResponseExample) && - } - - {showParams && - action.params && - } - - {showResponse && - action.hasResponseExample && - } - - {showChangelog && } -
- ); - } -} 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 new file mode 100644 index 00000000000..92cea769d0a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/Action.tsx @@ -0,0 +1,181 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { Link } from 'react-router'; +import * as classNames from 'classnames'; +import { getActionKey } from '../utils'; +import Params from './Params'; +import ResponseExample from './ResponseExample'; +import ActionChangelog from './ActionChangelog'; +import DeprecatedBadge from './DeprecatedBadge'; +import InternalBadge from './InternalBadge'; +import LinkIcon from '../../../components/icons-components/LinkIcon'; +import { Action as ActionType, Domain as DomainType } from '../../../api/web-api'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; + +interface Props { + action: ActionType; + domain: DomainType; + showDeprecated: boolean; + showInternal: boolean; +} + +interface State { + showChangelog: boolean; + showParams: boolean; + showResponse: boolean; +} + +export default class Action extends React.PureComponent { + state: State = { + showChangelog: false, + showParams: false, + showResponse: false + }; + + handleShowParamsClick = (e: React.SyntheticEvent) => { + e.preventDefault(); + this.setState({ + showChangelog: false, + showResponse: false, + showParams: !this.state.showParams + }); + }; + + handleShowResponseClick = (e: React.SyntheticEvent) => { + e.preventDefault(); + this.setState({ + showChangelog: false, + showParams: false, + showResponse: !this.state.showResponse + }); + }; + + handleChangelogClick = (e: React.SyntheticEvent) => { + e.preventDefault(); + this.setState({ + showChangelog: !this.state.showChangelog, + showParams: false, + showResponse: false + }); + }; + + renderTabs() { + const { action } = this.props; + const { showChangelog, showParams, showResponse } = this.state; + + if (action.params || action.hasResponseExample || action.changelog.length > 0) { + return ( + + ); + } + + return
; + } + + render() { + const { action, domain } = this.props; + const { showChangelog, showParams, showResponse } = this.state; + const verb = action.post ? 'POST' : 'GET'; + const actionKey = getActionKey(domain.path, action.key); + + return ( +
+
+ + + + +

+ {verb} {actionKey} +

+ + {action.internal && + + + } + + {action.since && + + {translateWithParameters('since_x', action.since)} + } + + {action.deprecatedSince && + + + } +
+ +
+ + {this.renderTabs()} + + {showParams && + action.params && + } + + {showResponse && + action.hasResponseExample && + } + + {showChangelog && } +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/ActionChangelog.js b/server/sonar-web/src/main/js/apps/web-api/components/ActionChangelog.js deleted file mode 100644 index ff5b42b5213..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/ActionChangelog.js +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; - -/*:: -type Props = { - changelog: Array<{ - description: string, - version: string - }> -}; -*/ - -export default class ActionChangelog extends React.PureComponent { - /*:: props: Props; */ - - render() { - return ( -
    - {this.props.changelog.map((item, index) => -
  • - - {item.version} - - {item.description} -
  • - )} -
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/ActionChangelog.tsx b/server/sonar-web/src/main/js/apps/web-api/components/ActionChangelog.tsx new file mode 100644 index 00000000000..7e33e9719ae --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/ActionChangelog.tsx @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { Changelog } from '../../../api/web-api'; + +interface Props { + changelog: Changelog[]; +} + +export default function ActionChangelog({ changelog }: Props) { + return ( +
    + {changelog.map((item, index) => +
  • + + {item.version} + + {item.description} +
  • + )} +
+ ); +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/DeprecatedBadge.js b/server/sonar-web/src/main/js/apps/web-api/components/DeprecatedBadge.js deleted file mode 100644 index 988daab5efc..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/DeprecatedBadge.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import { translate } from '../../../helpers/l10n'; - -export default function DeprecatedBadge({ since }) { - const label = since ? `deprecated since ${since}` : 'deprecated'; - - return ( - - {label} - - ); -} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/DeprecatedBadge.tsx b/server/sonar-web/src/main/js/apps/web-api/components/DeprecatedBadge.tsx new file mode 100644 index 00000000000..504d0553823 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/DeprecatedBadge.tsx @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import Tooltip from '../../../components/controls/Tooltip'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; + +export default function DeprecatedBadge({ since }: { since?: string }) { + const label = since + ? translateWithParameters('api_documentation.depracated_since_x', since) + : translate('api_documentation.depracated'); + return ( + + + {label} + + + ); +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Domain.js b/server/sonar-web/src/main/js/apps/web-api/components/Domain.js deleted file mode 100644 index e7240504008..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/Domain.js +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import Action from './Action'; -import DeprecatedBadge from './DeprecatedBadge'; -import InternalBadge from './InternalBadge'; -import { getActionKey, actionsFilter } from '../utils'; -/*:: import type { Domain as DomainType } from '../../../api/web-api'; */ - -/*:: -type Props = { - domain: DomainType, - showDeprecated: boolean, - showInternal: boolean, - searchQuery: string -}; -*/ - -export default class Domain extends React.PureComponent { - /*:: props: Props; */ - - render() { - const { domain, showInternal, showDeprecated, searchQuery } = this.props; - const filteredActions = domain.actions.filter(action => - actionsFilter(showDeprecated, showInternal, searchQuery, domain, action) - ); - - return ( -
-
-

- {domain.path} -

- - {domain.deprecated && - - - } - - {domain.internal && - - - } -
- - {domain.description && -
} - -
- {filteredActions.map(action => - - )} -
-
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Domain.tsx b/server/sonar-web/src/main/js/apps/web-api/components/Domain.tsx new file mode 100644 index 00000000000..8e70e2ed767 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/Domain.tsx @@ -0,0 +1,76 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import Action from './Action'; +import DeprecatedBadge from './DeprecatedBadge'; +import InternalBadge from './InternalBadge'; +import { getActionKey, actionsFilter } from '../utils'; +import { Domain as DomainType } from '../../../api/web-api'; + +interface Props { + domain: DomainType; + showDeprecated: boolean; + showInternal: boolean; + searchQuery: string; +} + +export default function Domain({ domain, showInternal, showDeprecated, searchQuery }: Props) { + const filteredActions = domain.actions.filter(action => + actionsFilter(showDeprecated, showInternal, searchQuery, domain, action) + ); + + return ( +
+
+

+ {domain.path} +

+ + {domain.deprecated && + + + } + + {domain.internal && + + + } +
+ + {domain.description && +
} + +
+ {filteredActions.map(action => + + )} +
+
+ ); +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/InternalBadge.js b/server/sonar-web/src/main/js/apps/web-api/components/InternalBadge.js deleted file mode 100644 index 210d30b9a2c..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/InternalBadge.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import { translate } from '../../../helpers/l10n'; - -export default function InternalBadge() { - return ( - - internal - - ); -} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/InternalBadge.tsx b/server/sonar-web/src/main/js/apps/web-api/components/InternalBadge.tsx new file mode 100644 index 00000000000..4b7ed15fede --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/InternalBadge.tsx @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import Tooltip from '../../../components/controls/Tooltip'; +import { translate } from '../../../helpers/l10n'; + +export default function InternalBadge() { + return ( + + + {translate('internal')} + + + ); +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Menu.js b/server/sonar-web/src/main/js/apps/web-api/components/Menu.js deleted file mode 100644 index 521817badff..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/Menu.js +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import { Link } from 'react-router'; -import classNames from 'classnames'; -import DeprecatedBadge from './DeprecatedBadge'; -import InternalBadge from './InternalBadge'; -import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin'; -import { isDomainPathActive, actionsFilter } from '../utils'; -/*:: import type { Domain as DomainType } from '../../../api/web-api'; */ - -/*:: -type Props = { - domains: Array, - showDeprecated: boolean, - showInternal: boolean, - searchQuery: string, - splat: string -}; -*/ - -export default class Menu extends React.PureComponent { - /*:: props: Props; */ - - render() { - const { domains, showInternal, showDeprecated, searchQuery, splat } = this.props; - const filteredDomains = (domains || []) - .map(domain => { - const filteredActions = domain.actions.filter(action => - actionsFilter(showDeprecated, showInternal, searchQuery, domain, action) - ); - return { ...domain, filteredActions }; - }) - .filter(domain => domain.filteredActions.length); - - return ( -
- -
- {filteredDomains.map(domain => - -

- {domain.path} - {domain.deprecated && } - {domain.internal && } -

- {domain.description && -
} - - )} -
- -
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Menu.tsx b/server/sonar-web/src/main/js/apps/web-api/components/Menu.tsx new file mode 100644 index 00000000000..d33ddade68b --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/Menu.tsx @@ -0,0 +1,72 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { Link } from 'react-router'; +import * as classNames from 'classnames'; +import DeprecatedBadge from './DeprecatedBadge'; +import InternalBadge from './InternalBadge'; +import { isDomainPathActive, actionsFilter } from '../utils'; +import { Domain } from '../../../api/web-api'; + +interface Props { + domains: Domain[]; + showDeprecated: boolean; + showInternal: boolean; + searchQuery: string; + splat: string; +} + +export default function Menu(props: Props) { + const { domains, showInternal, showDeprecated, searchQuery, splat } = props; + const filteredDomains = (domains || []) + .map(domain => { + const filteredActions = domain.actions.filter(action => + actionsFilter(showDeprecated, showInternal, searchQuery, domain, action) + ); + return { ...domain, filteredActions }; + }) + .filter(domain => domain.filteredActions.length); + + return ( +
+
+ {filteredDomains.map(domain => + +

+ {domain.path} + {domain.deprecated && } + {domain.internal && } +

+ {domain.description && +
} + + )} +
+
+ ); +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Params.js b/server/sonar-web/src/main/js/apps/web-api/components/Params.js deleted file mode 100644 index f2e7751c3c0..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/Params.js +++ /dev/null @@ -1,138 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import InternalBadge from './InternalBadge'; -import DeprecatedBadge from './DeprecatedBadge'; -/*:: import type { Param } from '../../../api/web-api'; */ - -export default class Params extends React.PureComponent { - /*:: props: { - showDeprecated: boolean, - showInternal: boolean, - params: Array - }; -*/ - - render() { - const { showDeprecated, showInternal, params } = this.props; - const displayedParameters = params - .filter(p => showDeprecated || !p.deprecatedSince) - .filter(p => showInternal || !p.internal); - return ( -
- - - {displayedParameters.map(param => - - - - - - - - )} - -
- - {param.key} - - - {param.internal && -
- -
} - - {param.deprecatedSince && -
- -
} - - {showDeprecated && - param.deprecatedKey && -
- - {param.deprecatedKey} - -
} - - {showDeprecated && - param.deprecatedKey && - param.deprecatedKeySince && -
- -
} - -
- {param.required ? 'required' : 'optional'} -
- - {param.since && -
- since {param.since} -
} -
-
-
- {param.possibleValues && -
-

Possible values

-
    - {param.possibleValues.map(value => -
  • - - {value} - -
  • - )} -
-
} - - {param.defaultValue && -
-

Default value

- - {param.defaultValue} - -
} - - {param.exampleValue && -
-

Example value

- - {param.exampleValue} - -
} - - {param.maxValuesAllowed != null && -
-

Maximum allowed values

- - {param.maxValuesAllowed} - -
} -
-
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Params.tsx b/server/sonar-web/src/main/js/apps/web-api/components/Params.tsx new file mode 100644 index 00000000000..e0691804e7d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/Params.tsx @@ -0,0 +1,139 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import InternalBadge from './InternalBadge'; +import DeprecatedBadge from './DeprecatedBadge'; +import { Param } from '../../../api/web-api'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; + +interface Props { + params: Param[]; + showDeprecated: boolean; + showInternal: boolean; +} + +export default function Params({ params, showDeprecated, showInternal }: Props) { + const displayedParameters = params + .filter(p => showDeprecated || !p.deprecatedSince) + .filter(p => showInternal || !p.internal); + return ( +
+ + + {displayedParameters.map(param => + + + + + + + + )} + +
+ + {param.key} + + + {param.internal && +
+ +
} + + {param.deprecatedSince && +
+ +
} + + {showDeprecated && + param.deprecatedKey && +
+ + {param.deprecatedKey} + +
} + + {showDeprecated && + param.deprecatedKey && + param.deprecatedKeySince && +
+ +
} + +
+ {param.required ? 'required' : 'optional'} +
+ + {param.since && +
+ {translateWithParameters('since_x', param.since)} +
} +
+
+
+ {param.possibleValues && +
+

+ {translate('api_documentation.possible_values')} +

+
    + {param.possibleValues.map(value => +
  • + + {value} + +
  • + )} +
+
} + + {param.defaultValue && +
+

+ {translate('api_documentation.default_values')} +

+ + {param.defaultValue} + +
} + + {param.exampleValue && +
+

+ {translate('api_documentation.example_values')} +

+ + {param.exampleValue} + +
} + + {param.maxValuesAllowed != null && +
+

+ {translate('api_documentation.max_values')} +

+ + {param.maxValuesAllowed} + +
} +
+
+ ); +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/ResponseExample.js b/server/sonar-web/src/main/js/apps/web-api/components/ResponseExample.js deleted file mode 100644 index 88bf4973bec..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/ResponseExample.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import { fetchResponseExample as fetchResponseExampleApi } from '../../../api/web-api'; - -export default class ResponseExample extends React.PureComponent { - state = {}; - - componentDidMount() { - this.mounted = true; - this.fetchResponseExample(); - } - - componentDidUpdate(nextProps) { - if (nextProps.action !== this.props.action) { - this.fetchResponseExample(); - } - } - - componentWillUnmount() { - this.mounted = false; - } - - fetchResponseExample() { - const { domain, action } = this.props; - fetchResponseExampleApi(domain.path, action.key).then(responseExample => - this.setState({ responseExample }) - ); - } - - render() { - const { responseExample } = this.state; - - return ( -
- {responseExample && -
-            {responseExample.example}
-          
} -
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/ResponseExample.tsx b/server/sonar-web/src/main/js/apps/web-api/components/ResponseExample.tsx new file mode 100644 index 00000000000..746fb398e11 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/ResponseExample.tsx @@ -0,0 +1,75 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { + Action, + Domain, + Example, + fetchResponseExample as fetchResponseExampleApi +} from '../../../api/web-api'; + +interface Props { + action: Action; + domain: Domain; +} + +interface State { + responseExample?: Example; +} + +export default class ResponseExample extends React.PureComponent { + mounted: boolean; + state: State = {}; + + componentDidMount() { + this.mounted = true; + this.fetchResponseExample(); + } + + componentDidUpdate(nextProps: Props) { + if (nextProps.action !== this.props.action) { + this.fetchResponseExample(); + } + } + + componentWillUnmount() { + this.mounted = false; + } + + fetchResponseExample() { + const { domain, action } = this.props; + fetchResponseExampleApi(domain.path, action.key).then(responseExample => + this.setState({ responseExample }) + ); + } + + render() { + const { responseExample } = this.state; + + return ( +
+ {responseExample && +
+            {responseExample.example}
+          
} +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Search.js b/server/sonar-web/src/main/js/apps/web-api/components/Search.js deleted file mode 100644 index c08bbb8bb2e..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/Search.js +++ /dev/null @@ -1,110 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import { debounce } from 'lodash'; -import Checkbox from '../../../components/controls/Checkbox'; -import HelpIcon from '../../../components/icons-components/HelpIcon'; -import Tooltip from '../../../components/controls/Tooltip'; -import { translate } from '../../../helpers/l10n'; - -/*:: -type Props = { - showDeprecated: boolean, - showInternal: boolean, - onSearch: string => void, - onToggleInternal: () => void, - onToggleDeprecated: () => void -}; -*/ - -/*:: -type State = { - query: string -}; -*/ - -export default class Search extends React.PureComponent { - /*:: actuallySearch: () => void; */ - /*:: props: Props; */ - /*:: state: State; */ - - constructor(props /*: Props */) { - super(props); - this.state = { query: '' }; - this.actuallySearch = debounce(this.actuallySearch, 250); - } - - handleSearch = (e /*: SyntheticInputEvent */) => { - const { value } = e.target; - this.setState({ query: value }); - this.actuallySearch(); - }; - - actuallySearch = () => { - const { onSearch } = this.props; - onSearch(this.state.query); - }; - - render() { - const { showInternal, showDeprecated, onToggleInternal, onToggleDeprecated } = this.props; - - return ( -
-
- - -
- -
- - - {translate('api_documentation.show_deprecated')} - - - - - - - -
- -
- - - {translate('api_documentation.show_internal')} - - - - - - - -
-
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Search.tsx b/server/sonar-web/src/main/js/apps/web-api/components/Search.tsx new file mode 100644 index 00000000000..ab64ad6167e --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/Search.tsx @@ -0,0 +1,97 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { debounce } from 'lodash'; +import Checkbox from '../../../components/controls/Checkbox'; +import HelpIcon from '../../../components/icons-components/HelpIcon'; +import Tooltip from '../../../components/controls/Tooltip'; +import { translate } from '../../../helpers/l10n'; + +interface Props { + showDeprecated: boolean; + showInternal: boolean; + onSearch: (search: string) => void; + onToggleInternal: () => void; + onToggleDeprecated: () => void; +} + +interface State { + query: string; +} + +export default class Search extends React.PureComponent { + constructor(props: Props) { + super(props); + this.state = { query: '' }; + this.actuallySearch = debounce(this.actuallySearch, 250); + } + + handleSearch = (e: React.SyntheticEvent) => { + this.setState({ query: e.currentTarget.value }); + this.actuallySearch(); + }; + + actuallySearch = () => this.props.onSearch(this.state.query); + + render() { + const { showInternal, showDeprecated, onToggleInternal, onToggleDeprecated } = this.props; + + return ( +
+
+ + +
+ +
+ + + {translate('api_documentation.show_internal')} + + + + + + + +
+ +
+ + + {translate('api_documentation.show_deprecated')} + + + + + + + +
+
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.js b/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.js deleted file mode 100644 index a8e8eadb27e..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.js +++ /dev/null @@ -1,202 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import PropTypes from 'prop-types'; -import Helmet from 'react-helmet'; -import { Link } from 'react-router'; -import { fetchWebApi } from '../../../api/web-api'; -import Menu from './Menu'; -import Search from './Search'; -import Domain from './Domain'; -import { getActionKey, isDomainPathActive } from '../utils'; -import { translate } from '../../../helpers/l10n'; -/*:: import type { Domain as DomainType } from '../../../api/web-api'; */ -import '../styles/web-api.css'; - -/*:: -type State = { - domains: Array, - searchQuery: string, - showDeprecated: boolean, - showInternal: boolean -}; -*/ - -export default class WebApiApp extends React.PureComponent { - /*:: mounted: boolean; */ - /*:: scrollToAction: () => void; */ - state /*: State */ = { - domains: [], - searchQuery: '', - showDeprecated: false, - showInternal: false - }; - - componentDidMount() { - this.mounted = true; - this.fetchList(); - const footer = document.getElementById('footer'); - if (footer) { - footer.classList.add('search-navigator-footer'); - } - } - - componentDidUpdate() { - this.toggleInternalInitially(); - this.scrollToAction(); - } - - componentWillUnmount() { - this.mounted = false; - const footer = document.getElementById('footer'); - if (footer) { - footer.classList.remove('search-navigator-footer'); - } - } - - fetchList(cb /*: void | () => void */) { - fetchWebApi().then(domains => { - if (this.mounted) { - this.setState({ domains }, cb); - } - }); - } - - scrollToAction = () => { - const splat = this.props.params.splat || ''; - this.scrollToElement(splat); - }; - - scrollToElement(id /*: string */) { - const element = document.getElementById(id); - - if (element) { - const rect = element.getBoundingClientRect(); - const top = rect.top + window.pageYOffset - 20; - - window.scrollTo(0, top); - } else { - window.scrollTo(0, 0); - } - } - - toggleInternalInitially() { - const splat = this.props.params.splat || ''; - const { domains, showInternal } = this.state; - - if (!showInternal) { - domains.forEach(domain => { - if (domain.path === splat && domain.internal) { - this.setState({ showInternal: true }); - } - domain.actions.forEach(action => { - const actionKey = getActionKey(domain.path, action.key); - if (actionKey === splat && action.internal) { - this.setState({ showInternal: true }); - } - }); - }); - } - } - - handleSearch = (searchQuery /*: string */) => { - this.setState({ searchQuery }); - }; - - handleToggleInternal = () => { - const splat = this.props.params.splat || ''; - const { router } = this.context; - const { domains } = this.state; - const domain = domains.find(domain => isDomainPathActive(domain.path, splat)); - const showInternal = !this.state.showInternal; - - if (domain && domain.internal && !showInternal) { - router.push('/web_api'); - } - - this.setState({ showInternal }); - }; - - handleToggleDeprecated = () => { - this.setState(state => ({ showDeprecated: !state.showDeprecated })); - }; - - render() { - const splat = this.props.params.splat || ''; - const { domains, showInternal, showDeprecated, searchQuery } = this.state; - - const domain = domains.find(domain => isDomainPathActive(domain.path, splat)); - - return ( -
- -
-
-
-
-
- -

- {translate('api_documentation.page')} -

- -
- - - - -
-
-
-
- -
-
- {domain && - } -
-
-
- ); - } -} - -WebApiApp.contextTypes = { - router: PropTypes.object.isRequired -}; 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 new file mode 100644 index 00000000000..9a346b3f921 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx @@ -0,0 +1,191 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import * as PropTypes from 'prop-types'; +import Helmet from 'react-helmet'; +import { Link } from 'react-router'; +import { Domain as DomainType, fetchWebApi } from '../../../api/web-api'; +import Menu from './Menu'; +import Search from './Search'; +import Domain from './Domain'; +import { getActionKey, isDomainPathActive } from '../utils'; +import { scrollToElement } from '../../../helpers/scrolling'; +import { translate } from '../../../helpers/l10n'; +import '../styles/web-api.css'; + +interface Props { + params: { splat?: string }; +} + +interface State { + domains: DomainType[]; + searchQuery: string; + showDeprecated: boolean; + showInternal: boolean; +} + +export default class WebApiApp extends React.PureComponent { + mounted: boolean; + state: State = { + domains: [], + searchQuery: '', + showDeprecated: false, + showInternal: false + }; + + static contextTypes = { + router: PropTypes.object.isRequired + }; + + componentDidMount() { + this.mounted = true; + this.fetchList(); + const footer = document.getElementById('footer'); + if (footer) { + footer.classList.add('search-navigator-footer'); + } + } + + componentDidUpdate() { + this.toggleInternalInitially(); + this.scrollToAction(); + } + + componentWillUnmount() { + this.mounted = false; + const footer = document.getElementById('footer'); + if (footer) { + footer.classList.remove('search-navigator-footer'); + } + } + + fetchList(cb?: () => void) { + fetchWebApi().then(domains => { + if (this.mounted) { + this.setState({ domains }, cb); + } + }); + } + + scrollToAction = () => { + const splat = this.props.params.splat || ''; + const action = document.getElementById(splat); + if (action) { + scrollToElement(action, { topOffset: 20, bottomOffset: 20 }); + } else { + window.scrollTo(0, 0); + } + }; + + toggleInternalInitially() { + const splat = this.props.params.splat || ''; + const { domains, showInternal } = this.state; + + if (!showInternal) { + domains.forEach(domain => { + if (domain.path === splat && domain.internal) { + this.setState({ showInternal: true }); + } + domain.actions.forEach(action => { + const actionKey = getActionKey(domain.path, action.key); + if (actionKey === splat && action.internal) { + this.setState({ showInternal: true }); + } + }); + }); + } + } + + handleSearch = (searchQuery: string) => this.setState({ searchQuery }); + + handleToggleInternal = () => { + const splat = this.props.params.splat || ''; + const { router } = this.context; + const { domains } = this.state; + const domain = domains.find(domain => isDomainPathActive(domain.path, splat)); + const showInternal = !this.state.showInternal; + + if (domain && domain.internal && !showInternal) { + router.push('/web_api'); + } + + this.setState({ showInternal }); + }; + + handleToggleDeprecated = () => + this.setState(state => ({ showDeprecated: !state.showDeprecated })); + + render() { + const splat = this.props.params.splat || ''; + const { domains, showInternal, showDeprecated, searchQuery } = this.state; + + const domain = domains.find(domain => isDomainPathActive(domain.path, splat)); + + return ( +
+ +
+
+
+
+
+ +

+ {translate('api_documentation.page')} +

+ +
+ + + + +
+
+
+
+ +
+
+ {domain && + } +
+
+
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Action-test.tsx b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Action-test.tsx new file mode 100644 index 00000000000..98c97e6134b --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Action-test.tsx @@ -0,0 +1,75 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import Action from '../Action'; + +const ACTION = { + key: 'foo', + changelog: [{ description: 'Changelog desc', version: '5.0' }], + description: 'Foo Desc', + hasResponseExample: true, + internal: false, + params: [ + { + key: 'param', + description: 'Param desc', + internal: true, + required: true + } + ], + post: false +}; +const DOMAIN = { + actions: [ACTION], + path: 'foo', + description: 'API Foo', + deprecated: false, + internal: false +}; + +const PROPS = { + action: ACTION, + domain: DOMAIN, + showDeprecated: false, + showInternal: false +}; + +it('should render correctly', () => { + expect(shallow()).toMatchSnapshot(); +}); + +it('should display the params', () => { + const wrapper = shallow(); + wrapper.setState({ showParams: true }); + expect(wrapper.find('Params')).toMatchSnapshot(); +}); + +it('should display the response example', () => { + const wrapper = shallow(); + wrapper.setState({ showResponse: true }); + expect(wrapper.find('ResponseExample')).toMatchSnapshot(); +}); + +it('should display the changelog', () => { + const wrapper = shallow(); + wrapper.setState({ showChangelog: true }); + expect(wrapper.find('ActionChangelog')).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ActionChangelog-test.js b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ActionChangelog-test.js deleted file mode 100644 index 380213bf33a..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ActionChangelog-test.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import { shallow } from 'enzyme'; -import ActionChangelog from '../ActionChangelog'; - -it('should render', () => { - const changelog = [ - { version: '5.0', description: 'foo' }, - { version: '5.1', description: 'bar' } - ]; - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ActionChangelog-test.tsx b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ActionChangelog-test.tsx new file mode 100644 index 00000000000..d05d9ec184f --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ActionChangelog-test.tsx @@ -0,0 +1,30 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import ActionChangelog from '../ActionChangelog'; + +it('should render', () => { + const changelog = [ + { version: '5.0', description: 'foo' }, + { version: '5.1', description: 'bar' } + ]; + expect(shallow()).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Domain-test.js b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Domain-test.js deleted file mode 100644 index 5608b8c5987..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Domain-test.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import { shallow } from 'enzyme'; -import Domain from '../Domain'; - -it('should render deprecated actions', () => { - const actions = [{ key: 'foo', deprecatedSince: '5.0' }]; - const domain = { actions, path: 'api' }; - expect( - shallow() - ).toMatchSnapshot(); -}); - -it('should not render deprecated actions', () => { - const actions = [{ key: 'foo', deprecatedSince: '5.0' }]; - const domain = { actions, path: 'api' }; - expect( - shallow() - ).toMatchSnapshot(); -}); - -it('should render internal actions', () => { - const actions = [{ key: 'foo', internal: true }]; - const domain = { actions, path: 'api' }; - expect(shallow()).toMatchSnapshot(); -}); - -it('should not render internal actions', () => { - const actions = [{ key: 'foo', internal: true }]; - const domain = { actions, path: 'api' }; - expect(shallow()).toMatchSnapshot(); -}); - -it('should render only actions matching the query', () => { - const actions = [{ key: 'foo' }, { key: 'bar' }]; - const domain = { actions, path: 'api' }; - expect(shallow()).toMatchSnapshot(); -}); - -it('should also render actions with a description matching the query', () => { - const actions = [{ key: 'foo', description: 'foobar' }, { key: 'bar' }, { key: 'baz' }]; - const domain = { actions, path: 'api' }; - expect( - shallow() - ).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Domain-test.tsx b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Domain-test.tsx new file mode 100644 index 00000000000..4114f4944e0 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Domain-test.tsx @@ -0,0 +1,96 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import Domain from '../Domain'; + +const ACTION = { + key: 'foo', + changelog: [], + description: 'Foo Desc', + hasResponseExample: false, + internal: false, + post: false +}; +const DOMAIN = { + actions: [ACTION], + path: 'api', + description: 'API Desc', + deprecated: false, + internal: false +}; +const DEFAULT_PROPS = { + domain: DOMAIN, + showDeprecated: false, + showInternal: false, + searchQuery: '' +}; + +it('should render deprecated actions', () => { + const action = { ...ACTION, deprecatedSince: '5.0' }; + const domain = { ...DOMAIN, actions: [action] }; + expect( + shallow() + ).toMatchSnapshot(); +}); + +it('should not render deprecated actions', () => { + const action = { ...ACTION, deprecatedSince: '5.0' }; + const domain = { ...DOMAIN, actions: [action] }; + expect( + shallow() + ).toMatchSnapshot(); +}); + +it('should render internal actions', () => { + const action = { ...ACTION, internal: true }; + const domain = { ...DOMAIN, actions: [action] }; + expect( + shallow() + ).toMatchSnapshot(); +}); + +it('should not render internal actions', () => { + const action = { ...ACTION, internal: true }; + const domain = { ...DOMAIN, actions: [action] }; + expect( + shallow() + ).toMatchSnapshot(); +}); + +it('should render only actions matching the query', () => { + const actions = [ACTION, { ...ACTION, key: 'bar', description: 'Bar desc' }]; + const domain = { ...DOMAIN, actions: actions }; + expect( + shallow() + ).toMatchSnapshot(); +}); + +it('should also render actions with a description matching the query', () => { + const actions = [ + ACTION, + { ...ACTION, key: 'bar', description: 'Bar desc' }, + { ...ACTION, key: 'baz', description: 'foobar' } + ]; + const domain = { ...DOMAIN, actions: actions }; + expect( + shallow() + ).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Menu-test.tsx b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Menu-test.tsx new file mode 100644 index 00000000000..198f04ac895 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Menu-test.tsx @@ -0,0 +1,104 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import Menu from '../Menu'; + +const ACTION = { + key: 'foo', + changelog: [], + description: 'Foo Desc', + hasResponseExample: false, + internal: false, + post: false +}; +const DOMAIN1 = { + actions: [ACTION], + path: 'foo', + description: 'API Foo', + deprecated: false, + internal: false +}; +const DOMAIN2 = { + actions: [ACTION], + path: 'bar', + description: 'API Bar', + deprecated: false, + internal: false +}; +const PROPS = { + domains: [DOMAIN1, DOMAIN2], + showDeprecated: false, + showInternal: false, + searchQuery: '', + splat: '' +}; + +it('should render deprecated domains', () => { + const domain = { + ...DOMAIN2, + deprecatedSince: '5.0', + actions: [{ ...ACTION, deprecatedSince: '5.0' }] + }; + const domains = [DOMAIN1, domain]; + expect(shallow()).toMatchSnapshot(); +}); + +it('should not render deprecated domains', () => { + const domain = { + ...DOMAIN2, + deprecatedSince: '5.0', + actions: [{ ...ACTION, deprecatedSince: '5.0' }] + }; + const domains = [DOMAIN1, domain]; + expect(shallow()).toMatchSnapshot(); +}); + +it('should render internal domains', () => { + const domain = { ...DOMAIN2, internal: true, actions: [{ ...ACTION, internal: true }] }; + const domains = [DOMAIN1, domain]; + expect(shallow()).toMatchSnapshot(); +}); + +it('should not render internal domains', () => { + const domain = { ...DOMAIN2, internal: true, actions: [{ ...ACTION, internal: true }] }; + const domains = [DOMAIN1, domain]; + expect(shallow()).toMatchSnapshot(); +}); + +it('should render only domains with an action matching the query', () => { + const domain = { + ...DOMAIN2, + actions: [{ ...ACTION, key: 'bar', path: 'bar', description: 'Bar Desc' }] + }; + const domains = [DOMAIN1, domain]; + expect(shallow()).toMatchSnapshot(); +}); + +it('should also render domains with an actions description matching the query', () => { + const domain = { + ...DOMAIN1, + path: 'baz', + description: 'API Baz', + actions: [{ ...ACTION, key: 'baz', path: 'baz', description: 'barbaz' }] + }; + const domains = [DOMAIN1, DOMAIN2, domain]; + expect(shallow()).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Params-test.js b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Params-test.js deleted file mode 100644 index e8ca685eaea..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Params-test.js +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import { shallow } from 'enzyme'; -import Params from '../Params'; - -it('should render deprecated parameters', () => { - const params = [ - { - key: 'foo', - deprecatedSince: '5.0' - } - ]; - expect(shallow()).toMatchSnapshot(); -}); - -it('should not render deprecated parameters', () => { - const params = [ - { - key: 'foo', - deprecatedSince: '5.0' - } - ]; - expect(shallow()).toMatchSnapshot(); -}); - -it('should render deprecated key', () => { - const params = [ - { - key: 'foo', - deprecatedKey: 'foo-deprecated', - deprecatedKeySince: '5.0' - } - ]; - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Params-test.tsx b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Params-test.tsx new file mode 100644 index 00000000000..480b56f26f0 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Params-test.tsx @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import Params from '../Params'; + +const DEFAULT_PARAM = { + key: 'foo', + description: 'Foo desc', + internal: false, + required: false +}; + +it('should render deprecated and internal parameters', () => { + const params = [ + { ...DEFAULT_PARAM, deprecatedSince: '5.0' }, + { ...DEFAULT_PARAM, deprecatedSince: '5.0', internal: true } + ]; + expect( + shallow() + ).toMatchSnapshot(); +}); + +it('should not render deprecated parameters', () => { + const params = [{ ...DEFAULT_PARAM, deprecatedSince: '5.0' }]; + expect( + shallow() + ).toMatchSnapshot(); +}); + +it('should render deprecated key', () => { + const params = [ + { ...DEFAULT_PARAM, deprecatedKey: 'foo-deprecated', deprecatedSince: '5.0' }, + { ...DEFAULT_PARAM, deprecatedSince: '5.0', internal: true } + ]; + expect( + shallow() + ).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ResponseExample-test.tsx b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ResponseExample-test.tsx new file mode 100644 index 00000000000..5e90e29d23f --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/ResponseExample-test.tsx @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import ResponseExample from '../ResponseExample'; + +const ACTION = { + key: 'foo', + changelog: [], + description: 'Foo Desc', + hasResponseExample: false, + internal: false, + post: false +}; +const DOMAIN = { + actions: [ACTION], + path: 'foo', + description: 'API Foo', + deprecated: false, + internal: false +}; + +const PROPS = { + action: ACTION, + domain: DOMAIN +}; + +it('should render correctly after fetching an example', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + wrapper.setState({ responseExample: { format: 'json', example: 'my example' } }); + expect(wrapper).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Search-test.tsx b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Search-test.tsx new file mode 100644 index 00000000000..a7f6a81210a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/Search-test.tsx @@ -0,0 +1,34 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import Search from '../Search'; + +const PROPS = { + showDeprecated: false, + showInternal: false, + onSearch: () => {}, + onToggleInternal: () => {}, + onToggleDeprecated: () => {} +}; + +it('should render correctly', () => { + expect(shallow()).toMatchSnapshot(); +}); 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 new file mode 100644 index 00000000000..02cc7f1b708 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Action-test.tsx.snap @@ -0,0 +1,160 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should display the changelog 1`] = ` + +`; + +exports[`should display the params 1`] = ` + +`; + +exports[`should display the response example 1`] = ` + +`; + +exports[`should render correctly 1`] = ` +
+
+ + + +

+ GET +   + foo/foo +

+
+ +`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ActionChangelog-test.js.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ActionChangelog-test.js.snap deleted file mode 100644 index 8c3eb7ace6d..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ActionChangelog-test.js.snap +++ /dev/null @@ -1,28 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render 1`] = ` -
    -
  • - - 5.0 - - foo -
  • -
  • - - 5.1 - - bar -
  • -
-`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ActionChangelog-test.tsx.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ActionChangelog-test.tsx.snap new file mode 100644 index 00000000000..8c3eb7ace6d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ActionChangelog-test.tsx.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render 1`] = ` +
    +
  • + + 5.0 + + foo +
  • +
  • + + 5.1 + + bar +
  • +
+`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Domain-test.js.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Domain-test.js.snap deleted file mode 100644 index 8a1c7fd8843..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Domain-test.js.snap +++ /dev/null @@ -1,230 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should also render actions with a description matching the query 1`] = ` -
-
-

- api -

-
-
- - -
-
-`; - -exports[`should not render deprecated actions 1`] = ` -
-
-

- api -

-
-
-
-`; - -exports[`should not render internal actions 1`] = ` -
-
-

- api -

-
-
-
-`; - -exports[`should render deprecated actions 1`] = ` -
-
-

- api -

-
-
- -
-
-`; - -exports[`should render internal actions 1`] = ` -
-
-

- api -

-
-
- -
-
-`; - -exports[`should render only actions matching the query 1`] = ` -
-
-

- api -

-
-
- -
-
-`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Domain-test.tsx.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Domain-test.tsx.snap new file mode 100644 index 00000000000..e1c93d26f4a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Domain-test.tsx.snap @@ -0,0 +1,369 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should also render actions with a description matching the query 1`] = ` +
+
+

+ api +

+
+
+
+ + +
+
+`; + +exports[`should not render deprecated actions 1`] = ` +
+
+

+ api +

+
+
+
+
+`; + +exports[`should not render internal actions 1`] = ` +
+
+

+ api +

+
+
+
+
+`; + +exports[`should render deprecated actions 1`] = ` +
+
+

+ api +

+
+
+
+ +
+
+`; + +exports[`should render internal actions 1`] = ` +
+
+

+ api +

+
+
+
+ +
+
+`; + +exports[`should render only actions matching the query 1`] = ` +
+
+

+ api +

+
+
+
+ +
+
+`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Menu-test.tsx.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Menu-test.tsx.snap new file mode 100644 index 00000000000..34329aa2fbf --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Menu-test.tsx.snap @@ -0,0 +1,248 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should also render domains with an actions description matching the query 1`] = ` +
+
+ +

+ bar +

+
+ + +

+ baz +

+
+ +
+
+`; + +exports[`should not render deprecated domains 1`] = ` +
+
+ +

+ foo +

+
+ +
+
+`; + +exports[`should not render internal domains 1`] = ` +
+
+ +

+ foo +

+
+ +
+
+`; + +exports[`should render deprecated domains 1`] = ` +
+
+ +

+ foo +

+
+ + +

+ bar +

+
+ +
+
+`; + +exports[`should render internal domains 1`] = ` +
+
+ +

+ foo +

+
+ + +

+ bar + +

+
+ +
+
+`; + +exports[`should render only domains with an action matching the query 1`] = ` +
+
+ +

+ foo +

+
+ +
+
+`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Params-test.js.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Params-test.js.snap deleted file mode 100644 index 294cc61c75a..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Params-test.js.snap +++ /dev/null @@ -1,126 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should not render deprecated parameters 1`] = ` -
- - -
-
-`; - -exports[`should render deprecated key 1`] = ` -
- - - - - - - -
- - foo - -
- - foo-deprecated - -
-
- -
-
- optional -
-
-
-
-
-
-`; - -exports[`should render deprecated parameters 1`] = ` -
- - - - - - - -
- - foo - -
- -
-
- optional -
-
-
-
-
-
-`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Params-test.tsx.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Params-test.tsx.snap new file mode 100644 index 00000000000..c6a75522309 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Params-test.tsx.snap @@ -0,0 +1,174 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should not render deprecated parameters 1`] = ` +
+ + +
+
+`; + +exports[`should render deprecated and internal parameters 1`] = ` +
+ + + + + + + + + + + +
+ + foo + +
+ +
+
+ optional +
+
+
+
+
+ + foo + +
+ +
+
+ +
+
+ optional +
+
+
+
+
+
+`; + +exports[`should render deprecated key 1`] = ` +
+ + + + + + + +
+ + foo + +
+ +
+
+ + foo-deprecated + +
+
+ optional +
+
+
+
+
+
+`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ResponseExample-test.tsx.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ResponseExample-test.tsx.snap new file mode 100644 index 00000000000..fd3c8003bda --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/ResponseExample-test.tsx.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly after fetching an example 1`] = ` +
+`; + +exports[`should render correctly after fetching an example 2`] = ` +
+
+    my example
+  
+
+`; diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Search-test.tsx.snap b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Search-test.tsx.snap new file mode 100644 index 00000000000..2e4b787f7fe --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/__snapshots__/Search-test.tsx.snap @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` +
+
+ + +
+
+ + + api_documentation.show_internal + + + + + + + +
+
+ + + api_documentation.show_deprecated + + + + + + + +
+
+`; diff --git a/server/sonar-web/src/main/js/apps/web-api/styles/web-api.css b/server/sonar-web/src/main/js/apps/web-api/styles/web-api.css index 627ac47564e..2b177063afd 100644 --- a/server/sonar-web/src/main/js/apps/web-api/styles/web-api.css +++ b/server/sonar-web/src/main/js/apps/web-api/styles/web-api.css @@ -48,6 +48,11 @@ margin-top: 10px; } +.web-api-action hr { + margin: 10px 0 0; + background-color: #ddd; +} + .web-api-params, .web-api-response { margin-top: 10px; diff --git a/server/sonar-web/src/main/js/apps/web-api/utils.js b/server/sonar-web/src/main/js/apps/web-api/utils.js deleted file mode 100644 index 5610c47142b..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api/utils.js +++ /dev/null @@ -1,58 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -//@flow -/*:: import type { Domain, Action } from '../../api/web-api'; */ - -export function actionsFilter( - showDeprecated /*: boolean */, - showInternal /*: boolean */, - searchQuery /*: string */, - domain /*: Domain */, - action /*: Action */ -) { - const lowSearchQuery = searchQuery.toLowerCase(); - return ( - (showInternal || !action.internal) && - (showDeprecated || !action.deprecatedSince) && - (getActionKey(domain.path, action.key).includes(lowSearchQuery) || - (action.description || '').toLowerCase().includes(lowSearchQuery)) - ); -} - -export function getActionKey(domainPath /*: string */, actionKey /*: string */) { - return domainPath + '/' + actionKey; -} - -export const isDomainPathActive = (path /*: string */, splat /*: string */) => { - const pathTokens = path.split('/'); - const splatTokens = splat.split('/'); - - if (pathTokens.length > splatTokens.length) { - return false; - } - - for (let i = 0; i < pathTokens.length; i++) { - if (pathTokens[i] !== splatTokens[i]) { - return false; - } - } - - return true; -}; 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 new file mode 100644 index 00000000000..9614fa4ecfd --- /dev/null +++ b/server/sonar-web/src/main/js/apps/web-api/utils.ts @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { Domain, Action } from '../../api/web-api'; + +export function actionsFilter( + showDeprecated: boolean, + showInternal: boolean, + searchQuery: string, + domain: Domain, + action: Action +) { + const lowSearchQuery = searchQuery.toLowerCase(); + return ( + (showInternal || !action.internal) && + (showDeprecated || !action.deprecatedSince) && + (getActionKey(domain.path, action.key).includes(lowSearchQuery) || + (action.description || '').toLowerCase().includes(lowSearchQuery)) + ); +} + +export function getActionKey(domainPath: string, actionKey: string) { + return domainPath + '/' + actionKey; +} + +export const isDomainPathActive = (path: string, splat: string) => { + const pathTokens = path.split('/'); + const splatTokens = splat.split('/'); + + if (pathTokens.length > splatTokens.length) { + return false; + } + + for (let i = 0; i < pathTokens.length; i++) { + if (pathTokens[i] !== splatTokens[i]) { + return false; + } + } + + return true; +}; diff --git a/server/sonar-web/src/main/js/components/icons-components/LinkIcon.js b/server/sonar-web/src/main/js/components/icons-components/LinkIcon.js deleted file mode 100644 index 7d09ef2b635..00000000000 --- a/server/sonar-web/src/main/js/components/icons-components/LinkIcon.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; - -/*:: type Props = { className?: string, size?: number }; */ - -export default function LinkIcon({ className, size = 14 } /*: Props */) { - /* eslint-disable max-len */ - return ( - - - - ); -} diff --git a/server/sonar-web/src/main/js/components/icons-components/LinkIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/LinkIcon.tsx new file mode 100644 index 00000000000..80cc7765a52 --- /dev/null +++ b/server/sonar-web/src/main/js/components/icons-components/LinkIcon.tsx @@ -0,0 +1,42 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; + +interface Props { + className?: string; + size?: number; +} + +export default function LinkIcon({ className, size = 14 }: Props) { + /* eslint-disable max-len */ + return ( + + + + ); +} 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 b494866ac8d..d5cc057a13a 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2875,6 +2875,17 @@ api_documentation.internal_tooltip=Use at your own risk; internal services are s api_documentation.page=Web API api_documentation.show_deprecated=Show Deprecated API api_documentation.show_internal=Show Internal API +api_documentation.possible_values=Possible values +api_documentation.default_values=Default value +api_documentation.example_values=Example value +api_documentation.max_values=Maximum allowed values +api_documentation.internal=internal +api_documentation.deprecated=deprecated +api_documentation.depracated_since_x=deprecated since {0} +api_documentation.parameters=Parameters +api_documentation.response_example=Response Example +api_documentation.changelog=Changelog + #------------------------------------------------------------------------------ #