Browse Source

SONAR-21692 fix react-queries to not do calls when it is not needed

tags/10.5.0.89998
Viktor Vorona 2 months ago
parent
commit
5508f434eb

+ 3
- 1
server/sonar-web/src/main/js/components/permissions/GroupHolder.tsx View File

@@ -58,7 +58,9 @@ export default function GroupHolder(props: Props) {
permissions,
removeOnly,
});
const { data: identityProvider } = useIdentityProviderQuery();
const { data: identityProvider } = useIdentityProviderQuery({
enabled: isGitHubProject ?? false,
});

const description =
group.name === ANYONE ? translate('user_groups.anyone.description') : group.description;

+ 3
- 1
server/sonar-web/src/main/js/components/permissions/UserHolder.tsx View File

@@ -45,7 +45,9 @@ export default function UserHolder(props: Props) {
permissions,
removeOnly,
});
const { data: identityProvider } = useIdentityProviderQuery();
const { data: identityProvider } = useIdentityProviderQuery({
enabled: isGitHubProject ?? false,
});

const permissionCells = permissions.map((permission) => (
<PermissionCell

+ 13
- 2
server/sonar-web/src/main/js/queries/devops-integration.ts View File

@@ -33,6 +33,10 @@ import { AlmKeys, ProjectAlmBindingParams, ProjectAlmBindingResponse } from '../

function useProjectKeyFromLocation() {
const location = useLocation();
// Permissions Templates page uses id in query for template id, so to avoid conflict and unwanted fetching we don't search for project there
if (location.pathname.includes('permission_templates')) {
return null;
}
const search = new URLSearchParams(location.search);
const id = search.get('id');
return id as string;
@@ -55,7 +59,7 @@ export function useProjectBindingQuery<T = ProjectAlmBindingResponse>(
const projectKey = project ?? keyFromUrl;

return useQuery({
queryKey: ['devops_integration', projectKey, 'binding'],
queryKey: ['devops_integration', projectKey ?? '_blank_', 'binding'],
queryFn: ({ queryKey: [_, key] }) =>
getProjectAlmBinding(key).catch((e: Response) => {
if (e.status === HttpStatus.NotFound) {
@@ -65,6 +69,7 @@ export function useProjectBindingQuery<T = ProjectAlmBindingResponse>(
}),
staleTime: 60_000,
retry: false,
enabled: projectKey !== null,
...options,
});
}
@@ -79,7 +84,13 @@ export function useDeleteProjectAlmBindingMutation(project?: string) {
const keyFromUrl = useProjectKeyFromLocation();
const client = useQueryClient();
return useMutation({
mutationFn: () => deleteProjectAlmBinding(project ?? keyFromUrl),
mutationFn: () => {
const key = project ?? keyFromUrl;
if (key === null) {
throw new Error('No project key');
}
return deleteProjectAlmBinding(key);
},
onSuccess: () => {
client.invalidateQueries({
queryKey: ['devops_integration', project ?? keyFromUrl, 'binding'],

+ 6
- 3
server/sonar-web/src/main/js/queries/identity-provider/common.ts View File

@@ -17,16 +17,19 @@
* 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 { UseQueryOptions, useQuery } from '@tanstack/react-query';
import { getSystemInfo } from '../../api/system';
import { SysInfoCluster } from '../../types/types';
import { Provider, SysInfoCluster } from '../../types/types';

export function useIdentityProviderQuery() {
export function useIdentityProviderQuery<T = { provider: Provider }>(
options?: Omit<UseQueryOptions<{ provider: Provider }, Error, T>, 'queryKey' | 'queryFn'>,
) {
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'] };
},
...options,
});
}

Loading…
Cancel
Save