From 80e5b85977523f14c1bb14ea90cb0cc73f4aa59d Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Sep 2021 15:55:09 +0200 Subject: [PATCH] SONAR-15366 Add Settings Search feature --- .../js/apps/settings/__tests__/utils-test.ts | 38 +++- .../settings/components/DefinitionsList.tsx | 9 +- .../apps/settings/components/PageHeader.tsx | 10 +- .../settings/components/SettingsSearch.tsx | 194 ++++++++++++++++++ .../components/SettingsSearchRenderer.tsx | 103 ++++++++++ .../components/SubCategoryDefinitionsList.tsx | 10 +- .../components/__tests__/PageHeader-test.tsx | 2 +- .../__tests__/SettingsSearch-test.tsx | 143 +++++++++++++ .../__tests__/SettingsSearchRenderer-test.tsx | 79 +++++++ .../__snapshots__/PageHeader-test.tsx.snap | 23 ++- .../SettingsSearchRenderer-test.tsx.snap | 142 +++++++++++++ .../SubCategoryDefinitionsList-test.tsx.snap | 3 + .../almIntegration/AlmIntegration.tsx | 13 +- .../__tests__/AlmIntegration-test.tsx | 16 +- .../js/apps/settings/store/rootReducer.ts | 4 + .../src/main/js/apps/settings/styles.css | 12 ++ .../src/main/js/apps/settings/utils.ts | 151 ++++++++++++++ .../src/main/js/store/rootReducer.ts | 4 + .../resources/org/sonar/l10n/core.properties | 2 + 19 files changed, 934 insertions(+), 24 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/settings/components/SettingsSearch.tsx create mode 100644 server/sonar-web/src/main/js/apps/settings/components/SettingsSearchRenderer.tsx create mode 100644 server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearch-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearchRenderer-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/settings/components/__tests__/__snapshots__/SettingsSearchRenderer-test.tsx.snap diff --git a/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.ts index aa0c97c7898..38d70015b55 100644 --- a/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.ts @@ -17,12 +17,13 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import { mockDefinition } from '../../../helpers/mocks/settings'; import { Setting, SettingCategoryDefinition, SettingFieldDefinition } from '../../../types/settings'; -import { getDefaultValue, getEmptyValue } from '../utils'; +import { buildSettingLink, getDefaultValue, getEmptyValue } from '../utils'; const fields = [ { key: 'foo', type: 'STRING' } as SettingFieldDefinition, @@ -82,3 +83,38 @@ describe('#getDefaultValue()', () => { } ); }); + +describe('buildSettingLink', () => { + it.each([ + [ + mockDefinition({ key: 'anykey' }), + { hash: '#anykey', pathname: '/admin/settings', query: { category: 'foo category' } } + ], + [ + mockDefinition({ key: 'sonar.auth.gitlab.name' }), + { + hash: '#sonar.auth.gitlab.name', + pathname: '/admin/settings', + query: { alm: 'gitlab', category: 'foo category' } + } + ], + [ + mockDefinition({ key: 'sonar.auth.github.token' }), + { + hash: '#sonar.auth.github.token', + pathname: '/admin/settings', + query: { alm: 'github', category: 'foo category' } + } + ], + [ + mockDefinition({ key: 'sonar.almintegration.azure' }), + { + hash: '#sonar.almintegration.azure', + pathname: '/admin/settings', + query: { alm: 'azure', category: 'foo category' } + } + ] + ])('should work as expected', (definition, expectedUrl) => { + expect(buildSettingLink(definition)).toEqual(expectedUrl); + }); +}); diff --git a/server/sonar-web/src/main/js/apps/settings/components/DefinitionsList.tsx b/server/sonar-web/src/main/js/apps/settings/components/DefinitionsList.tsx index 653cf225f8d..8f810e009f0 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/DefinitionsList.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/DefinitionsList.tsx @@ -23,14 +23,19 @@ import Definition from './Definition'; interface Props { component?: T.Component; + scrollToDefinition: (element: HTMLLIElement) => void; settings: Setting[]; } -export default function DefinitionsList({ component, settings }: Props) { +export default function DefinitionsList(props: Props) { + const { component, settings } = props; return (