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 | |
parent | fc14589ce7a24ca782b09ac3d34fb5f9bfe4bff1 (diff) | |
download | sonarqube-344e16be5060c96fceb39ee737dd7604ed6d717d.tar.gz sonarqube-344e16be5060c96fceb39ee737dd7604ed6d717d.zip |
SONAR-20122 Move react-queries to common folder
Diffstat (limited to 'server')
24 files changed, 101 insertions, 119 deletions
diff --git a/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx b/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx index 088a863a318..5b637c729df 100644 --- a/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx +++ b/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx @@ -24,7 +24,7 @@ import Link from '../../components/common/Link'; import CheckIcon from '../../components/icons/CheckIcon'; import { Alert } from '../../components/ui/Alert'; import { translate, translateWithParameters } from '../../helpers/l10n'; -import { useSyncStatusQuery } from '../../queries/github-sync'; +import { useGitHubSyncStatusQuery } from '../../queries/identity-provider'; import { GithubStatusEnabled } from '../../types/provisioning'; import { TaskStatuses } from '../../types/tasks'; import './SystemAnnouncement.css'; @@ -108,7 +108,7 @@ function LastSyncAlert({ info, short }: LastSyncProps) { } function GitHubSynchronisationWarning({ short }: GitHubSynchronisationWarningProps) { - const { data } = useSyncStatusQuery(); + const { data } = useGitHubSyncStatusQuery(); if (!data) { return null; 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/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/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/components/permissions/HoldersList.tsx b/server/sonar-web/src/main/js/components/permissions/HoldersList.tsx index 306a9772f57..5f0eb67e3c8 100644 --- a/server/sonar-web/src/main/js/components/permissions/HoldersList.tsx +++ b/server/sonar-web/src/main/js/components/permissions/HoldersList.tsx @@ -19,10 +19,10 @@ */ import { partition } from 'lodash'; import * as React from 'react'; -import { useGithubStatusQuery } from '../../apps/settings/components/authentication/queries/identity-provider'; import UseQuery from '../../helpers/UseQuery'; import { translate } from '../../helpers/l10n'; import { isPermissionDefinitionGroup } from '../../helpers/permissions'; +import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider'; import { Dict, PermissionDefinitions, PermissionGroup, PermissionUser } from '../../types/types'; import GroupHolder from './GroupHolder'; import PermissionHeader from './PermissionHeader'; @@ -105,7 +105,7 @@ export default class HoldersList extends React.PureComponent<Props, State> { renderItem(item: PermissionUser | PermissionGroup, permissions: PermissionDefinitions) { const { isGitHubProject, selectedPermission, isComponentPrivate } = this.props; return ( - <UseQuery key={this.getKey(item)} query={useGithubStatusQuery}> + <UseQuery key={this.getKey(item)} query={useGithubProvisioningEnabledQuery}> {({ data: githubProvisioningStatus }) => ( <> {this.isPermissionUser(item) ? ( diff --git a/server/sonar-web/src/main/js/apps/projectInformation/query/badges.ts b/server/sonar-web/src/main/js/queries/badges.ts index 204030a5ac3..57a451eeea6 100644 --- a/server/sonar-web/src/main/js/apps/projectInformation/query/badges.ts +++ b/server/sonar-web/src/main/js/queries/badges.ts @@ -20,15 +20,11 @@ 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)); -} +import { getProjectBadgesToken, renewProjectBadgesToken } from '../api/project-badges'; +import { MetricsContext } from '../app/components/metrics/MetricsContext'; +import { getLocalizedMetricName } from '../helpers/l10n'; +import { MetricKey } from '../types/metrics'; +import { useWebApiQuery } from './web-api'; export function useRenewBagdeTokenMutation() { const queryClient = useQueryClient(); @@ -44,7 +40,7 @@ export function useRenewBagdeTokenMutation() { export function useBadgeMetricsQuery() { const metrics = useContext(MetricsContext); - const { data: webservices = [], ...rest } = useFetchWebApiQuery(); + const { data: webservices = [], ...rest } = useWebApiQuery(); 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'); diff --git a/server/sonar-web/src/main/js/queries/github-sync.ts b/server/sonar-web/src/main/js/queries/github-sync.ts deleted file mode 100644 index 018e0685d86..00000000000 --- a/server/sonar-web/src/main/js/queries/github-sync.ts +++ /dev/null @@ -1,53 +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 { fetchGithubProvisioningStatus, syncNowGithubProvisioning } from '../api/provisioning'; -import { AvailableFeaturesContext } from '../app/components/available-features/AvailableFeaturesContext'; -import { Feature } from '../types/features'; - -interface GithubSyncStatusOptions { - noRefetch?: boolean; -} - -export function useSyncStatusQuery(options: GithubSyncStatusOptions = {}) { - const hasGithubProvisioning = useContext(AvailableFeaturesContext).includes( - Feature.GithubProvisioning - ); - return useQuery(['github_sync', 'status'], fetchGithubProvisioningStatus, { - enabled: hasGithubProvisioning, - refetchInterval: options.noRefetch ? undefined : 10_000, - }); -} - -export function useSyncNow() { - const queryClient = useQueryClient(); - const { data } = useSyncStatusQuery(); - const mutation = useMutation(syncNowGithubProvisioning, { - onSuccess: () => { - queryClient.invalidateQueries(['github_sync']); - }, - }); - - return { - synchronizeNow: mutation.mutate, - canSyncNow: data && data.enabled && !data.nextSync && !mutation.isLoading, - }; -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/queries/identity-provider.ts b/server/sonar-web/src/main/js/queries/identity-provider.ts index 9c02a99a80c..d9af694132a 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/queries/identity-provider.ts +++ b/server/sonar-web/src/main/js/queries/identity-provider.ts @@ -26,14 +26,15 @@ import { checkConfigurationValidity, deactivateGithubProvisioning, deactivateScim, + fetchGithubProvisioningStatus, 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'; + syncNowGithubProvisioning, +} from '../api/provisioning'; +import { getSystemInfo } from '../api/system'; +import { AvailableFeaturesContext } from '../app/components/available-features/AvailableFeaturesContext'; +import { mapReactQueryResult } from '../helpers/react-query'; +import { Feature } from '../types/features'; +import { SysInfoCluster } from '../types/types'; export function useIdentityProviderQuery() { return useQuery(['identity_provider'], async () => { @@ -53,12 +54,6 @@ export function useScimStatusQuery() { }); } -export function useGithubStatusQuery() { - const res = useSyncStatusQuery({ noRefetch: true }); - - return mapReactQueryResult(res, (data) => data.enabled); -} - export function useToggleScimMutation() { const client = useQueryClient(); return useMutation({ @@ -76,7 +71,6 @@ export function useToggleGithubProvisioningMutation() { activate ? activateGithubProvisioning() : deactivateGithubProvisioning(), onSuccess: () => { client.invalidateQueries({ queryKey: ['identity_provider'] }); - client.invalidateQueries({ queryKey: ['github_sync'] }); }, }); } @@ -86,3 +80,38 @@ export const useCheckGitHubConfigQuery = (githubEnabled: boolean) => { enabled: githubEnabled, }); }; + +interface GithubSyncStatusOptions { + noRefetch?: boolean; +} + +export function useGitHubSyncStatusQuery(options: GithubSyncStatusOptions = {}) { + const hasGithubProvisioning = useContext(AvailableFeaturesContext).includes( + Feature.GithubProvisioning + ); + return useQuery(['identity_provider', 'github_sync', 'status'], fetchGithubProvisioningStatus, { + enabled: hasGithubProvisioning, + refetchInterval: options.noRefetch ? undefined : 10_000, + }); +} + +export function useGithubProvisioningEnabledQuery() { + const res = useGitHubSyncStatusQuery({ noRefetch: true }); + + return mapReactQueryResult(res, (data) => data.enabled); +} + +export function useSyncWithGitHubNow() { + const queryClient = useQueryClient(); + const { data } = useGitHubSyncStatusQuery(); + const mutation = useMutation(syncNowGithubProvisioning, { + onSuccess: () => { + queryClient.invalidateQueries(['identity_provider', 'github_sync']); + }, + }); + + return { + synchronizeNow: mutation.mutate, + canSyncNow: data?.enabled && !data.nextSync && !mutation.isLoading, + }; +} diff --git a/server/sonar-web/src/main/js/apps/settings/queries/settings.ts b/server/sonar-web/src/main/js/queries/settings.ts index 6c88431f664..4aee8e6e1bb 100644 --- a/server/sonar-web/src/main/js/apps/settings/queries/settings.ts +++ b/server/sonar-web/src/main/js/queries/settings.ts @@ -18,8 +18,8 @@ * 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'; +import { getValues, resetSettingValue, setSettingValue } from '../api/settings'; +import { ExtendedSettingDefinition } from '../types/settings'; type SettingValue = string | boolean | string[]; diff --git a/server/sonar-web/src/main/js/apps/web-api-v2/queries.ts b/server/sonar-web/src/main/js/queries/web-api.ts index 1b0bf90d8d6..b6a1fe8ab9a 100644 --- a/server/sonar-web/src/main/js/apps/web-api-v2/queries.ts +++ b/server/sonar-web/src/main/js/queries/web-api.ts @@ -19,7 +19,11 @@ */ import { useQuery } from '@tanstack/react-query'; -import { fetchOpenAPI } from '../../api/web-api'; +import { fetchOpenAPI, fetchWebApi } from '../api/web-api'; + +export function useWebApiQuery() { + return useQuery(['web-api'], () => fetchWebApi(false)); +} export const useOpenAPI = () => { return useQuery(['open_api'], fetchOpenAPI, { staleTime: Infinity, cacheTime: Infinity }); |