diff options
author | Viktor Vorona <viktor.vorona@sonarsource.com> | 2023-08-10 17:12:59 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-08-11 20:02:49 +0000 |
commit | 344e16be5060c96fceb39ee737dd7604ed6d717d (patch) | |
tree | 2899a2f35629019bab1dededb20e452fc12b4f38 /server/sonar-web/src/main/js/apps | |
parent | fc14589ce7a24ca782b09ac3d34fb5f9bfe4bff1 (diff) | |
download | sonarqube-344e16be5060c96fceb39ee737dd7604ed6d717d.tar.gz sonarqube-344e16be5060c96fceb39ee737dd7604ed6d717d.zip |
SONAR-20122 Move react-queries to common folder
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
21 files changed, 41 insertions, 322 deletions
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/Header.tsx b/server/sonar-web/src/main/js/apps/permission-templates/components/Header.tsx index 176ac9ce6eb..9b19b8dd794 100644 --- a/server/sonar-web/src/main/js/apps/permission-templates/components/Header.tsx +++ b/server/sonar-web/src/main/js/apps/permission-templates/components/Header.tsx @@ -25,7 +25,7 @@ import { Alert } from '../../../components/ui/Alert'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { throwGlobalError } from '../../../helpers/error'; import { translate } from '../../../helpers/l10n'; -import { useGithubStatusQuery } from '../../settings/components/authentication/queries/identity-provider'; +import { useGithubProvisioningEnabledQuery } from '../../../queries/identity-provider'; import { PERMISSION_TEMPLATES_PATH } from '../utils'; import Form from './Form'; @@ -38,7 +38,7 @@ interface Props { function Header(props: Props) { const { ready, router } = props; const [createModal, setCreateModal] = useState(false); - const { data: gitHubProvisioningStatus } = useGithubStatusQuery(); + const { data: gitHubProvisioningStatus } = useGithubProvisioningEnabledQuery(); const handleCreateModalSubmit = async (data: { description: string; diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/Template.tsx b/server/sonar-web/src/main/js/apps/permission-templates/components/Template.tsx index 0c0c0819785..444d686ca83 100644 --- a/server/sonar-web/src/main/js/apps/permission-templates/components/Template.tsx +++ b/server/sonar-web/src/main/js/apps/permission-templates/components/Template.tsx @@ -30,8 +30,8 @@ import { PERMISSIONS_ORDER_FOR_PROJECT_TEMPLATE, } from '../../../helpers/permissions'; import UseQuery from '../../../helpers/UseQuery'; +import { useGithubProvisioningEnabledQuery } from '../../../queries/identity-provider'; import { Paging, PermissionGroup, PermissionTemplate, PermissionUser } from '../../../types/types'; -import { useGithubStatusQuery } from '../../settings/components/authentication/queries/identity-provider'; import TemplateDetails from './TemplateDetails'; import TemplateHeader from './TemplateHeader'; @@ -332,7 +332,7 @@ export default class Template extends React.PureComponent<Props, State> { /> <main> <TemplateDetails template={template} /> - <UseQuery query={useGithubStatusQuery}> + <UseQuery query={useGithubProvisioningEnabledQuery}> {({ data: githubProvisioningStatus }) => githubProvisioningStatus ? ( <Alert variant="warning" className="sw-w-fit"> diff --git a/server/sonar-web/src/main/js/apps/permissions/project/components/PageHeader.tsx b/server/sonar-web/src/main/js/apps/permissions/project/components/PageHeader.tsx index 200c721f57c..38d5012a19a 100644 --- a/server/sonar-web/src/main/js/apps/permissions/project/components/PageHeader.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/project/components/PageHeader.tsx @@ -24,9 +24,9 @@ import { Alert } from '../../../../components/ui/Alert'; import DeferredSpinner from '../../../../components/ui/DeferredSpinner'; import { translate } from '../../../../helpers/l10n'; import { getBaseUrl } from '../../../../helpers/system'; +import { useGithubProvisioningEnabledQuery } from '../../../../queries/identity-provider'; import { isApplication, isPortfolioLike, isProject } from '../../../../types/component'; import { Component } from '../../../../types/types'; -import { useGithubStatusQuery } from '../../../settings/components/authentication/queries/identity-provider'; import ApplyTemplate from './ApplyTemplate'; interface Props { @@ -38,7 +38,7 @@ interface Props { export default function PageHeader(props: Props) { const [applyTemplateModal, setApplyTemplateModal] = React.useState(false); - const { data: githubProvisioningStatus } = useGithubStatusQuery(); + const { data: githubProvisioningStatus } = useGithubProvisioningEnabledQuery(); const { component, isGitHubProject, loading } = props; const { configuration } = component; diff --git a/server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx b/server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx index 30f5baaaae8..249ce930773 100644 --- a/server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx @@ -31,11 +31,11 @@ import { PERMISSIONS_ORDER_BY_QUALIFIER, convertToPermissionDefinitions, } from '../../../../helpers/permissions'; +import { useGithubProvisioningEnabledQuery } from '../../../../queries/identity-provider'; import { AlmKeys } from '../../../../types/alm-settings'; import { ComponentContextShape, Visibility } from '../../../../types/component'; import { Permissions } from '../../../../types/permissions'; import { Component, Paging, PermissionGroup, PermissionUser } from '../../../../types/types'; -import { useGithubStatusQuery } from '../../../settings/components/authentication/queries/identity-provider'; import '../../styles.css'; import PageHeader from './PageHeader'; import PublicProjectDisclaimer from './PublicProjectDisclaimer'; @@ -355,7 +355,7 @@ class PermissionsProjectApp extends React.PureComponent<Props, State> { loading={loading} /> <div> - <UseQuery query={useGithubStatusQuery}> + <UseQuery query={useGithubProvisioningEnabledQuery}> {({ data: githubProvisioningStatus, isFetching }) => ( <VisibilitySelector canTurnToPrivate={canTurnToPrivate} diff --git a/server/sonar-web/src/main/js/apps/projectInformation/badges/ProjectBadges.tsx b/server/sonar-web/src/main/js/apps/projectInformation/badges/ProjectBadges.tsx index 4fec52c49a8..d5ae521d4b8 100644 --- a/server/sonar-web/src/main/js/apps/projectInformation/badges/ProjectBadges.tsx +++ b/server/sonar-web/src/main/js/apps/projectInformation/badges/ProjectBadges.tsx @@ -34,14 +34,14 @@ import * as React from 'react'; import { useState } from 'react'; import { getBranchLikeQuery } from '../../../helpers/branch-like'; import { translate } from '../../../helpers/l10n'; -import { BranchLike } from '../../../types/branch-like'; -import { MetricKey } from '../../../types/metrics'; -import { Component } from '../../../types/types'; import { useBadgeMetricsQuery, useBadgeTokenQuery, useRenewBagdeTokenMutation, -} from '../query/badges'; +} from '../../../queries/badges'; +import { BranchLike } from '../../../types/branch-like'; +import { MetricKey } from '../../../types/metrics'; +import { Component } from '../../../types/types'; import { BadgeFormats, BadgeOptions, BadgeType, getBadgeSnippet, getBadgeUrl } from './utils'; export interface ProjectBadgesProps { diff --git a/server/sonar-web/src/main/js/apps/projectInformation/query/badges.ts b/server/sonar-web/src/main/js/apps/projectInformation/query/badges.ts deleted file mode 100644 index 204030a5ac3..00000000000 --- a/server/sonar-web/src/main/js/apps/projectInformation/query/badges.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; -import { useContext } from 'react'; -import { getProjectBadgesToken, renewProjectBadgesToken } from '../../../api/project-badges'; -import { fetchWebApi } from '../../../api/web-api'; -import { MetricsContext } from '../../../app/components/metrics/MetricsContext'; -import { getLocalizedMetricName } from '../../../helpers/l10n'; -import { MetricKey } from '../../../types/metrics'; - -export function useFetchWebApiQuery() { - return useQuery(['web-api'], () => fetchWebApi(false)); -} - -export function useRenewBagdeTokenMutation() { - const queryClient = useQueryClient(); - return useMutation({ - mutationFn: async (key: string) => { - await renewProjectBadgesToken(key); - }, - onSuccess: (_, key) => { - queryClient.invalidateQueries({ queryKey: ['badges-token', key], refetchType: 'all' }); - }, - }); -} - -export function useBadgeMetricsQuery() { - const metrics = useContext(MetricsContext); - const { data: webservices = [], ...rest } = useFetchWebApiQuery(); - const domain = webservices.find((d) => d.path === 'api/project_badges'); - const ws = domain?.actions.find((w) => w.key === 'measure'); - const param = ws?.params?.find((p) => p.key === 'metric'); - if (param?.possibleValues) { - return { - ...rest, - data: param.possibleValues.map((key) => { - const metric = metrics[key]; - return { - value: key as MetricKey, - label: metric ? getLocalizedMetricName(metric) : key, - }; - }), - }; - } - return { ...rest, data: [] }; -} - -export function useBadgeTokenQuery(componentKey: string) { - return useQuery(['badges-token', componentKey] as const, ({ queryKey: [_, key] }) => - getProjectBadgesToken(key) - ); -} diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/ChangeDefaultVisibilityForm.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/ChangeDefaultVisibilityForm.tsx index 0a6c7791a2d..685629bb3bb 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/ChangeDefaultVisibilityForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/ChangeDefaultVisibilityForm.tsx @@ -23,8 +23,8 @@ import Radio from '../../components/controls/Radio'; import { Button, ResetButtonLink } from '../../components/controls/buttons'; import { Alert } from '../../components/ui/Alert'; import { translate } from '../../helpers/l10n'; +import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider'; import { Visibility } from '../../types/component'; -import { useGithubStatusQuery } from '../settings/components/authentication/queries/identity-provider'; export interface Props { defaultVisibility: Visibility; @@ -34,7 +34,7 @@ export interface Props { export default function ChangeDefaultVisibilityForm(props: Props) { const [visibility, setVisibility] = useState(props.defaultVisibility); - const { data: githubProbivisioningEnabled } = useGithubStatusQuery(); + const { data: githubProbivisioningEnabled } = useGithubProvisioningEnabledQuery(); const handleConfirmClick = () => { props.onConfirm(visibility); diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/ProjectRow.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/ProjectRow.tsx index d2acb3e932b..76fda3be051 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/ProjectRow.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/ProjectRow.tsx @@ -27,9 +27,9 @@ import QualifierIcon from '../../components/icons/QualifierIcon'; import DateFormatter from '../../components/intl/DateFormatter'; import { translate, translateWithParameters } from '../../helpers/l10n'; import { getComponentOverviewUrl } from '../../helpers/urls'; +import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider'; import { ComponentQualifier } from '../../types/component'; import { LoggedInUser } from '../../types/users'; -import { useGithubStatusQuery } from '../settings/components/authentication/queries/identity-provider'; import './ProjectRow.css'; import ProjectRowActions from './ProjectRowActions'; @@ -42,7 +42,7 @@ interface Props { export default function ProjectRow(props: Props) { const { currentUser, project, selected } = props; - const { data: githubProvisioningEnabled } = useGithubStatusQuery(); + const { data: githubProvisioningEnabled } = useGithubProvisioningEnabledQuery(); const handleProjectCheck = (checked: boolean) => { props.onProjectCheck(project, checked); diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/ProjectRowActions.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/ProjectRowActions.tsx index 032e81f83f2..26d929bcc01 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/ProjectRowActions.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/ProjectRowActions.tsx @@ -24,9 +24,9 @@ import ActionsDropdown, { ActionsDropdownItem } from '../../components/controls/ import DeferredSpinner from '../../components/ui/DeferredSpinner'; import { translate, translateWithParameters } from '../../helpers/l10n'; import { getComponentPermissionsUrl } from '../../helpers/urls'; +import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider'; import { LoggedInUser } from '../../types/users'; import ApplyTemplate from '../permissions/project/components/ApplyTemplate'; -import { useGithubStatusQuery } from '../settings/components/authentication/queries/identity-provider'; import RestoreAccessModal from './RestoreAccessModal'; export interface Props { @@ -39,7 +39,7 @@ export default function ProjectRowActions({ currentUser, project }: Props) { const [hasAccess, setHasAccess] = useState<boolean | undefined>(undefined); const [loading, setLoading] = useState(false); const [restoreAccessModal, setRestoreAccessModal] = useState(false); - const { data: githubProvisioningEnabled } = useGithubStatusQuery(); + const { data: githubProvisioningEnabled } = useGithubProvisioningEnabledQuery(); const fetchPermissions = () => { setLoading(true); diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx index 59965b85516..a1430ead8af 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx @@ -24,6 +24,7 @@ import BoxedTabs from '../../../../components/controls/BoxedTabs'; import { Alert } from '../../../../components/ui/Alert'; import { translate } from '../../../../helpers/l10n'; import { getBaseUrl } from '../../../../helpers/system'; +import { useGetValuesQuery } from '../../../../queries/settings'; import { AlmKeys, AlmSettingsBindingDefinitions, @@ -31,7 +32,6 @@ import { } from '../../../../types/alm-settings'; import { SettingsKey } from '../../../../types/settings'; import { Dict } from '../../../../types/types'; -import { useGetValuesQuery } from '../../queries/settings'; import { AlmTabs } from './AlmIntegration'; import AlmTab from './AlmTab'; import DeleteModal from './DeleteModal'; diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx index ae6d06d1432..4c1a3081db6 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx @@ -26,8 +26,8 @@ import { ResetButtonLink, SubmitButton } from '../../../../components/controls/b import { Alert } from '../../../../components/ui/Alert'; import DeferredSpinner from '../../../../components/ui/DeferredSpinner'; import { translate } from '../../../../helpers/l10n'; +import { useSaveValuesMutation } from '../../../../queries/settings'; import { Dict } from '../../../../types/types'; -import { useSaveValuesMutation } from '../../queries/settings'; import { AuthenticationTabs, DOCUMENTATION_LINK_SUFFIXES } from './Authentication'; import AuthenticationFormField from './AuthenticationFormField'; import { SettingValue } from './hook/useConfiguration'; diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubConfigurationValidity.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubConfigurationValidity.tsx index 867d5c7e968..06331668136 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubConfigurationValidity.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubConfigurationValidity.tsx @@ -27,8 +27,8 @@ import ClearIcon from '../../../../components/icons/ClearIcon'; import HelpIcon from '../../../../components/icons/HelpIcon'; import { Alert, AlertVariant } from '../../../../components/ui/Alert'; import { translate, translateWithParameters } from '../../../../helpers/l10n'; +import { useCheckGitHubConfigQuery } from '../../../../queries/identity-provider'; import { GitHubProvisioningStatus } from '../../../../types/provisioning'; -import { useCheckGitHubConfigQuery } from './queries/identity-provider'; const intlPrefix = 'settings.authentication.github.configuration.validation'; diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAuthenticationTab.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAuthenticationTab.tsx index 36bce8a1cb2..12f82b07647 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAuthenticationTab.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAuthenticationTab.tsx @@ -29,7 +29,11 @@ import DeleteIcon from '../../../../components/icons/DeleteIcon'; import EditIcon from '../../../../components/icons/EditIcon'; import { Alert } from '../../../../components/ui/Alert'; import { translate, translateWithParameters } from '../../../../helpers/l10n'; -import { useSyncNow } from '../../../../queries/github-sync'; +import { + useCheckGitHubConfigQuery, + useIdentityProviderQuery, + useSyncWithGitHubNow, +} from '../../../../queries/identity-provider'; import { AlmKeys } from '../../../../types/alm-settings'; import { ExtendedSettingDefinition } from '../../../../types/settings'; import { DOCUMENTATION_LINK_SUFFIXES } from './Authentication'; @@ -37,7 +41,6 @@ import AuthenticationFormField from './AuthenticationFormField'; import ConfigurationForm from './ConfigurationForm'; import GitHubConfigurationValidity from './GitHubConfigurationValidity'; import useGithubConfiguration, { GITHUB_JIT_FIELDS } from './hook/useGithubConfiguration'; -import { useCheckGitHubConfigQuery, useIdentityProviderQuery } from './queries/identity-provider'; interface GithubAuthenticationProps { definitions: ExtendedSettingDefinition[]; @@ -79,7 +82,7 @@ export default function GithubAuthenticationTab(props: GithubAuthenticationProps } = useGithubConfiguration(definitions); const hasDifferentProvider = data?.provider !== undefined && data.provider !== Provider.Github; - const { canSyncNow, synchronizeNow } = useSyncNow(); + const { canSyncNow, synchronizeNow } = useSyncWithGitHubNow(); const { refetch } = useCheckGitHubConfigQuery(enabled); const handleCreateConfiguration = () => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthenticationTab.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthenticationTab.tsx index 48448523693..edb9349490d 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthenticationTab.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthenticationTab.tsx @@ -30,8 +30,12 @@ import DeleteIcon from '../../../../components/icons/DeleteIcon'; import EditIcon from '../../../../components/icons/EditIcon'; import { Alert } from '../../../../components/ui/Alert'; import { translate } from '../../../../helpers/l10n'; +import { + useIdentityProviderQuery, + useToggleScimMutation, +} from '../../../../queries/identity-provider'; +import { useSaveValueMutation } from '../../../../queries/settings'; import { ExtendedSettingDefinition } from '../../../../types/settings'; -import { useSaveValueMutation } from '../../queries/settings'; import { getPropertyName } from '../../utils'; import DefinitionDescription from '../DefinitionDescription'; import ConfigurationForm from './ConfigurationForm'; @@ -40,7 +44,6 @@ import useSamlConfiguration, { SAML_GROUP_NAME, SAML_SCIM_DEPRECATED, } from './hook/useSamlConfiguration'; -import { useIdentityProviderQuery, useToggleScimMutation } from './queries/identity-provider'; interface SamlAuthenticationProps { definitions: ExtendedSettingDefinition[]; diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useConfiguration.ts b/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useConfiguration.ts index c3bf05a3b61..b88e1007257 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useConfiguration.ts +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useConfiguration.ts @@ -20,9 +20,9 @@ import { UseMutationResult } from '@tanstack/react-query'; import { every, isEmpty, keyBy, update } from 'lodash'; import { useCallback, useEffect, useState } from 'react'; +import { useGetValuesQuery, useResetSettingsMutation } from '../../../../../queries/settings'; import { ExtendedSettingDefinition } from '../../../../../types/settings'; import { Dict } from '../../../../../types/types'; -import { useGetValuesQuery, useResetSettingsMutation } from '../../../queries/settings'; export type SettingValue = | { diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts b/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts index b335b41f9ed..e8ca3a7fb62 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts @@ -20,13 +20,13 @@ import { some } from 'lodash'; import { useContext, useState } from 'react'; import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext'; -import { Feature } from '../../../../../types/features'; -import { ExtendedSettingDefinition } from '../../../../../types/settings'; -import { useSaveValueMutation, useSaveValuesMutation } from '../../../queries/settings'; import { - useGithubStatusQuery, + useGithubProvisioningEnabledQuery, useToggleGithubProvisioningMutation, -} from '../queries/identity-provider'; +} from '../../../../../queries/identity-provider'; +import { useSaveValueMutation, useSaveValuesMutation } from '../../../../../queries/settings'; +import { Feature } from '../../../../../types/features'; +import { ExtendedSettingDefinition } from '../../../../../types/settings'; import useConfiguration from './useConfiguration'; export const GITHUB_ENABLED_FIELD = 'sonar.auth.github.enabled'; @@ -59,7 +59,7 @@ export default function useGithubConfiguration(definitions: ExtendedSettingDefin const hasGithubProvisioning = useContext(AvailableFeaturesContext).includes( Feature.GithubProvisioning ); - const { data: githubProvisioningStatus } = useGithubStatusQuery(); + const { data: githubProvisioningStatus } = useGithubProvisioningEnabledQuery(); const toggleGithubProvisioning = useToggleGithubProvisioningMutation(); const [newGithubProvisioningStatus, setNewGithubProvisioningStatus] = useState<boolean>(); const hasGithubProvisioningTypeChange = diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useSamlConfiguration.ts b/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useSamlConfiguration.ts index 47b2a9c5207..cf720362be1 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useSamlConfiguration.ts +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useSamlConfiguration.ts @@ -19,9 +19,9 @@ */ import React from 'react'; import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext'; +import { useScimStatusQuery } from '../../../../../queries/identity-provider'; import { Feature } from '../../../../../types/features'; import { ExtendedSettingDefinition } from '../../../../../types/settings'; -import { useScimStatusQuery } from '../queries/identity-provider'; import useConfiguration from './useConfiguration'; export const SAML_ENABLED_FIELD = 'sonar.auth.saml.enabled'; diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/queries/identity-provider.ts b/server/sonar-web/src/main/js/apps/settings/components/authentication/queries/identity-provider.ts deleted file mode 100644 index 9c02a99a80c..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/queries/identity-provider.ts +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; -import { useContext } from 'react'; -import { - activateGithubProvisioning, - activateScim, - checkConfigurationValidity, - deactivateGithubProvisioning, - deactivateScim, - fetchIsScimEnabled, -} from '../../../../../api/provisioning'; -import { getSystemInfo } from '../../../../../api/system'; -import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext'; -import { mapReactQueryResult } from '../../../../../helpers/react-query'; -import { useSyncStatusQuery } from '../../../../../queries/github-sync'; -import { Feature } from '../../../../../types/features'; -import { SysInfoCluster } from '../../../../../types/types'; - -export function useIdentityProviderQuery() { - return useQuery(['identity_provider'], async () => { - const info = (await getSystemInfo()) as SysInfoCluster; - return { provider: info.System['External Users and Groups Provisioning'] }; - }); -} - -export function useScimStatusQuery() { - const hasScim = useContext(AvailableFeaturesContext).includes(Feature.Scim); - - return useQuery(['identity_provider', 'scim_status'], () => { - if (!hasScim) { - return false; - } - return fetchIsScimEnabled(); - }); -} - -export function useGithubStatusQuery() { - const res = useSyncStatusQuery({ noRefetch: true }); - - return mapReactQueryResult(res, (data) => data.enabled); -} - -export function useToggleScimMutation() { - const client = useQueryClient(); - return useMutation({ - mutationFn: (activate: boolean) => (activate ? activateScim() : deactivateScim()), - onSuccess: () => { - client.invalidateQueries({ queryKey: ['identity_provider'] }); - }, - }); -} - -export function useToggleGithubProvisioningMutation() { - const client = useQueryClient(); - return useMutation({ - mutationFn: (activate: boolean) => - activate ? activateGithubProvisioning() : deactivateGithubProvisioning(), - onSuccess: () => { - client.invalidateQueries({ queryKey: ['identity_provider'] }); - client.invalidateQueries({ queryKey: ['github_sync'] }); - }, - }); -} - -export const useCheckGitHubConfigQuery = (githubEnabled: boolean) => { - return useQuery(['identity_provider', 'github_check'], checkConfigurationValidity, { - enabled: githubEnabled, - }); -}; diff --git a/server/sonar-web/src/main/js/apps/settings/queries/settings.ts b/server/sonar-web/src/main/js/apps/settings/queries/settings.ts deleted file mode 100644 index 6c88431f664..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/queries/settings.ts +++ /dev/null @@ -1,103 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; -import { getValues, resetSettingValue, setSettingValue } from '../../../api/settings'; -import { ExtendedSettingDefinition } from '../../../types/settings'; - -type SettingValue = string | boolean | string[]; - -export function useGetValuesQuery(keys: string[]) { - return useQuery(['settings', 'values', keys] as const, ({ queryKey: [_a, _b, keys] }) => { - return getValues({ keys }); - }); -} - -export function useResetSettingsMutation() { - const queryClient = useQueryClient(); - return useMutation({ - mutationFn: (keys: string[]) => resetSettingValue({ keys: keys.join(',') }), - onSuccess: () => { - queryClient.invalidateQueries(['settings']); - }, - }); -} - -export function useSaveValuesMutation() { - const queryClient = useQueryClient(); - return useMutation({ - mutationFn: ( - values: { - newValue?: SettingValue; - definition: ExtendedSettingDefinition; - }[] - ) => { - return Promise.all( - values - .filter((v) => v.newValue !== undefined) - .map(async ({ newValue, definition }) => { - try { - if (isDefaultValue(newValue as string | boolean | string[], definition)) { - await resetSettingValue({ keys: definition.key }); - } else { - await setSettingValue(definition, newValue); - } - return { key: definition.key, success: true }; - } catch (error) { - return { key: definition.key, success: false }; - } - }) - ); - }, - onSuccess: () => { - queryClient.invalidateQueries(['settings']); - }, - }); -} - -export function useSaveValueMutation() { - const queryClient = useQueryClient(); - return useMutation({ - mutationFn: async ({ - newValue, - definition, - }: { - newValue: SettingValue; - definition: ExtendedSettingDefinition; - }) => { - if (isDefaultValue(newValue, definition)) { - await resetSettingValue({ keys: definition.key }); - } else { - await setSettingValue(definition, newValue); - } - }, - onSuccess: () => { - queryClient.invalidateQueries(['settings']); - }, - }); -} - -function isDefaultValue(value: SettingValue, definition: ExtendedSettingDefinition) { - const defaultValue = definition.defaultValue ?? ''; - if (definition.multiValues) { - return defaultValue === (value as string[]).join(','); - } - - return defaultValue === String(value); -} diff --git a/server/sonar-web/src/main/js/apps/web-api-v2/WebApiApp.tsx b/server/sonar-web/src/main/js/apps/web-api-v2/WebApiApp.tsx index 94d840db9b2..4147cca391a 100644 --- a/server/sonar-web/src/main/js/apps/web-api-v2/WebApiApp.tsx +++ b/server/sonar-web/src/main/js/apps/web-api-v2/WebApiApp.tsx @@ -24,9 +24,9 @@ import React, { useMemo } from 'react'; import { Helmet } from 'react-helmet-async'; import { useLocation } from 'react-router-dom'; import { translate } from '../../helpers/l10n'; +import { useOpenAPI } from '../../queries/web-api'; import ApiInformation from './components/ApiInformation'; import ApiSidebar from './components/ApiSidebar'; -import { useOpenAPI } from './queries'; import { URL_DIVIDER, dereferenceSchema } from './utils'; export default function WebApiApp() { diff --git a/server/sonar-web/src/main/js/apps/web-api-v2/queries.ts b/server/sonar-web/src/main/js/apps/web-api-v2/queries.ts deleted file mode 100644 index 1b0bf90d8d6..00000000000 --- a/server/sonar-web/src/main/js/apps/web-api-v2/queries.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { useQuery } from '@tanstack/react-query'; -import { fetchOpenAPI } from '../../api/web-api'; - -export const useOpenAPI = () => { - return useQuery(['open_api'], fetchOpenAPI, { staleTime: Infinity, cacheTime: Infinity }); -}; |