]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Move all constants to a constants.ts file
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Fri, 3 Jun 2022 09:59:56 +0000 (11:59 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 7 Jun 2022 20:03:10 +0000 (20:03 +0000)
As per our team guidelines, we prefer having a constants.ts file at the
root of the app, where we consolidate all constant values.

15 files changed:
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavProjectBindingErrorNotif.tsx
server/sonar-web/src/main/js/apps/create/project/AzureProjectCreateRenderer.tsx
server/sonar-web/src/main/js/apps/create/project/WrongBindingCountAlert.tsx
server/sonar-web/src/main/js/apps/overview/branches/FirstAnalysisNextStepsNotif.tsx
server/sonar-web/src/main/js/apps/settings/components/AdditionalCategories.tsx
server/sonar-web/src/main/js/apps/settings/components/AdditionalCategoryKeys.ts [deleted file]
server/sonar-web/src/main/js/apps/settings/components/AllCategoriesList.tsx
server/sonar-web/src/main/js/apps/settings/components/CategoryOverrides.ts [deleted file]
server/sonar-web/src/main/js/apps/settings/components/Languages.tsx
server/sonar-web/src/main/js/apps/settings/components/SettingsAppRenderer.tsx
server/sonar-web/src/main/js/apps/settings/components/__tests__/AdditionalCategories-test.tsx
server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsAppRenderer-test.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTabRenderer.tsx
server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBindingRenderer.tsx
server/sonar-web/src/main/js/apps/settings/constants.ts [new file with mode: 0644]

index eea7f2c11e0b7ad430bb8bd607b7d74b69c0d43c..58a0175c583ec005fa526b87d93fc0aa07fb7146 100644 (file)
@@ -20,7 +20,7 @@
 import * as React from 'react';
 import { FormattedMessage } from 'react-intl';
 import { Link } from 'react-router';
-import { PULL_REQUEST_DECORATION_BINDING_CATEGORY } from '../../../../apps/settings/components/AdditionalCategoryKeys';
+import { PULL_REQUEST_DECORATION_BINDING_CATEGORY } from '../../../../apps/settings/constants';
 import { Alert } from '../../../../components/ui/Alert';
 import { translate } from '../../../../helpers/l10n';
 import { getProjectSettingsUrl } from '../../../../helpers/urls';
index 0306e0c241e9fed23405356a68b4ca3309f8a4dd..51e3911aa0365484a951bc1e3930cec53fb2cf89 100644 (file)
@@ -30,7 +30,7 @@ import { getGlobalSettingsUrl } from '../../../helpers/urls';
 import { AzureProject, AzureRepository } from '../../../types/alm-integration';
 import { AlmKeys, AlmSettingsInstance } from '../../../types/alm-settings';
 import { Dict } from '../../../types/types';
-import { ALM_INTEGRATION } from '../../settings/components/AdditionalCategoryKeys';
+import { ALM_INTEGRATION_CATEGORY } from '../../settings/constants';
 import AzurePersonalAccessTokenForm from './AzurePersonalAccessTokenForm';
 import AzureProjectsList from './AzureProjectsList';
 import CreateProjectPageHeader from './CreateProjectPageHeader';
@@ -121,7 +121,7 @@ export default function AzureProjectCreateRenderer(props: AzureProjectCreateRend
               values={{
                 alm: translate('onboarding.alm', AlmKeys.Azure),
                 url: (
-                  <Link to={getGlobalSettingsUrl(ALM_INTEGRATION)}>
+                  <Link to={getGlobalSettingsUrl(ALM_INTEGRATION_CATEGORY)}>
                     {translate('settings.page')}
                   </Link>
                 )
index d5510a109af3742435eca25b501de517a7d74154..bed32e27e6fb83a5747e59d829352aca6c1101cf 100644 (file)
@@ -24,7 +24,7 @@ import { Alert } from '../../../components/ui/Alert';
 import { translate } from '../../../helpers/l10n';
 import { getGlobalSettingsUrl } from '../../../helpers/urls';
 import { AlmKeys } from '../../../types/alm-settings';
-import { ALM_INTEGRATION } from '../../settings/components/AdditionalCategoryKeys';
+import { ALM_INTEGRATION_CATEGORY } from '../../settings/constants';
 
 export interface WrongBindingCountAlertProps {
   alm: AlmKeys;
@@ -43,7 +43,9 @@ export default function WrongBindingCountAlert(props: WrongBindingCountAlertProp
           values={{
             alm: translate('onboarding.alm', alm),
             url: (
-              <Link to={getGlobalSettingsUrl(ALM_INTEGRATION)}>{translate('settings.page')}</Link>
+              <Link to={getGlobalSettingsUrl(ALM_INTEGRATION_CATEGORY)}>
+                {translate('settings.page')}
+              </Link>
             )
           }}
         />
index fa57e1b9d0f3936e501092c0e64deb94709a79bb..a70c5ea4b0b8bec802168a976d047c0b9d40465d 100644 (file)
@@ -27,7 +27,7 @@ import { ProjectAlmBindingResponse } from '../../../types/alm-settings';
 import { ComponentQualifier } from '../../../types/component';
 import { Component } from '../../../types/types';
 import { CurrentUser, isLoggedIn } from '../../../types/users';
-import { PULL_REQUEST_DECORATION_BINDING_CATEGORY } from '../../settings/components/AdditionalCategoryKeys';
+import { PULL_REQUEST_DECORATION_BINDING_CATEGORY } from '../../settings/constants';
 
 export interface FirstAnalysisNextStepsNotifProps {
   branchesEnabled?: boolean;
index ed870f1cd043dd9f1df26aaa40409f698e20249e..7b3c78f583ad4eb39ab7808ead2a3c5e169a4727 100644 (file)
@@ -22,12 +22,12 @@ import { translate } from '../../../helpers/l10n';
 import { ExtendedSettingDefinition } from '../../../types/settings';
 import { Component } from '../../../types/types';
 import {
-  ALM_INTEGRATION,
+  ALM_INTEGRATION_CATEGORY,
   ANALYSIS_SCOPE_CATEGORY,
   LANGUAGES_CATEGORY,
   NEW_CODE_PERIOD_CATEGORY,
   PULL_REQUEST_DECORATION_BINDING_CATEGORY
-} from './AdditionalCategoryKeys';
+} from '../constants';
 import AlmIntegration from './almIntegration/AlmIntegration';
 import { AnalysisScope } from './AnalysisScope';
 import Languages from './Languages';
@@ -77,7 +77,7 @@ export const ADDITIONAL_CATEGORIES: AdditionalCategory[] = [
     displayTab: false
   },
   {
-    key: ALM_INTEGRATION,
+    key: ALM_INTEGRATION_CATEGORY,
     name: translate('property.category.almintegration'),
     renderComponent: getAlmIntegrationComponent,
     availableGlobally: true,
diff --git a/server/sonar-web/src/main/js/apps/settings/components/AdditionalCategoryKeys.ts b/server/sonar-web/src/main/js/apps/settings/components/AdditionalCategoryKeys.ts
deleted file mode 100644 (file)
index 387f645..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.
- */
-export const ALM_INTEGRATION = 'almintegration';
-export const ANALYSIS_SCOPE_CATEGORY = 'exclusions';
-export const LANGUAGES_CATEGORY = 'languages';
-export const NEW_CODE_PERIOD_CATEGORY = 'new_code_period';
-export const PULL_REQUEST_DECORATION_BINDING_CATEGORY = 'pull_request_decoration_binding';
index bfc388ce5b2667dbac3eb9ff573e54033550647e..91c8ced89c172efe8143564a5d437267794bdbf9 100644 (file)
@@ -25,9 +25,9 @@ import withAppStateContext from '../../../app/components/app-state/withAppStateC
 import { getGlobalSettingsUrl, getProjectSettingsUrl } from '../../../helpers/urls';
 import { AppState } from '../../../types/appstate';
 import { Component } from '../../../types/types';
+import { CATEGORY_OVERRIDES } from '../constants';
 import { getCategoryName } from '../utils';
 import { ADDITIONAL_CATEGORIES } from './AdditionalCategories';
-import CATEGORY_OVERRIDES from './CategoryOverrides';
 
 export interface CategoriesListProps {
   appState: AppState;
diff --git a/server/sonar-web/src/main/js/apps/settings/components/CategoryOverrides.ts b/server/sonar-web/src/main/js/apps/settings/components/CategoryOverrides.ts
deleted file mode 100644 (file)
index a2a915e..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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 { Dict } from '../../../types/types';
-import { LANGUAGES_CATEGORY } from './AdditionalCategoryKeys';
-
-const CATEGORY_OVERRIDES: Dict<string> = {
-  abap: LANGUAGES_CATEGORY,
-  apex: LANGUAGES_CATEGORY,
-  'c / c++ / objective-c': LANGUAGES_CATEGORY,
-  'c#': LANGUAGES_CATEGORY,
-  cloudformation: LANGUAGES_CATEGORY,
-  cobol: LANGUAGES_CATEGORY,
-  css: LANGUAGES_CATEGORY,
-  flex: LANGUAGES_CATEGORY,
-  go: LANGUAGES_CATEGORY,
-  html: LANGUAGES_CATEGORY,
-  java: LANGUAGES_CATEGORY,
-  javascript: LANGUAGES_CATEGORY,
-  'javascript / typescript': LANGUAGES_CATEGORY,
-  json: LANGUAGES_CATEGORY,
-  kotlin: LANGUAGES_CATEGORY,
-  php: LANGUAGES_CATEGORY,
-  'pl/i': LANGUAGES_CATEGORY,
-  'pl/sql': LANGUAGES_CATEGORY,
-  python: LANGUAGES_CATEGORY,
-  rpg: LANGUAGES_CATEGORY,
-  ruby: LANGUAGES_CATEGORY,
-  scala: LANGUAGES_CATEGORY,
-  swift: LANGUAGES_CATEGORY,
-  't-sql': LANGUAGES_CATEGORY,
-  terraform: LANGUAGES_CATEGORY,
-  typescript: LANGUAGES_CATEGORY,
-  'vb.net': LANGUAGES_CATEGORY,
-  'visual basic': LANGUAGES_CATEGORY,
-  xml: LANGUAGES_CATEGORY,
-  yaml: LANGUAGES_CATEGORY
-};
-
-export default CATEGORY_OVERRIDES;
index 83adcaee6860816102eeb872ee49b9236d770d49..46af2305a4e3f733072592fc0f1d781cb5aa2097 100644 (file)
@@ -21,11 +21,10 @@ import * as React from 'react';
 import Select from '../../../components/controls/Select';
 import { Location, Router, withRouter } from '../../../components/hoc/withRouter';
 import { translate } from '../../../helpers/l10n';
+import { CATEGORY_OVERRIDES, LANGUAGES_CATEGORY } from '../constants';
 import { getCategoryName } from '../utils';
 import { AdditionalCategoryComponentProps } from './AdditionalCategories';
-import { LANGUAGES_CATEGORY } from './AdditionalCategoryKeys';
 import CategoryDefinitionsList from './CategoryDefinitionsList';
-import CATEGORY_OVERRIDES from './CategoryOverrides';
 
 export interface LanguagesProps extends AdditionalCategoryComponentProps {
   location: Location;
index 4d5a07307e0ca249e1152f2fcb3f036cc7f3c108..e292205d6266e6b1146cae4a054074daf9fad081 100644 (file)
@@ -26,11 +26,11 @@ import { Location, withRouter } from '../../../components/hoc/withRouter';
 import { translate } from '../../../helpers/l10n';
 import { ExtendedSettingDefinition } from '../../../types/settings';
 import { Component } from '../../../types/types';
+import { CATEGORY_OVERRIDES } from '../constants';
 import { getDefaultCategory } from '../utils';
 import { ADDITIONAL_CATEGORIES } from './AdditionalCategories';
 import AllCategoriesList from './AllCategoriesList';
 import CategoryDefinitionsList from './CategoryDefinitionsList';
-import CATEGORY_OVERRIDES from './CategoryOverrides';
 import PageHeader from './PageHeader';
 
 export interface SettingsAppRendererProps {
index 68e86362105551f463d95e86bc48011dbe01a4f6..2bdeab6a2c406b3289edefb284cb477622120105 100644 (file)
@@ -19,8 +19,8 @@
  */
 import { find } from 'lodash';
 import { mockComponent } from '../../../../helpers/mocks/component';
+import { PULL_REQUEST_DECORATION_BINDING_CATEGORY } from '../../constants';
 import { ADDITIONAL_CATEGORIES } from '../AdditionalCategories';
-import { PULL_REQUEST_DECORATION_BINDING_CATEGORY } from '../AdditionalCategoryKeys';
 
 it('should render additional categories component correctly', () => {
   ADDITIONAL_CATEGORIES.forEach(cat => {
index dc200d4ebacc8441639c645defaecd526805473f..4479fd6bb3af96508e08f224c31e314b759f0732 100644 (file)
@@ -23,12 +23,12 @@ import ScreenPositionHelper from '../../../../components/common/ScreenPositionHe
 import { mockDefinition } from '../../../../helpers/mocks/settings';
 import { mockLocation } from '../../../../helpers/testMocks';
 import {
-  ALM_INTEGRATION,
+  ALM_INTEGRATION_CATEGORY,
   ANALYSIS_SCOPE_CATEGORY,
   LANGUAGES_CATEGORY,
   NEW_CODE_PERIOD_CATEGORY,
   PULL_REQUEST_DECORATION_BINDING_CATEGORY
-} from '../AdditionalCategoryKeys';
+} from '../../constants';
 import { SettingsAppRenderer, SettingsAppRendererProps } from '../SettingsAppRenderer';
 
 it('should render loading correctly', () => {
@@ -46,7 +46,7 @@ it.each([
   [NEW_CODE_PERIOD_CATEGORY],
   [LANGUAGES_CATEGORY],
   [ANALYSIS_SCOPE_CATEGORY],
-  [ALM_INTEGRATION],
+  [ALM_INTEGRATION_CATEGORY],
   [PULL_REQUEST_DECORATION_BINDING_CATEGORY]
 ])('should render %s correctly', category => {
   const wrapper = shallowRender({
index df5639fb5be1500971610a1da8b97162ff6c2af7..12482862a20f7a00e0efe5da76c35ddf099cfcb2 100644 (file)
@@ -30,7 +30,7 @@ import {
 } from '../../../../types/alm-settings';
 import { ExtendedSettingDefinition } from '../../../../types/settings';
 import { Dict } from '../../../../types/types';
-import { ALM_INTEGRATION } from '../AdditionalCategoryKeys';
+import { ALM_INTEGRATION_CATEGORY } from '../../constants';
 import CategoryDefinitionsList from '../CategoryDefinitionsList';
 import AlmBindingDefinitionBox from './AlmBindingDefinitionBox';
 import AlmBindingDefinitionForm from './AlmBindingDefinitionForm';
@@ -120,7 +120,7 @@ export default function AlmTabRenderer(props: AlmTabRendererProps) {
 
       <div className="big-padded">
         <CategoryDefinitionsList
-          category={ALM_INTEGRATION}
+          category={ALM_INTEGRATION_CATEGORY}
           definitions={settingsDefinitions}
           subCategory={almTab}
         />
index b74af2527a5a73e4e4d57ed40e590747b7f1fbf4..3a4f0b7d07cf3666b09465ba09e2e249a0cf5bd6 100644 (file)
@@ -36,7 +36,7 @@ import {
   ProjectAlmBindingConfigurationErrorScope,
   ProjectAlmBindingResponse
 } from '../../../../types/alm-settings';
-import { ALM_INTEGRATION } from '../AdditionalCategoryKeys';
+import { ALM_INTEGRATION_CATEGORY } from '../../constants';
 import AlmSpecificForm from './AlmSpecificForm';
 
 export interface PRDecorationBindingRendererProps {
@@ -105,7 +105,7 @@ export default function PRDecorationBindingRenderer(props: PRDecorationBindingRe
               id="settings.pr_decoration.binding.no_bindings.admin"
               values={{
                 link: (
-                  <Link to={getGlobalSettingsUrl(ALM_INTEGRATION)}>
+                  <Link to={getGlobalSettingsUrl(ALM_INTEGRATION_CATEGORY)}>
                     {translate('settings.pr_decoration.binding.no_bindings.link')}
                   </Link>
                 )
@@ -223,7 +223,7 @@ export default function PRDecorationBindingRenderer(props: PRDecorationBindingRe
                     )}
                     values={{
                       link: (
-                        <Link to={getGlobalSettingsUrl(ALM_INTEGRATION, { alm })}>
+                        <Link to={getGlobalSettingsUrl(ALM_INTEGRATION_CATEGORY, { alm })}>
                           {translate(
                             'settings.pr_decoration.binding.check_configuration.failure.check_global_settings.link'
                           )}
diff --git a/server/sonar-web/src/main/js/apps/settings/constants.ts b/server/sonar-web/src/main/js/apps/settings/constants.ts
new file mode 100644 (file)
index 0000000..d285466
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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 { Dict } from '../../types/types';
+
+export const ALM_INTEGRATION_CATEGORY = 'almintegration';
+export const ANALYSIS_SCOPE_CATEGORY = 'exclusions';
+export const LANGUAGES_CATEGORY = 'languages';
+export const NEW_CODE_PERIOD_CATEGORY = 'new_code_period';
+export const PULL_REQUEST_DECORATION_BINDING_CATEGORY = 'pull_request_decoration_binding';
+
+export const CATEGORY_OVERRIDES: Dict<string> = {
+  abap: LANGUAGES_CATEGORY,
+  apex: LANGUAGES_CATEGORY,
+  'c / c++ / objective-c': LANGUAGES_CATEGORY,
+  'c#': LANGUAGES_CATEGORY,
+  cloudformation: LANGUAGES_CATEGORY,
+  cobol: LANGUAGES_CATEGORY,
+  css: LANGUAGES_CATEGORY,
+  flex: LANGUAGES_CATEGORY,
+  go: LANGUAGES_CATEGORY,
+  html: LANGUAGES_CATEGORY,
+  java: LANGUAGES_CATEGORY,
+  javascript: LANGUAGES_CATEGORY,
+  'javascript / typescript': LANGUAGES_CATEGORY,
+  json: LANGUAGES_CATEGORY,
+  kotlin: LANGUAGES_CATEGORY,
+  php: LANGUAGES_CATEGORY,
+  'pl/i': LANGUAGES_CATEGORY,
+  'pl/sql': LANGUAGES_CATEGORY,
+  python: LANGUAGES_CATEGORY,
+  rpg: LANGUAGES_CATEGORY,
+  ruby: LANGUAGES_CATEGORY,
+  scala: LANGUAGES_CATEGORY,
+  swift: LANGUAGES_CATEGORY,
+  't-sql': LANGUAGES_CATEGORY,
+  terraform: LANGUAGES_CATEGORY,
+  typescript: LANGUAGES_CATEGORY,
+  'vb.net': LANGUAGES_CATEGORY,
+  'visual basic': LANGUAGES_CATEGORY,
+  xml: LANGUAGES_CATEGORY,
+  yaml: LANGUAGES_CATEGORY
+};
+
+// As per Bitbucket Cloud's documentation, Workspace ID's can only contain lowercase letters,
+// numbers, dashes, and underscores.
+export const BITBUCKET_CLOUD_WORKSPACE_ID_FORMAT = /^[a-z0-9\-_]+$/;