update dataset groups

This commit is contained in:
Nate Kelley 2025-03-10 21:05:04 -06:00
parent 2d2396c0bf
commit 3fbd22b250
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
6 changed files with 109 additions and 104 deletions

View File

@ -36,34 +36,27 @@ export const useListDatasetGroups = () => {
export const useDeleteDatasetGroup = () => { export const useDeleteDatasetGroup = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const mutationFn = useMemoizedFn(async (id: string) => {
const res = await deleteDatasetGroup(id);
queryClient.invalidateQueries({
queryKey: queryKeys.datasetGroupsList.queryKey,
exact: true
});
return res;
});
return useMutation({ return useMutation({
mutationFn mutationFn: deleteDatasetGroup,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: queryKeys.datasetGroupsList.queryKey,
exact: true
});
}
}); });
}; };
export const useUpdateDatasetGroup = () => { export const useUpdateDatasetGroup = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const mutationFn = useMemoizedFn(async (data: Parameters<typeof updateDatasetGroup>[0]) => {
const res = await updateDatasetGroup(data);
queryClient.invalidateQueries({
queryKey: queryKeys.datasetGroupsList.queryKey,
exact: true
});
return res;
});
return useMutation({ return useMutation({
mutationFn mutationFn: updateDatasetGroup,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: queryKeys.datasetGroupsList.queryKey,
exact: true
});
}
}); });
}; };
@ -195,39 +188,34 @@ export const prefetchDatasetGroupPermissionGroups = async (
return queryClient; return queryClient;
}; };
export const useUpdateDatasetGroupUsers = (datasetGroupId: string) => { export const useUpdateDatasetGroupUsers = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const mutationFn = useMemoizedFn((data: { id: string; assigned: boolean }[]) => {
queryClient.setQueryData(
queryKeys.datasetGroupsGetUsers(datasetGroupId).queryKey,
(oldData: GetDatasetGroupUsersResponse[] | undefined) => {
if (!oldData) return [];
return oldData.map((user) => {
const userToUpdate = data.find((d) => d.id === user.id);
if (userToUpdate) {
return { ...user, assigned: userToUpdate.assigned };
}
return user;
});
}
);
return updateDatasetGroupUsers(datasetGroupId, data);
});
return useMutation({ return useMutation({
mutationFn mutationFn: updateDatasetGroupUsers,
onMutate: ({ data, datasetGroupId }) => {
queryClient.setQueryData(
queryKeys.datasetGroupsGetUsers(datasetGroupId).queryKey,
(oldData: GetDatasetGroupUsersResponse[] | undefined) => {
if (!oldData) return [];
return oldData.map((user) => {
const userToUpdate = data.find((d) => d.id === user.id);
if (userToUpdate) {
return { ...user, assigned: userToUpdate.assigned };
}
return user;
});
}
);
}
}); });
}; };
export const useUpdateDatasetGroupDatasets = () => { export const useUpdateDatasetGroupDatasets = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const mutationFn = useMemoizedFn(
({ return useMutation({
datasetGroupId, mutationFn: updateDatasetGroupDatasets,
groups onMutate: ({ groups, datasetGroupId }) => {
}: {
datasetGroupId: string;
groups: { id: string; assigned: boolean }[];
}) => {
queryClient.setQueryData( queryClient.setQueryData(
queryKeys.datasetGroupsGetDatasets(datasetGroupId).queryKey, queryKeys.datasetGroupsGetDatasets(datasetGroupId).queryKey,
(oldData: GetDatasetGroupDatasetsResponse[] | undefined) => { (oldData: GetDatasetGroupDatasetsResponse[] | undefined) => {
@ -241,33 +229,29 @@ export const useUpdateDatasetGroupDatasets = () => {
}); });
} }
); );
return updateDatasetGroupDatasets(datasetGroupId, groups);
} }
);
return useMutation({
mutationFn
}); });
}; };
export const useUpdateDatasetGroupPermissionGroups = (datasetGroupId: string) => { export const useUpdateDatasetGroupPermissionGroups = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const mutationFn = useMemoizedFn((data: { id: string; assigned: boolean }[]) => {
queryClient.setQueryData(
queryKeys.datasetGroupsGetPermissionGroups(datasetGroupId).queryKey,
(oldData: GetDatasetGroupPermissionGroupsResponse[] | undefined) => {
if (!oldData) return [];
return oldData.map((permissionGroup) => {
const permissionGroupToUpdate = data.find((d) => d.id === permissionGroup.id);
if (permissionGroupToUpdate) {
return { ...permissionGroup, assigned: permissionGroupToUpdate.assigned };
}
return permissionGroup;
});
}
);
return updateDatasetGroupPermissionGroups(datasetGroupId, data);
});
return useMutation({ return useMutation({
mutationFn mutationFn: updateDatasetGroupPermissionGroups,
onMutate: ({ data, datasetGroupId }) => {
queryClient.setQueryData(
queryKeys.datasetGroupsGetPermissionGroups(datasetGroupId).queryKey,
(oldData: GetDatasetGroupPermissionGroupsResponse[] | undefined) => {
if (!oldData) return [];
return oldData.map((permissionGroup) => {
const permissionGroupToUpdate = data.find((d) => d.id === permissionGroup.id);
if (permissionGroupToUpdate) {
return { ...permissionGroup, assigned: permissionGroupToUpdate.assigned };
}
return permissionGroup;
});
}
);
}
}); });
}; };

