From: Viktor Vorona Date: Mon, 5 Feb 2024 13:21:28 +0000 (+0100) Subject: SONAR-21571 Update react-query X-Git-Tag: 10.5.0.89998~280 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2194a20a846a6aae34acc3e445bf4d58fb7eaad0;p=sonarqube.git SONAR-21571 Update react-query --- diff --git a/server/sonar-web/package.json b/server/sonar-web/package.json index 58b852ef303..0e1280ba593 100644 --- a/server/sonar-web/package.json +++ b/server/sonar-web/package.json @@ -13,7 +13,7 @@ "@primer/octicons-react": "19.8.0", "@react-spring/rafz": "9.7.3", "@react-spring/web": "9.7.3", - "@tanstack/react-query": "4.33.0", + "@tanstack/react-query": "5.18.1", "axios": "1.6.4", "classnames": "2.3.2", "clipboard": "2.0.11", diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx index 37ccc4cc98a..508eefcceb3 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx @@ -57,7 +57,7 @@ const FORM_ID = 'rule-activation-modal-form'; export default function ActivationFormModal(props: Readonly) { const { activation, rule, profiles, modalHeader } = props; - const { mutate: activateRule, isLoading: submitting } = useActivateRuleMutation((data) => { + const { mutate: activateRule, isPending: submitting } = useActivateRuleMutation((data) => { props.onDone?.(data.severity as string); props.onClose(); }); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx index d3d79510683..035e0a6cac9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx @@ -78,11 +78,11 @@ export default function CustomRuleFormModal(props: Readonly) { f: 'name,severity,params', template_key: templateRule.key, }; - const { mutate: updateRule, isLoading: updatingRule } = useUpdateRuleMutation( + const { mutate: updateRule, isPending: updatingRule } = useUpdateRuleMutation( customRulesSearchParams, props.onClose, ); - const { mutate: createRule, isLoading: creatingRule } = useCreateRuleMutation( + const { mutate: createRule, isPending: creatingRule } = useCreateRuleMutation( customRulesSearchParams, props.onClose, (response: Response) => { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsCustomRules.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsCustomRules.tsx index 7b545df9d30..0717e518569 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsCustomRules.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsCustomRules.tsx @@ -52,7 +52,7 @@ export default function RuleDetailsCustomRules(props: Readonly) { template_key: ruleDetails.key, }; const { isLoading: loadingRules, data } = useSearchRulesQuery(rulesSearchParams); - const { mutate: deleteRules, isLoading: deletingRule } = useDeleteRuleMutation(rulesSearchParams); + const { mutate: deleteRules, isPending: deletingRule } = useDeleteRuleMutation(rulesSearchParams); const loading = loadingRules || deletingRule; const rules = data?.rules ?? []; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx index 23077e42cd7..0728fe6a421 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx @@ -46,7 +46,7 @@ export default function RuleDetailsDescription(props: Readonly) { const [descriptionForm, setDescriptionForm] = React.useState(false); const [removeDescriptionModal, setDescriptionModal] = React.useState(false); - const { mutate: updateRule, isLoading: updatingRule } = useUpdateRuleMutation(undefined, () => + const { mutate: updateRule, isPending: updatingRule } = useUpdateRuleMutation(undefined, () => setDescriptionForm(false), ); diff --git a/server/sonar-web/src/main/js/apps/groups/components/DeleteGroupForm.tsx b/server/sonar-web/src/main/js/apps/groups/components/DeleteGroupForm.tsx index 5b275c2589e..4abc6d4ab07 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/DeleteGroupForm.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/DeleteGroupForm.tsx @@ -31,7 +31,7 @@ interface Props { export default function DeleteGroupForm(props: Readonly) { const { group } = props; - const { mutate: deleteGroup, isLoading } = useDeleteGroupMutation(); + const { mutate: deleteGroup, isPending } = useDeleteGroupMutation(); const onSubmit = () => { deleteGroup(group.id, { @@ -45,7 +45,7 @@ export default function DeleteGroupForm(props: Readonly) { onClose={props.onClose} body={translateWithParameters('groups.delete_group.confirmation', group.name)} primaryButton={ - + {translate('delete')} } diff --git a/server/sonar-web/src/main/js/apps/groups/components/EditMembersModal.tsx b/server/sonar-web/src/main/js/apps/groups/components/EditMembersModal.tsx index fa75a1e9932..bcb718b48a6 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/EditMembersModal.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/EditMembersModal.tsx @@ -28,6 +28,7 @@ import { translate } from '../../../helpers/l10n'; import { useAddGroupMembershipMutation, useGroupMembersQuery, + useRemoveGroupMembersQueryFromCache, useRemoveGroupMembershipMutation, } from '../../../queries/group-memberships'; import { Group } from '../../../types/types'; @@ -46,16 +47,12 @@ export default function EditMembersModal(props: Readonly) { const [filter, setFilter] = React.useState(SelectListFilter.Selected); const { mutateAsync: addUserToGroup } = useAddGroupMembershipMutation(); const { mutateAsync: removeUserFromGroup } = useRemoveGroupMembershipMutation(); - const { - data, - isLoading, - fetchNextPage, - remove: emptyQueryCache, - } = useGroupMembersQuery({ + const { data, isLoading, fetchNextPage } = useGroupMembersQuery({ q: query, groupId: group.id, filter, }); + const emptyQueryCache = useRemoveGroupMembersQueryFromCache(); const users: (RestUserBase & { selected?: boolean })[] = data?.pages.flatMap((page) => page.users) ?? []; diff --git a/server/sonar-web/src/main/js/apps/groups/components/GroupForm.tsx b/server/sonar-web/src/main/js/apps/groups/components/GroupForm.tsx index 9865567daff..0b76702de2f 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/GroupForm.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/GroupForm.tsx @@ -43,8 +43,8 @@ export default function GroupForm(props: Props) { const [name, setName] = useState(create ? '' : group.name); const [description, setDescription] = useState(create ? '' : group.description ?? ''); - const { mutate: createGroup, isLoading: isCreating } = useCreateGroupMutation(); - const { mutate: updateGroup, isLoading: isUpdating } = useUpdateGroupMutation(); + const { mutate: createGroup, isPending: isCreating } = useCreateGroupMutation(); + const { mutate: updateGroup, isPending: isUpdating } = useUpdateGroupMutation(); const handleCreateGroup = () => { createGroup({ name, description }, { onSuccess: props.onClose }); diff --git a/server/sonar-web/src/main/js/apps/overview/components/AnalysisWarningsModal.tsx b/server/sonar-web/src/main/js/apps/overview/components/AnalysisWarningsModal.tsx index d17e2f71782..1847fee0f2b 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/AnalysisWarningsModal.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/AnalysisWarningsModal.tsx @@ -37,7 +37,7 @@ interface Props { export function AnalysisWarningsModal(props: Props) { const { component, currentUser, warnings } = props; - const { mutate, isLoading, variables } = useDismissBranchWarningMutation(); + const { mutate, isPending, variables } = useDismissBranchWarningMutation(); const handleDismissMessage = (messageKey: string) => { mutate({ component, key: messageKey }); @@ -63,7 +63,7 @@ export function AnalysisWarningsModal(props: Props) { {dismissable && currentUser.isLoggedIn && (
{ handleDismissMessage(key); }} @@ -71,7 +71,7 @@ export function AnalysisWarningsModal(props: Props) { {translate('dismiss_permanently')} - +
)} diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchPurgeSetting.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchPurgeSetting.tsx index dbf6506da43..dce0f7d4ef6 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchPurgeSetting.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchPurgeSetting.tsx @@ -34,7 +34,7 @@ interface Props { export default function BranchPurgeSetting(props: Props) { const { branch, component } = props; - const { mutate: excludeFromPurge, isLoading } = useExcludeFromPurgeMutation(); + const { mutate: excludeFromPurge, isPending } = useExcludeFromPurgeMutation(); useEffect(() => { excludeFromPurge({ component, key: branch.name, exclude: branch.excludedFromPurge }); @@ -45,7 +45,7 @@ export default function BranchPurgeSetting(props: Props) { }; const isTheMainBranch = isMainBranch(branch); - const disabled = isTheMainBranch || isLoading; + const disabled = isTheMainBranch || isPending; return ( <> @@ -58,7 +58,7 @@ export default function BranchPurgeSetting(props: Props) { off: translate('off'), }} /> - + {isTheMainBranch && ( ) => { @@ -73,7 +73,7 @@ export default function DeleteBranchModal(props: Props) { /> } - loading={isLoading} + loading={isPending} primaryButton={ diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/RenameBranchModal.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/RenameBranchModal.tsx index f2a58facc77..12ec89d966b 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/RenameBranchModal.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/RenameBranchModal.tsx @@ -38,7 +38,7 @@ export default function RenameBranchModal(props: Props) { const { branch, component, onClose } = props; const [name, setName] = useState(); - const { mutate: renameMainBranch, isLoading } = useRenameMainBranchMutation(); + const { mutate: renameMainBranch, isPending } = useRenameMainBranchMutation(); const handleSubmit = React.useCallback( (event: React.SyntheticEvent) => { @@ -57,7 +57,7 @@ export default function RenameBranchModal(props: Props) { }, []); const header = translate('project_branch_pull_request.branch.rename'); - const submitDisabled = isLoading || !name || name === branch.name; + const submitDisabled = isPending || !name || name === branch.name; return ( } - loading={isLoading} + loading={isPending} primaryButton={ diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/SetAsMainBranchModal.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/SetAsMainBranchModal.tsx index 16aca54e6a3..e57ba4a2d10 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/SetAsMainBranchModal.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/SetAsMainBranchModal.tsx @@ -37,7 +37,7 @@ const FORM_ID = 'branch-setasmain-form'; export default function SetAsMainBranchModal(props: SetAsMainBranchModalProps) { const { branch, component, onClose, onSetAsMain } = props; - const { mutate: setMainBranch, isLoading } = useSetMainBranchMutation(); + const { mutate: setMainBranch, isPending } = useSetMainBranchMutation(); const handleSubmit = React.useCallback( (e: React.SyntheticEvent) => { @@ -55,7 +55,7 @@ export default function SetAsMainBranchModal(props: SetAsMainBranchModalProps) { values={{ branch: {branch.name} }} /> } - loading={isLoading} + loading={isPending} onClose={onClose} body={
@@ -83,7 +83,7 @@ export default function SetAsMainBranchModal(props: SetAsMainBranchModalProps) {
} primaryButton={ - + } 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 2acf1bdc8bc..e445738fe8d 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 @@ -65,7 +65,7 @@ export default function ProjectBadges(props: ProjectBadgesProps) { isFetching: isFetchingToken, } = useBadgeTokenQuery(project); const { data: metricOptions, isLoading: isLoadingMetrics } = useBadgeMetricsQuery(); - const { mutate: renewToken, isLoading: isRenewing } = useRenewBagdeTokenMutation(); + const { mutate: renewToken, isPending: isRenewing } = useRenewBagdeTokenMutation(); const isLoading = isLoadingMetrics || isLoadingToken || isRenewing; const handleSelectType = (selectedType: BadgeType) => { diff --git a/server/sonar-web/src/main/js/apps/projectNewCode/components/ProjectNewCodeDefinitionApp.tsx b/server/sonar-web/src/main/js/apps/projectNewCode/components/ProjectNewCodeDefinitionApp.tsx index 3301953b5b7..700a997d771 100644 --- a/server/sonar-web/src/main/js/apps/projectNewCode/components/ProjectNewCodeDefinitionApp.tsx +++ b/server/sonar-web/src/main/js/apps/projectNewCode/components/ProjectNewCodeDefinitionApp.tsx @@ -73,7 +73,7 @@ function ProjectNewCodeDefinitionApp(props: Readonly { return sortBranches(branchLikes.filter(isBranch)); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfilePermissionsForm.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfilePermissionsForm.tsx index 90fc5ce6725..b7c40626aa9 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfilePermissionsForm.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfilePermissionsForm.tsx @@ -36,10 +36,10 @@ export default function ProfilePermissionForm(props: Readonly) { const { profile } = props; const [selected, setSelected] = React.useState(); - const { mutate: addUser, isLoading: addingUser } = useAddUserMutation(() => + const { mutate: addUser, isPending: addingUser } = useAddUserMutation(() => props.onUserAdd(selected as UserSelected), ); - const { mutate: addGroup, isLoading: addingGroup } = useAddGroupMutation(() => + const { mutate: addGroup, isPending: addingGroup } = useAddGroupMutation(() => props.onGroupAdd(selected as Group), ); diff --git a/server/sonar-web/src/main/js/apps/settings/components/NewCodeDefinition.tsx b/server/sonar-web/src/main/js/apps/settings/components/NewCodeDefinition.tsx index 47920dde7fd..64e9416c45e 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/NewCodeDefinition.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/NewCodeDefinition.tsx @@ -44,7 +44,7 @@ export default function NewCodeDefinition() { >(undefined); const { data: newCodeDefinition, isLoading } = useNewCodeDefinitionQuery(); - const { isLoading: isSaving, mutate: postNewCodeDefinition } = useNewCodeDefinitionMutation(); + const { isPending: isSaving, mutate: postNewCodeDefinition } = useNewCodeDefinitionMutation(); const resetNewCodeDefinition = useCallback(() => { setSelectedNewCodeDefinitionType(newCodeDefinition?.type); diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubMappingModal.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubMappingModal.tsx index 6291b5d9410..d22e7f0bf55 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubMappingModal.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubMappingModal.tsx @@ -114,7 +114,7 @@ function PermissionRow(props: Readonly) { } export default function GitHubMappingModal({ mapping, setMapping, onClose }: Readonly) { - const { data: roles, isLoading } = useGithubRolesMappingQuery(); + const { data: roles, isPending } = useGithubRolesMappingQuery(); const permissions = convertToPermissionDefinitions( PERMISSIONS_ORDER_FOR_PROJECT_TEMPLATE, 'projects_role', @@ -234,7 +234,7 @@ export default function GitHubMappingModal({ mapping, setMapping, onClose }: Rea 'settings.authentication.github.configuration.roles_mapping.dialog.custom_roles_description', )} - + ); diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/GitLabAuthenticationTab.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/GitLabAuthenticationTab.tsx index 1de75c707cf..e7e2b41e01e 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/GitLabAuthenticationTab.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/GitLabAuthenticationTab.tsx @@ -103,8 +103,8 @@ export default function GitLabAuthenticationTab() { const { canSyncNow, synchronizeNow } = useSyncWithGitLabNow(); - const { mutate: updateConfig, isLoading: isUpdating } = useUpdateGitLabConfigurationMutation(); - const { mutate: deleteConfig, isLoading: isDeleting } = useDeleteGitLabConfigurationMutation(); + const { mutate: updateConfig, isPending: isUpdating } = useUpdateGitLabConfigurationMutation(); + const { mutate: deleteConfig, isPending: isDeleting } = useDeleteGitLabConfigurationMutation(); const definitions = getDefinitions( changes?.provisioningType ?? configuration?.provisioningType ?? ProvisioningType.jit, diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/GitLabConfigurationForm.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/GitLabConfigurationForm.tsx index f17d87d5b4c..41845a5b896 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/GitLabConfigurationForm.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/GitLabConfigurationForm.tsx @@ -55,8 +55,8 @@ export default function GitLabConfigurationForm(props: Readonly) { const { data } = props; const isCreate = data === null; const [errors, setErrors] = React.useState>({}); - const { mutate: createConfig, isLoading: createLoading } = useCreateGitLabConfigurationMutation(); - const { mutate: updateConfig, isLoading: updateLoading } = useUpdateGitLabConfigurationMutation(); + const { mutate: createConfig, isPending: createLoading } = useCreateGitLabConfigurationMutation(); + const { mutate: updateConfig, isPending: updateLoading } = useUpdateGitLabConfigurationMutation(); const [formData, setFormData] = React.useState< Record 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 16028509502..d582ecd64a8 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 @@ -86,7 +86,7 @@ export default function GithubAuthenticationTab(props: GithubAuthenticationProps setRolesMapping, applyAdditionalOptions, hasLegacyConfiguration, - deleteMutation: { isLoading: isDeleting, mutate: deleteConfiguration }, + deleteMutation: { isPending: isDeleting, mutate: deleteConfiguration }, } = useGithubConfiguration(definitions); const provisioningStatus = 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 b253dc80787..cb0c2b6c9eb 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 @@ -68,7 +68,7 @@ export default function SamlAuthenticationTab(props: SamlAuthenticationProps) { newScimStatus, setNewScimStatus, setNewGroupSetting, - deleteMutation: { isLoading: isDeleting, mutate: deleteConfiguration }, + deleteMutation: { isPending: isDeleting, mutate: deleteConfiguration }, } = useSamlConfiguration(definitions); const toggleScim = useToggleScimMutation(); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx index 5da48c1bb73..a56bf2fcb1a 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx @@ -80,10 +80,10 @@ export function PRDecorationBinding(props: Props) { const [successfullyUpdated, setSuccessfullyUpdated] = React.useState(false); const [checkingConfiguration, setCheckingConfiguration] = React.useState(false); const { data: originalData } = useProjectBindingQuery(component.key); - const { mutateAsync: deleteMutation, isLoading: isDeleting } = useDeleteProjectAlmBindingMutation( + const { mutateAsync: deleteMutation, isPending: isDeleting } = useDeleteProjectAlmBindingMutation( component.key, ); - const { mutateAsync: updateMutation, isLoading: isUpdating } = useSetProjectBindingMutation(); + const { mutateAsync: updateMutation, isPending: isUpdating } = useSetProjectBindingMutation(); const isConfigured = !!originalData; const updating = isDeleting || isUpdating; diff --git a/server/sonar-web/src/main/js/apps/users/components/DeactivateForm.tsx b/server/sonar-web/src/main/js/apps/users/components/DeactivateForm.tsx index 40c4f688b6a..c681a0dc0ac 100644 --- a/server/sonar-web/src/main/js/apps/users/components/DeactivateForm.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/DeactivateForm.tsx @@ -43,7 +43,7 @@ export default function DeactivateForm(props: Props) { const { user } = props; const [anonymize, setAnonymize] = React.useState(false); - const { mutate: deactivateUser, isLoading } = useDeactivateUserMutation(); + const { mutate: deactivateUser, isPending } = useDeactivateUserMutation(); const handleDeactivate = (event: React.SyntheticEvent) => { event.preventDefault(); @@ -88,9 +88,9 @@ export default function DeactivateForm(props: Props) { } onClose={props.onClose} - loading={isLoading} + loading={isPending} primaryButton={ - + {translate('users.deactivate')} } diff --git a/server/sonar-web/src/main/js/apps/users/components/TokensForm.tsx b/server/sonar-web/src/main/js/apps/users/components/TokensForm.tsx index 6961767c107..42b2cbaa6ae 100644 --- a/server/sonar-web/src/main/js/apps/users/components/TokensForm.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/TokensForm.tsx @@ -73,7 +73,7 @@ export function TokensForm(props: Readonly) { const [tokenExpirationOptions, setTokenExpirationOptions] = React.useState<{ value: TokenExpiration; label: string }[]>(EXPIRATION_OPTIONS); - const { mutateAsync: generate, isLoading: generating } = useGenerateTokenMutation(); + const { mutateAsync: generate, isPending: generating } = useGenerateTokenMutation(); const tokenTypeOptions = React.useMemo(() => { const value = [{ label: translate('users.tokens', TokenType.User), value: TokenType.User }]; diff --git a/server/sonar-web/src/main/js/apps/users/components/TokensFormItem.tsx b/server/sonar-web/src/main/js/apps/users/components/TokensFormItem.tsx index 84e81312d0a..c6ec562dba3 100644 --- a/server/sonar-web/src/main/js/apps/users/components/TokensFormItem.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/TokensFormItem.tsx @@ -48,7 +48,7 @@ interface Props { export default function TokensFormItem(props: Readonly) { const { token, deleteConfirmation, login } = props; const [showConfirmation, setShowConfirmation] = React.useState(false); - const { mutateAsync, isLoading } = useRevokeTokenMutation(); + const { mutateAsync, isPending } = useRevokeTokenMutation(); const handleRevoke = () => mutateAsync({ login, name: token.name }); @@ -116,11 +116,11 @@ export default function TokensFormItem(props: Readonly) { {token.isExpired && ( - + {translate('remove')} @@ -142,7 +142,7 @@ export default function TokensFormItem(props: Readonly) { > {({ onClick }) => ( @@ -159,10 +159,10 @@ export default function TokensFormItem(props: Readonly) { ? translate('users.tokens.sure') : translateWithParameters('users.tokens.revoke_label', token.name) } - disabled={isLoading} + disabled={isPending} onClick={handleClick} > - + {showConfirmation ? translate('users.tokens.sure') : translate('users.tokens.revoke')} diff --git a/server/sonar-web/src/main/js/apps/users/components/UserForm.tsx b/server/sonar-web/src/main/js/apps/users/components/UserForm.tsx index 21a167daa48..8e572e5353e 100644 --- a/server/sonar-web/src/main/js/apps/users/components/UserForm.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/UserForm.tsx @@ -48,8 +48,8 @@ const INTERNAL_SERVER_ERROR = 500; export default function UserForm(props: Props) { const { user, isInstanceManaged } = props; - const { mutate: createUser, isLoading: isLoadingCreate } = usePostUserMutation(); - const { mutate: updateUser, isLoading: isLoadingUserUpdate } = useUpdateUserMutation(); + const { mutate: createUser, isPending: isLoadingCreate } = usePostUserMutation(); + const { mutate: updateUser, isPending: isLoadingUserUpdate } = useUpdateUserMutation(); const [email, setEmail] = React.useState(user?.email ?? ''); const [login, setLogin] = React.useState(user?.login ?? ''); diff --git a/server/sonar-web/src/main/js/queries/badges.ts b/server/sonar-web/src/main/js/queries/badges.ts index f8346b94b08..914ee8167aa 100644 --- a/server/sonar-web/src/main/js/queries/badges.ts +++ b/server/sonar-web/src/main/js/queries/badges.ts @@ -67,7 +67,8 @@ export function useBadgeMetricsQuery() { } export function useBadgeTokenQuery(componentKey: string) { - return useQuery(['badges-token', componentKey] as const, ({ queryKey: [_, key] }) => - getProjectBadgesToken(key), - ); + return useQuery({ + queryKey: ['badges-token', componentKey] as const, + queryFn: ({ queryKey: [_, key] }) => getProjectBadgesToken(key), + }); } diff --git a/server/sonar-web/src/main/js/queries/devops-integration.ts b/server/sonar-web/src/main/js/queries/devops-integration.ts index 50e225fb5f2..4620641a5cc 100644 --- a/server/sonar-web/src/main/js/queries/devops-integration.ts +++ b/server/sonar-web/src/main/js/queries/devops-integration.ts @@ -40,36 +40,39 @@ function useProjectKeyFromLocation() { export function useProjectBindingQuery( project?: string, - options?: UseQueryOptions< - ProjectAlmBindingResponse, - unknown, - T, - ['devops_integration', string, 'binding'] + options?: Omit< + UseQueryOptions< + ProjectAlmBindingResponse | null, + Error, + T, + ['devops_integration', string, 'binding'] + >, + 'queryKey' | 'queryFn' >, ) { const keyFromUrl = useProjectKeyFromLocation(); const projectKey = project ?? keyFromUrl; - return useQuery( - ['devops_integration', projectKey, 'binding'], - ({ queryKey: [_, key] }) => + return useQuery({ + queryKey: ['devops_integration', projectKey, 'binding'], + queryFn: ({ queryKey: [_, key] }) => getProjectAlmBinding(key).catch((e: Response) => { if (e.status === HttpStatus.NotFound) { return null; } - throw e; + return e; }), - { - staleTime: 60_000, - retry: false, - ...options, - }, - ); + staleTime: 60_000, + retry: false, + ...options, + }); } export function useIsGitHubProjectQuery(project?: string) { - return useProjectBindingQuery(project, { select: (data) => data?.alm === AlmKeys.GitHub }); + return useProjectBindingQuery(project, { + select: (data) => data?.alm === AlmKeys.GitHub, + }); } export function useDeleteProjectAlmBindingMutation(project?: string) { @@ -78,7 +81,9 @@ export function useDeleteProjectAlmBindingMutation(project?: string) { return useMutation({ mutationFn: () => deleteProjectAlmBinding(project ?? keyFromUrl), onSuccess: () => { - client.invalidateQueries(['devops_integration', project ?? keyFromUrl, 'binding']); + client.invalidateQueries({ + queryKey: ['devops_integration', project ?? keyFromUrl, 'binding'], + }); }, }); } @@ -153,7 +158,7 @@ export function useSetProjectBindingMutation() { return useMutation({ mutationFn: (data: SetBindingParams) => getSetProjectBindingFn(data), onSuccess: (_, variables) => { - client.invalidateQueries(['devops_integration', variables.project, 'binding']); + client.invalidateQueries({ queryKey: ['devops_integration', variables.project, 'binding'] }); }, }); } diff --git a/server/sonar-web/src/main/js/queries/group-memberships.ts b/server/sonar-web/src/main/js/queries/group-memberships.ts index a513895ca7e..457040f34cf 100644 --- a/server/sonar-web/src/main/js/queries/group-memberships.ts +++ b/server/sonar-web/src/main/js/queries/group-memberships.ts @@ -41,8 +41,8 @@ export function useGroupMembersQuery(params: { pageIndex?: number; }) { return useInfiniteQuery({ - queryKey: [DOMAIN, GROUP_SUB_DOMAIN, params], - queryFn: async ({ pageParam = 1 }) => { + queryKey: [DOMAIN, GROUP_SUB_DOMAIN, 'list', params], + queryFn: async ({ pageParam }) => { if (params.filter === SelectListFilter.All) { const result = await getUsers({ q: params.q ?? '', @@ -77,9 +77,17 @@ export function useGroupMembersQuery(params: { }, getNextPageParam, getPreviousPageParam, + initialPageParam: 1, }); } +export function useRemoveGroupMembersQueryFromCache() { + const queryClient = useQueryClient(); + return () => { + queryClient.removeQueries({ queryKey: [DOMAIN, GROUP_SUB_DOMAIN, 'list'] }); + }; +} + export function useUserGroupsQuery(params: { filter?: SelectListFilter; q?: string; @@ -88,21 +96,22 @@ export function useUserGroupsQuery(params: { const { q, filter, userId } = params; const { data: groupsPages, - isLoading: loadingGroups, + isPending: loadingGroups, fetchNextPage: fetchNextPageGroups, hasNextPage: hasNextPageGroups, } = useGroupsQueries({}); const { data: membershipsPages, - isLoading: loadingMemberships, + isPending: loadingMemberships, fetchNextPage: fetchNextPageMemberships, hasNextPage: hasNextPageMemberships, } = useInfiniteQuery({ queryKey: [DOMAIN, USER_SUB_DOMAIN, 'memberships', userId], - queryFn: ({ pageParam = 1 }) => + queryFn: ({ pageParam }) => getGroupMemberships({ userId, pageSize: 100, pageIndex: pageParam }), getNextPageParam, getPreviousPageParam, + initialPageParam: 1, }); if (hasNextPageGroups) { fetchNextPageGroups(); @@ -167,7 +176,9 @@ export function useAddGroupMembershipMutation() { [DOMAIN, USER_SUB_DOMAIN, 'count', data.userId], (oldData) => (oldData !== undefined ? oldData + 1 : undefined), ); - queryClient.invalidateQueries([DOMAIN, USER_SUB_DOMAIN, 'memberships', data.userId]); + queryClient.invalidateQueries({ + queryKey: [DOMAIN, USER_SUB_DOMAIN, 'memberships', data.userId], + }); }, }); } @@ -194,7 +205,9 @@ export function useRemoveGroupMembershipMutation() { [DOMAIN, USER_SUB_DOMAIN, 'count', data.userId], (oldData) => (oldData !== undefined ? oldData - 1 : undefined), ); - queryClient.invalidateQueries([DOMAIN, USER_SUB_DOMAIN, 'memberships', data.userId]); + queryClient.invalidateQueries({ + queryKey: [DOMAIN, USER_SUB_DOMAIN, 'memberships', data.userId], + }); }, }); } diff --git a/server/sonar-web/src/main/js/queries/groups.ts b/server/sonar-web/src/main/js/queries/groups.ts index ea96fa495e8..ac331a70473 100644 --- a/server/sonar-web/src/main/js/queries/groups.ts +++ b/server/sonar-web/src/main/js/queries/groups.ts @@ -26,9 +26,10 @@ export function useGroupsQueries( ) { return useInfiniteQuery({ queryKey: ['group', 'list', getParams], - queryFn: ({ pageParam = 1 }) => getUsersGroups({ ...getParams, pageIndex: pageParam }), + queryFn: ({ pageParam }) => getUsersGroups({ ...getParams, pageIndex: pageParam }), getNextPageParam, getPreviousPageParam, + initialPageParam: 1, }); } diff --git a/server/sonar-web/src/main/js/queries/identity-provider/common.ts b/server/sonar-web/src/main/js/queries/identity-provider/common.ts index 4bba1554aa7..fd080b4e281 100644 --- a/server/sonar-web/src/main/js/queries/identity-provider/common.ts +++ b/server/sonar-web/src/main/js/queries/identity-provider/common.ts @@ -22,8 +22,11 @@ import { getSystemInfo } from '../../api/system'; import { SysInfoCluster } from '../../types/types'; export function useIdentityProviderQuery() { - return useQuery(['identity_provider', 'users_and_groups_provider'], async () => { - const info = (await getSystemInfo()) as SysInfoCluster; - return { provider: info.System['External Users and Groups Provisioning'] }; + return useQuery({ + queryKey: ['identity_provider', 'users_and_groups_provider'], + queryFn: async () => { + const info = (await getSystemInfo()) as SysInfoCluster; + return { provider: info.System['External Users and Groups Provisioning'] }; + }, }); } diff --git a/server/sonar-web/src/main/js/queries/identity-provider/github.ts b/server/sonar-web/src/main/js/queries/identity-provider/github.ts index d7b6152ec49..694ac7d5ff0 100644 --- a/server/sonar-web/src/main/js/queries/identity-provider/github.ts +++ b/server/sonar-web/src/main/js/queries/identity-provider/github.ts @@ -52,7 +52,9 @@ export function useToggleGithubProvisioningMutation() { } export const useCheckGitHubConfigQuery = (githubEnabled: boolean) => { - return useQuery(['identity_provider', 'github_check'], checkConfigurationValidity, { + return useQuery({ + queryKey: ['identity_provider', 'github_check'], + queryFn: checkConfigurationValidity, enabled: githubEnabled, }); }; @@ -65,7 +67,9 @@ export function useGitHubSyncStatusQuery(options: GithubSyncStatusOptions = {}) const hasGithubProvisioning = useContext(AvailableFeaturesContext).includes( Feature.GithubProvisioning, ); - return useQuery(['identity_provider', 'github_sync', 'status'], fetchGithubProvisioningStatus, { + return useQuery({ + queryKey: ['identity_provider', 'github_sync', 'status'], + queryFn: fetchGithubProvisioningStatus, enabled: hasGithubProvisioning, refetchInterval: options.noRefetch ? undefined : 10_000, }); @@ -80,15 +84,16 @@ export function useGithubProvisioningEnabledQuery() { export function useSyncWithGitHubNow() { const queryClient = useQueryClient(); const { data } = useGitHubSyncStatusQuery(); - const mutation = useMutation(syncNowGithubProvisioning, { + const mutation = useMutation({ + mutationFn: syncNowGithubProvisioning, onSuccess: () => { - queryClient.invalidateQueries(['identity_provider', 'github_sync']); + queryClient.invalidateQueries({ queryKey: ['identity_provider', 'github_sync'] }); }, }); return { synchronizeNow: mutation.mutate, - canSyncNow: data?.enabled && !data.nextSync && !mutation.isLoading, + canSyncNow: data?.enabled && !data.nextSync && !mutation.isPending, }; } @@ -96,7 +101,9 @@ export function useSyncWithGitHubNow() { const defaultRoleOrder = ['admin', 'maintain', 'write', 'triage', 'read']; export function useGithubRolesMappingQuery() { - return useQuery(['identity_provider', 'github_mapping'], fetchGithubRolesMapping, { + return useQuery({ + queryKey: ['identity_provider', 'github_mapping'], + queryFn: fetchGithubRolesMapping, staleTime: MAPPING_STALE_TIME, select: (data) => [...data].sort((a, b) => { diff --git a/server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts b/server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts index 11692886506..4af3d08e285 100644 --- a/server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts +++ b/server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts @@ -32,7 +32,10 @@ import { AlmSyncStatus, ProvisioningType } from '../../types/provisioning'; import { TaskStatuses, TaskTypes } from '../../types/tasks'; export function useGitLabConfigurationsQuery() { - return useQuery(['identity_provider', 'gitlab_config', 'list'], fetchGitLabConfigurations); + return useQuery({ + queryKey: ['identity_provider', 'gitlab_config', 'list'], + queryFn: fetchGitLabConfigurations, + }); } export function useCreateGitLabConfigurationMutation() { @@ -141,19 +144,17 @@ export function useGitLabSyncStatusQuery() { return { status: nextSync.status as TaskStatuses.Pending | TaskStatuses.InProgress }; }; - return useQuery( - ['identity_provider', 'gitlab_sync', 'status'], - async () => { + return useQuery({ + queryKey: ['identity_provider', 'gitlab_sync', 'status'], + queryFn: async () => { const [lastSync, nextSync] = await Promise.all([getLastSync(), getNextSync()]); return { lastSync, nextSync, } as AlmSyncStatus; }, - { - refetchInterval: 10_000, - }, - ); + refetchInterval: 10_000, + }); } export function useSyncWithGitLabNow() { @@ -164,14 +165,15 @@ export function useSyncWithGitLabNow() { (configuration) => configuration.enabled && configuration.provisioningType === ProvisioningType.auto, ); - const mutation = useMutation(syncNowGitLabProvisioning, { + const mutation = useMutation({ + mutationFn: syncNowGitLabProvisioning, onSuccess: () => { - queryClient.invalidateQueries(['identity_provider', 'gitlab_sync']); + queryClient.invalidateQueries({ queryKey: ['identity_provider', 'gitlab_sync'] }); }, }); return { synchronizeNow: mutation.mutate, - canSyncNow: autoProvisioningEnabled && !syncStatus?.nextSync && !mutation.isLoading, + canSyncNow: autoProvisioningEnabled && !syncStatus?.nextSync && !mutation.isPending, }; } diff --git a/server/sonar-web/src/main/js/queries/identity-provider/scim.ts b/server/sonar-web/src/main/js/queries/identity-provider/scim.ts index 16e2f3b60eb..5ead680bd96 100644 --- a/server/sonar-web/src/main/js/queries/identity-provider/scim.ts +++ b/server/sonar-web/src/main/js/queries/identity-provider/scim.ts @@ -26,11 +26,14 @@ import { Feature } from '../../types/features'; export function useScimStatusQuery() { const hasScim = useContext(AvailableFeaturesContext).includes(Feature.Scim); - return useQuery(['identity_provider', 'scim_status'], () => { - if (!hasScim) { - return false; - } - return fetchIsScimEnabled(); + return useQuery({ + queryKey: ['identity_provider', 'scim_status'], + queryFn: () => { + if (!hasScim) { + return false; + } + return fetchIsScimEnabled(); + }, }); } diff --git a/server/sonar-web/src/main/js/queries/newCodeDefinition.ts b/server/sonar-web/src/main/js/queries/newCodeDefinition.ts index 6642a6f4704..cf00c317e0e 100644 --- a/server/sonar-web/src/main/js/queries/newCodeDefinition.ts +++ b/server/sonar-web/src/main/js/queries/newCodeDefinition.ts @@ -36,11 +36,13 @@ export function useNewCodeDefinitionQuery(params?: { enabled?: boolean; projectKey?: string; }) { - return useQuery( - getNewCodeDefinitionQueryKey(params?.projectKey, params?.branchName), - () => getNewCodeDefinition({ branch: params?.branchName, project: params?.projectKey }), - { enabled: params?.enabled ?? true, refetchOnWindowFocus: false }, - ); + return useQuery({ + queryKey: getNewCodeDefinitionQueryKey(params?.projectKey, params?.branchName), + queryFn: () => + getNewCodeDefinition({ branch: params?.branchName, project: params?.projectKey }), + enabled: params?.enabled ?? true, + refetchOnWindowFocus: false, + }); } export function useNewCodeDefinitionMutation() { diff --git a/server/sonar-web/src/main/js/queries/quality-gates.ts b/server/sonar-web/src/main/js/queries/quality-gates.ts index f73b05c7bd5..7ef74ae3703 100644 --- a/server/sonar-web/src/main/js/queries/quality-gates.ts +++ b/server/sonar-web/src/main/js/queries/quality-gates.ts @@ -80,7 +80,7 @@ export function useCreateQualityGateMutation() { return createQualityGate({ name }); }, onSuccess: () => { - queryClient.invalidateQueries(getQualityGateQueryKey()); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); }, }); } @@ -93,8 +93,8 @@ export function useSetQualityGateAsDefaultMutation(gateName: string) { return setQualityGateAsDefault({ name: qualityGate.name }); }, onSuccess: () => { - queryClient.invalidateQueries(getQualityGateQueryKey()); - queryClient.invalidateQueries(getQualityGateQueryKey('name', gateName)); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey('name', gateName) }); }, }); } @@ -107,8 +107,8 @@ export function useRenameQualityGateMutation(currentName: string) { return renameQualityGate({ currentName, name: newName }); }, onSuccess: (_, newName: string) => { - queryClient.invalidateQueries(getQualityGateQueryKey()); - queryClient.invalidateQueries(getQualityGateQueryKey('name', newName)); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey('name', newName) }); }, }); } @@ -121,7 +121,7 @@ export function useCopyQualityGateMutation(sourceName: string) { return copyQualityGate({ sourceName, name: newName }); }, onSuccess: () => { - queryClient.invalidateQueries(getQualityGateQueryKey()); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); }, }); } @@ -134,7 +134,7 @@ export function useDeleteQualityGateMutation(name: string) { return deleteQualityGate({ name }); }, onSuccess: () => { - queryClient.invalidateQueries(getQualityGateQueryKey()); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); }, }); } @@ -169,8 +169,8 @@ export function useFixQualityGateMutation(gateName: string) { return Promise.all(promiseArr); }, onSuccess: () => { - queryClient.invalidateQueries(getQualityGateQueryKey()); - queryClient.invalidateQueries(getQualityGateQueryKey('name', gateName)); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey('name', gateName) }); addGlobalSuccessMessage(translate('quality_gates.conditions_updated')); }, }); @@ -184,7 +184,7 @@ export function useCreateConditionMutation(gateName: string) { return createCondition({ ...condition, gateName }); }, onSuccess: (_, condition) => { - queryClient.invalidateQueries(getQualityGateQueryKey()); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); queryClient.setQueryData( getQualityGateQueryKey('name', gateName), (oldData?: QualityGate) => { @@ -196,7 +196,7 @@ export function useCreateConditionMutation(gateName: string) { : undefined; }, ); - queryClient.invalidateQueries(getQualityGateQueryKey('name', gateName)); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey('name', gateName) }); addGlobalSuccessMessage(translate('quality_gates.condition_added')); }, }); @@ -210,8 +210,8 @@ export function useUpdateConditionMutation(gateName: string) { return updateCondition(condition); }, onSuccess: () => { - queryClient.invalidateQueries(getQualityGateQueryKey()); - queryClient.invalidateQueries(getQualityGateQueryKey('name', gateName)); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey('name', gateName) }); addGlobalSuccessMessage(translate('quality_gates.condition_updated')); }, }); @@ -227,8 +227,8 @@ export function useDeleteConditionMutation(gateName: string) { }); }, onSuccess: () => { - queryClient.invalidateQueries(getQualityGateQueryKey()); - queryClient.invalidateQueries(getQualityGateQueryKey('name', gateName)); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey() }); + queryClient.invalidateQueries({ queryKey: getQualityGateQueryKey('name', gateName) }); addGlobalSuccessMessage(translate('quality_gates.condition_deleted')); }, }); diff --git a/server/sonar-web/src/main/js/queries/settings.ts b/server/sonar-web/src/main/js/queries/settings.ts index f61420dcbac..225957e384f 100644 --- a/server/sonar-web/src/main/js/queries/settings.ts +++ b/server/sonar-web/src/main/js/queries/settings.ts @@ -26,14 +26,20 @@ 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 }); + return useQuery({ + queryKey: ['settings', 'values', keys] as const, + queryFn: ({ queryKey: [_a, _b, keys] }) => { + return getValues({ keys }); + }, }); } export function useGetValueQuery(key: string, component?: string) { - return useQuery(['settings', 'details', key] as const, ({ queryKey: [_a, _b, key] }) => { - return getValue({ key, component }).then((v) => v ?? null); + return useQuery({ + queryKey: ['settings', 'details', key] as const, + queryFn: ({ queryKey: [_a, _b, key] }) => { + return getValue({ key, component }).then((v) => v ?? null); + }, }); } @@ -44,9 +50,9 @@ export function useResetSettingsMutation() { resetSettingValue({ keys: keys.join(','), component }), onSuccess: (_, { keys }) => { keys.forEach((key) => { - queryClient.invalidateQueries(['settings', 'details', key]); + queryClient.invalidateQueries({ queryKey: ['settings', 'details', key] }); }); - queryClient.invalidateQueries(['settings', 'values']); + queryClient.invalidateQueries({ queryKey: ['settings', 'values'] }); }, }); } @@ -80,9 +86,9 @@ export function useSaveValuesMutation() { onSuccess: (data) => { if (data.length > 0) { data.forEach(({ key }) => { - queryClient.invalidateQueries(['settings', 'details', key]); + queryClient.invalidateQueries({ queryKey: ['settings', 'details', key] }); }); - queryClient.invalidateQueries(['settings', 'values']); + queryClient.invalidateQueries({ queryKey: ['settings', 'values'] }); addGlobalSuccessMessage(translate('settings.authentication.form.settings.save_success')); } }, @@ -107,8 +113,8 @@ export function useSaveValueMutation() { return setSettingValue(definition, newValue, component); }, onSuccess: (_, { definition }) => { - queryClient.invalidateQueries(['settings', 'details', definition.key]); - queryClient.invalidateQueries(['settings', 'values']); + queryClient.invalidateQueries({ queryKey: ['settings', 'details', definition.key] }); + queryClient.invalidateQueries({ queryKey: ['settings', 'values'] }); addGlobalSuccessMessage(translate('settings.authentication.form.settings.save_success')); }, }); diff --git a/server/sonar-web/src/main/js/queries/users.ts b/server/sonar-web/src/main/js/queries/users.ts index 3991572059d..c7391c0b002 100644 --- a/server/sonar-web/src/main/js/queries/users.ts +++ b/server/sonar-web/src/main/js/queries/users.ts @@ -33,10 +33,11 @@ export function useUsersQueries( ) { return useInfiniteQuery({ queryKey: ['user', 'list', getParams], - queryFn: ({ pageParam = 1 }) => getUsers({ ...getParams, pageIndex: pageParam }), + queryFn: ({ pageParam }) => getUsers({ ...getParams, pageIndex: pageParam }), getNextPageParam, getPreviousPageParam, enabled, + initialPageParam: 1, }); } diff --git a/server/sonar-web/src/main/js/queries/web-api.ts b/server/sonar-web/src/main/js/queries/web-api.ts index de1f0291bed..bbb1ff20863 100644 --- a/server/sonar-web/src/main/js/queries/web-api.ts +++ b/server/sonar-web/src/main/js/queries/web-api.ts @@ -21,9 +21,14 @@ import { useQuery } from '@tanstack/react-query'; import { fetchOpenAPI, fetchWebApi } from '../api/web-api'; export function useWebApiQuery() { - return useQuery(['web-api'], () => fetchWebApi(false)); + return useQuery({ queryKey: ['web-api'], queryFn: () => fetchWebApi(false) }); } export const useOpenAPI = () => { - return useQuery(['open_api'], fetchOpenAPI, { staleTime: Infinity, cacheTime: Infinity }); + return useQuery({ + queryKey: ['open_api'], + queryFn: fetchOpenAPI, + staleTime: Infinity, + gcTime: Infinity, + }); }; diff --git a/server/sonar-web/yarn.lock b/server/sonar-web/yarn.lock index b07f184b41a..0338724de3b 100644 --- a/server/sonar-web/yarn.lock +++ b/server/sonar-web/yarn.lock @@ -4193,29 +4193,21 @@ __metadata: languageName: node linkType: hard -"@tanstack/query-core@npm:4.33.0": - version: 4.33.0 - resolution: "@tanstack/query-core@npm:4.33.0" - checksum: fae325f1d79b936435787797c32367331d5b8e9c5ced84852bf2085115e3aafef57a7ae530a6b0af46da4abafb4b0afaef885926b71715a0e6f166d74da61c7f +"@tanstack/query-core@npm:5.18.1": + version: 5.18.1 + resolution: "@tanstack/query-core@npm:5.18.1" + checksum: dd831e508fa4519a6e88af1f48e24c75f8c603d77dc603745c3f69ab6d650ba85b43041ab19572f20139dde13c56e6f477552228d469371b01ebe4268933a795 languageName: node linkType: hard -"@tanstack/react-query@npm:4.33.0": - version: 4.33.0 - resolution: "@tanstack/react-query@npm:4.33.0" +"@tanstack/react-query@npm:5.18.1": + version: 5.18.1 + resolution: "@tanstack/react-query@npm:5.18.1" dependencies: - "@tanstack/query-core": 4.33.0 - use-sync-external-store: ^1.2.0 + "@tanstack/query-core": 5.18.1 peerDependencies: - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 - react-native: "*" - peerDependenciesMeta: - react-dom: - optional: true - react-native: - optional: true - checksum: b3cf4afa427435e464e077b3f23c891e38e5f78873518f15c1d061ad55f1464d6241ecd92d796a5dbc9412b4fd7eb30b01f2a9cfc285ee9f30dfdd2ca0ecaf4b + react: ^18.0.0 + checksum: d24d79b7bf464d0c80c72d6c93d5e51c7c400a0ed895f6bda9e6f53c3c576a08d7302193c70b6d5e2842981354a739ed9b12de9bb4e5fe35e8b41aa9e833f5af languageName: node linkType: hard @@ -5229,7 +5221,7 @@ __metadata: "@react-spring/web": 9.7.3 "@swc/core": 1.3.95 "@swc/jest": 0.2.29 - "@tanstack/react-query": 4.33.0 + "@tanstack/react-query": 5.18.1 "@testing-library/jest-dom": 6.1.4 "@testing-library/react": 14.1.0 "@testing-library/user-event": 14.5.1 @@ -13643,15 +13635,6 @@ __metadata: languageName: node linkType: hard -"use-sync-external-store@npm:^1.2.0": - version: 1.2.0 - resolution: "use-sync-external-store@npm:1.2.0" - peerDependencies: - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - checksum: 5c639e0f8da3521d605f59ce5be9e094ca772bd44a4ce7322b055a6f58eeed8dda3c94cabd90c7a41fb6fa852210092008afe48f7038792fd47501f33299116a - languageName: node - linkType: hard - "util-deprecate@npm:^1.0.2, util-deprecate@npm:~1.0.1": version: 1.0.2 resolution: "util-deprecate@npm:1.0.2"