Refactor to avoid rule of hooks violations
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable react-hooks/rules-of-hooks */
|
|
||||||
import { skipToken } from '@reduxjs/toolkit/query';
|
import { skipToken } from '@reduxjs/toolkit/query';
|
||||||
import { useEffect, useMemo } from 'react';
|
import { useEffect, useMemo } from 'react';
|
||||||
|
|
||||||
@@ -167,11 +166,11 @@ export const useCreateTeam = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useGetExternalGroupMappings = (args: { teamId: string }) => {
|
export const useGetExternalGroupMappings = (args: { teamId: string }) => {
|
||||||
if (!config.featureToggles.kubernetesExternalGroupMapping) {
|
const shouldUseAppPlatform = Boolean(config.featureToggles.kubernetesExternalGroupMapping);
|
||||||
return useGetTeamGroupsApiQuery(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data: newApiData, ...newApiRest } = useListExternalGroupMappingQuery({});
|
const legacyResult = useGetTeamGroupsApiQuery(args, { skip: shouldUseAppPlatform });
|
||||||
|
|
||||||
|
const { data: newApiData, ...newApiRest } = useListExternalGroupMappingQuery({}, { skip: !shouldUseAppPlatform });
|
||||||
|
|
||||||
const groups: TeamGroupDto[] = useMemo(() => {
|
const groups: TeamGroupDto[] = useMemo(() => {
|
||||||
// FIXME: Consider using the search API which has sorting support
|
// FIXME: Consider using the search API which has sorting support
|
||||||
@@ -183,16 +182,17 @@ export const useGetExternalGroupMappings = (args: { teamId: string }) => {
|
|||||||
}));
|
}));
|
||||||
}, [newApiData, args.teamId]);
|
}, [newApiData, args.teamId]);
|
||||||
|
|
||||||
return {
|
if (shouldUseAppPlatform) {
|
||||||
...newApiRest,
|
return {
|
||||||
data: groups,
|
...newApiRest,
|
||||||
};
|
data: groups,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return legacyResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useAddExternalGroupMapping = () => {
|
export const useAddExternalGroupMapping = () => {
|
||||||
if (!config.featureToggles.kubernetesExternalGroupMapping) {
|
const legacyMutation = useAddTeamGroupApiMutation();
|
||||||
return useAddTeamGroupApiMutation();
|
|
||||||
}
|
|
||||||
|
|
||||||
const [addNew, newResult] = useCreateExternalGroupMappingMutation();
|
const [addNew, newResult] = useCreateExternalGroupMappingMutation();
|
||||||
|
|
||||||
@@ -212,13 +212,14 @@ export const useAddExternalGroupMapping = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!config.featureToggles.kubernetesExternalGroupMapping) {
|
||||||
|
return legacyMutation;
|
||||||
|
}
|
||||||
return [add, newResult] as const;
|
return [add, newResult] as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useRemoveExternalGroupMapping = () => {
|
export const useRemoveExternalGroupMapping = () => {
|
||||||
if (!config.featureToggles.kubernetesExternalGroupMapping) {
|
const legacyMutation = useRemoveTeamGroupApiQueryMutation();
|
||||||
return useRemoveTeamGroupApiQueryMutation();
|
|
||||||
}
|
|
||||||
|
|
||||||
const [deleteMapping, deleteResult] = useDeleteExternalGroupMappingMutation();
|
const [deleteMapping, deleteResult] = useDeleteExternalGroupMappingMutation();
|
||||||
|
|
||||||
@@ -226,5 +227,8 @@ export const useRemoveExternalGroupMapping = () => {
|
|||||||
return deleteMapping({ name: args.uid });
|
return deleteMapping({ name: args.uid });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!config.featureToggles.kubernetesExternalGroupMapping) {
|
||||||
|
return legacyMutation;
|
||||||
|
}
|
||||||
return [remove, deleteResult] as const;
|
return [remove, deleteResult] as const;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user