View File

@ -27,8 +27,8 @@ export const updateDatasetGroup = async (data: UpdateDatasetGroupRequest[]) => {
return mainApi.put(`/dataset_groups`, data).then((res) => res.data); return mainApi.put(`/dataset_groups`, data).then((res) => res.data);
}; };
export const deleteDatasetGroup = async (id: string) => { export const deleteDatasetGroup = async (ids: string[]) => {
return mainApi.delete(`/dataset_groups/${id}`).then((res) => res.data); return mainApi.delete(`/dataset_groups`, { data: { ids } }).then((res) => res.data);
}; };
export const getDatasetGroup = async (id: string) => { export const getDatasetGroup = async (id: string) => {
@ -71,20 +71,34 @@ export const getDatasetGroupPermissionGroups_server = async (id: string) => {
); );
}; };
export const updateDatasetGroupUsers = async (id: string, data: UpdateDatasetGroupUsersRequest) => { export const updateDatasetGroupUsers = async ({
return mainApi.put(`/dataset_groups/${id}/users`, data).then((res) => res.data); datasetGroupId,
data
}: {
datasetGroupId: string;
data: UpdateDatasetGroupUsersRequest;
}) => {
return mainApi.put(`/dataset_groups/${datasetGroupId}/users`, data).then((res) => res.data);
}; };
export const updateDatasetGroupDatasets = async ( export const updateDatasetGroupDatasets = async ({
id: string, datasetGroupId,
data: UpdateDatasetGroupDatasetsRequest groups
) => { }: {
return mainApi.put(`/dataset_groups/${id}/datasets`, data).then((res) => res.data); datasetGroupId: string;
groups: UpdateDatasetGroupDatasetsRequest;
}) => {
return mainApi.put(`/dataset_groups/${datasetGroupId}/datasets`, groups).then((res) => res.data);
}; };
export const updateDatasetGroupPermissionGroups = async ( export const updateDatasetGroupPermissionGroups = async ({
id: string, datasetGroupId,
data: UpdateDatasetGroupPermissionGroupsRequest data
) => { }: {
return mainApi.put(`/dataset_groups/${id}/permission_groups`, data).then((res) => res.data); datasetGroupId: string;
data: UpdateDatasetGroupPermissionGroupsRequest;
}) => {
return mainApi
.put(`/dataset_groups/${datasetGroupId}/permission_groups`, data)
.then((res) => res.data);
}; };

View File

