Use the search endpoint for listing
This commit is contained in:
@@ -95,9 +95,27 @@ const deleteExternalGroupMapping = () =>
|
||||
}
|
||||
);
|
||||
|
||||
const getExternalGroupMappingsHandler = () =>
|
||||
http.get<{ namespace: string; teamId: string }>(
|
||||
'/apis/iam.grafana.app/v0alpha1/namespaces/:namespace/teams/:teamId/groups',
|
||||
({ params }) => {
|
||||
const teamData = mockTeamsMap.get(params.teamId);
|
||||
|
||||
return HttpResponse.json({
|
||||
items: teamData
|
||||
? teamData.groups.map((group) => ({
|
||||
externalGroup: group.groupId,
|
||||
name: `mapping-${params.teamId}-${group.groupId}`,
|
||||
}))
|
||||
: [],
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default [
|
||||
getDisplayMapping(),
|
||||
listExternalGroupMappings(),
|
||||
createExternalGroupMapping(),
|
||||
deleteExternalGroupMapping(),
|
||||
getExternalGroupMappingsHandler(),
|
||||
];
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useEffect, useMemo } from 'react';
|
||||
|
||||
import {
|
||||
useCreateExternalGroupMappingMutation,
|
||||
useListExternalGroupMappingQuery,
|
||||
useGetTeamGroupsQuery,
|
||||
useDeleteExternalGroupMappingMutation,
|
||||
} from '@grafana/api-clients/rtkq/iam/v0alpha1';
|
||||
import {
|
||||
@@ -171,20 +171,18 @@ export const useGetExternalGroupMappings = (args: { teamId: string }) => {
|
||||
return useGetTeamGroupsApiQuery(args);
|
||||
}
|
||||
|
||||
const { data: newApiData, ...newApiRest } = useListExternalGroupMappingQuery({});
|
||||
const { data: newApiData, ...newApiRest } = useGetTeamGroupsQuery({ name: args.teamId });
|
||||
|
||||
const groups: TeamGroupDto[] = useMemo(() => {
|
||||
return (newApiData?.items || [])
|
||||
.filter((item) => item.spec.teamRef.name === args.teamId)
|
||||
.map(
|
||||
(item) =>
|
||||
// eslint-disable-next-line
|
||||
({
|
||||
groupId: item.spec.externalGroupId,
|
||||
teamId: item.spec.teamRef.name,
|
||||
uid: item.metadata.name,
|
||||
}) as unknown as TeamGroupDto
|
||||
);
|
||||
return (newApiData?.items || []).map(
|
||||
(item) =>
|
||||
// eslint-disable-next-line
|
||||
({
|
||||
groupId: item.externalGroup,
|
||||
teamId: args.teamId,
|
||||
uid: item.name,
|
||||
}) as unknown as TeamGroupDto
|
||||
);
|
||||
}, [newApiData, args.teamId]);
|
||||
|
||||
return {
|
||||
@@ -203,8 +201,6 @@ export const useAddExternalGroupMapping = () => {
|
||||
const add = async (args: { teamId: string; teamGroupMapping: { groupId: string } }) => {
|
||||
return addNew({
|
||||
externalGroupMapping: {
|
||||
apiVersion: 'iam.grafana.app/v0alpha1',
|
||||
kind: 'ExternalGroupMapping',
|
||||
metadata: {
|
||||
generateName: 'external-group-mapping-',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user