@ -1,8 +1,4 @@
import { import { useUpdateDatasetGroupPermissionGroups } from '@/api/buster_rest';
updatePermissionGroupDatasetGroups,
useUpdateDatasetGroupPermissionGroups,
useUpdatePermissionGroupDatasetGroups
} from '@/api/buster_rest';
import { PermissionAssignedButton } from '@/components/features/PermissionComponents'; import { PermissionAssignedButton } from '@/components/features/PermissionComponents';
import { BusterListSelectedOptionPopupContainer } from '@/components/ui/list'; import { BusterListSelectedOptionPopupContainer } from '@/components/ui/list';
import { useMemoizedFn } from '@/hooks'; import { useMemoizedFn } from '@/hooks';
@ -13,11 +9,13 @@ export const DatasetGroupDatasetGroupSelectedPopup: React.FC<{
onSelectChange: (selectedRowKeys: string[]) => void; onSelectChange: (selectedRowKeys: string[]) => void;
datasetGroupId: string; datasetGroupId: string;
}> = React.memo(({ selectedRowKeys, onSelectChange, datasetGroupId }) => { }> = React.memo(({ selectedRowKeys, onSelectChange, datasetGroupId }) => {
const { mutateAsync: updateDatasetGroupDatasetGroups } = const { mutateAsync: updateDatasetGroupDatasetGroups } = useUpdateDatasetGroupPermissionGroups();
useUpdateDatasetGroupPermissionGroups(datasetGroupId);
const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }[]) => { const onSelectAssigned = useMemoizedFn(async (data: { id: string; assigned: boolean }[]) => {
await updateDatasetGroupDatasetGroups(params); await updateDatasetGroupDatasetGroups({
datasetGroupId,
data
});
}); });
return ( return (

View File

@ -23,11 +23,13 @@ export const DatasetGroupDatasetGroupsListContainer: React.FC<{
datasetGroupId: string; datasetGroupId: string;
}> = React.memo(({ filteredDatasetGroups, datasetGroupId }) => { }> = React.memo(({ filteredDatasetGroups, datasetGroupId }) => {
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]); const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
const { mutateAsync: updateDatasetGroupDatasetGroups } = const { mutateAsync: updateDatasetGroupDatasetGroups } = useUpdateDatasetGroupPermissionGroups();
useUpdateDatasetGroupPermissionGroups(datasetGroupId);
const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }) => { const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }) => {
await updateDatasetGroupDatasetGroups([params]); await updateDatasetGroupDatasetGroups({
datasetGroupId,
data: [params]
});
}); });
const columns: BusterListColumn[] = useMemo( const columns: BusterListColumn[] = useMemo(

View File

@ -24,10 +24,13 @@ export const DatasetGroupUsersListContainer: React.FC<{
datasetGroupId: string; datasetGroupId: string;
}> = React.memo(({ filteredUsers, datasetGroupId }) => { }> = React.memo(({ filteredUsers, datasetGroupId }) => {
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]); const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
const { mutateAsync: updateDatasetGroupUsers } = useUpdateDatasetGroupUsers(datasetGroupId); const { mutateAsync: updateDatasetGroupUsers } = useUpdateDatasetGroupUsers();
const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }) => { const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }) => {
await updateDatasetGroupUsers([params]); await updateDatasetGroupUsers({
datasetGroupId,
data: [params]
});
}); });
const columns: BusterListColumn[] = useMemo( const columns: BusterListColumn[] = useMemo(

View File

@ -1,10 +1,7 @@
import { import { useUpdateDatasetGroupUsers } from '@/api/buster_rest';
useUpdateDatasetGroupUsers,
useUpdatePermissionGroupUsers,
useUpdateUserDatasets
} from '@/api/buster_rest';
import { PermissionAssignedButton } from '@/components/features/PermissionComponents'; import { PermissionAssignedButton } from '@/components/features/PermissionComponents';
import { BusterListSelectedOptionPopupContainer } from '@/components/ui/list'; import { BusterListSelectedOptionPopupContainer } from '@/components/ui/list';
import { useMemoizedFn } from '@/hooks';
import React from 'react'; import React from 'react';
export const DatasetGroupUsersSelectedPopup: React.FC<{ export const DatasetGroupUsersSelectedPopup: React.FC<{
@ -12,7 +9,14 @@ export const DatasetGroupUsersSelectedPopup: React.FC<{
onSelectChange: (selectedRowKeys: string[]) => void; onSelectChange: (selectedRowKeys: string[]) => void;
datasetGroupId: string; datasetGroupId: string;
}> = React.memo(({ selectedRowKeys, onSelectChange, datasetGroupId }) => { }> = React.memo(({ selectedRowKeys, onSelectChange, datasetGroupId }) => {
const { mutateAsync: updateDatasetGroupUsers } = useUpdateDatasetGroupUsers(datasetGroupId); const { mutateAsync: updateDatasetGroupUsers } = useUpdateDatasetGroupUsers();
const onUpdate = useMemoizedFn(async (data: { id: string; assigned: boolean }[]) => {
await updateDatasetGroupUsers({
datasetGroupId,
data
});
});
return ( return (
<BusterListSelectedOptionPopupContainer <BusterListSelectedOptionPopupContainer
@ -24,7 +28,7 @@ export const DatasetGroupUsersSelectedPopup: React.FC<{
text="assigned" text="assigned"
selectedRowKeys={selectedRowKeys} selectedRowKeys={selectedRowKeys}
onSelectChange={onSelectChange} onSelectChange={onSelectChange}
onUpdate={updateDatasetGroupUsers} onUpdate={onUpdate}
/> />
]} ]}
/> />