mirror of https://github.com/buster-so/buster.git
update dataset groups
This commit is contained in:
parent
2d2396c0bf
commit
3fbd22b250
|
@ -36,34 +36,27 @@ export const useListDatasetGroups = () => {
|
|||
|
||||
export const useDeleteDatasetGroup = () => {
|
||||
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({
|
||||
mutationFn
|
||||
mutationFn: deleteDatasetGroup,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.datasetGroupsList.queryKey,
|
||||
exact: true
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateDatasetGroup = () => {
|
||||
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({
|
||||
mutationFn
|
||||
mutationFn: updateDatasetGroup,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.datasetGroupsList.queryKey,
|
||||
exact: true
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -195,39 +188,34 @@ export const prefetchDatasetGroupPermissionGroups = async (
|
|||
return queryClient;
|
||||
};
|
||||
|
||||
export const useUpdateDatasetGroupUsers = (datasetGroupId: string) => {
|
||||
export const useUpdateDatasetGroupUsers = () => {
|
||||
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({
|
||||
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 = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const mutationFn = useMemoizedFn(
|
||||
({
|
||||
datasetGroupId,
|
||||
groups
|
||||
}: {
|
||||
datasetGroupId: string;
|
||||
groups: { id: string; assigned: boolean }[];
|
||||
}) => {
|
||||
|
||||
return useMutation({
|
||||
mutationFn: updateDatasetGroupDatasets,
|
||||
onMutate: ({ groups, datasetGroupId }) => {
|
||||
queryClient.setQueryData(
|
||||
queryKeys.datasetGroupsGetDatasets(datasetGroupId).queryKey,
|
||||
(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 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({
|
||||
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;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -27,8 +27,8 @@ export const updateDatasetGroup = async (data: UpdateDatasetGroupRequest[]) => {
|
|||
return mainApi.put(`/dataset_groups`, data).then((res) => res.data);
|
||||
};
|
||||
|
||||
export const deleteDatasetGroup = async (id: string) => {
|
||||
return mainApi.delete(`/dataset_groups/${id}`).then((res) => res.data);
|
||||
export const deleteDatasetGroup = async (ids: string[]) => {
|
||||
return mainApi.delete(`/dataset_groups`, { data: { ids } }).then((res) => res.data);
|
||||
};
|
||||
|
||||
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) => {
|
||||
return mainApi.put(`/dataset_groups/${id}/users`, data).then((res) => res.data);
|
||||
export const updateDatasetGroupUsers = async ({
|
||||
datasetGroupId,
|
||||
data
|
||||
}: {
|
||||
datasetGroupId: string;
|
||||
data: UpdateDatasetGroupUsersRequest;
|
||||
}) => {
|
||||
return mainApi.put(`/dataset_groups/${datasetGroupId}/users`, data).then((res) => res.data);
|
||||
};
|
||||
|
||||
export const updateDatasetGroupDatasets = async (
|
||||
id: string,
|
||||
data: UpdateDatasetGroupDatasetsRequest
|
||||
) => {
|
||||
return mainApi.put(`/dataset_groups/${id}/datasets`, data).then((res) => res.data);
|
||||
export const updateDatasetGroupDatasets = async ({
|
||||
datasetGroupId,
|
||||
groups
|
||||
}: {
|
||||
datasetGroupId: string;
|
||||
groups: UpdateDatasetGroupDatasetsRequest;
|
||||
}) => {
|
||||
return mainApi.put(`/dataset_groups/${datasetGroupId}/datasets`, groups).then((res) => res.data);
|
||||
};
|
||||
|
||||
export const updateDatasetGroupPermissionGroups = async (
|
||||
id: string,
|
||||
data: UpdateDatasetGroupPermissionGroupsRequest
|
||||
) => {
|
||||
return mainApi.put(`/dataset_groups/${id}/permission_groups`, data).then((res) => res.data);
|
||||
export const updateDatasetGroupPermissionGroups = async ({
|
||||
datasetGroupId,
|
||||
data
|
||||
}: {
|
||||
datasetGroupId: string;
|
||||
data: UpdateDatasetGroupPermissionGroupsRequest;
|
||||
}) => {
|
||||
return mainApi
|
||||
.put(`/dataset_groups/${datasetGroupId}/permission_groups`, data)
|
||||
.then((res) => res.data);
|
||||
};
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
import {
|
||||
updatePermissionGroupDatasetGroups,
|
||||
useUpdateDatasetGroupPermissionGroups,
|
||||
useUpdatePermissionGroupDatasetGroups
|
||||
} from '@/api/buster_rest';
|
||||
import { useUpdateDatasetGroupPermissionGroups } from '@/api/buster_rest';
|
||||
import { PermissionAssignedButton } from '@/components/features/PermissionComponents';
|
||||
import { BusterListSelectedOptionPopupContainer } from '@/components/ui/list';
|
||||
import { useMemoizedFn } from '@/hooks';
|
||||
|
@ -13,11 +9,13 @@ export const DatasetGroupDatasetGroupSelectedPopup: React.FC<{
|
|||
onSelectChange: (selectedRowKeys: string[]) => void;
|
||||
datasetGroupId: string;
|
||||
}> = React.memo(({ selectedRowKeys, onSelectChange, datasetGroupId }) => {
|
||||
const { mutateAsync: updateDatasetGroupDatasetGroups } =
|
||||
useUpdateDatasetGroupPermissionGroups(datasetGroupId);
|
||||
const { mutateAsync: updateDatasetGroupDatasetGroups } = useUpdateDatasetGroupPermissionGroups();
|
||||
|
||||
const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }[]) => {
|
||||
await updateDatasetGroupDatasetGroups(params);
|
||||
const onSelectAssigned = useMemoizedFn(async (data: { id: string; assigned: boolean }[]) => {
|
||||
await updateDatasetGroupDatasetGroups({
|
||||
datasetGroupId,
|
||||
data
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
|
|
|
@ -23,11 +23,13 @@ export const DatasetGroupDatasetGroupsListContainer: React.FC<{
|
|||
datasetGroupId: string;
|
||||
}> = React.memo(({ filteredDatasetGroups, datasetGroupId }) => {
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
||||
const { mutateAsync: updateDatasetGroupDatasetGroups } =
|
||||
useUpdateDatasetGroupPermissionGroups(datasetGroupId);
|
||||
const { mutateAsync: updateDatasetGroupDatasetGroups } = useUpdateDatasetGroupPermissionGroups();
|
||||
|
||||
const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }) => {
|
||||
await updateDatasetGroupDatasetGroups([params]);
|
||||
await updateDatasetGroupDatasetGroups({
|
||||
datasetGroupId,
|
||||
data: [params]
|
||||
});
|
||||
});
|
||||
|
||||
const columns: BusterListColumn[] = useMemo(
|
||||
|
|
|
@ -24,10 +24,13 @@ export const DatasetGroupUsersListContainer: React.FC<{
|
|||
datasetGroupId: string;
|
||||
}> = React.memo(({ filteredUsers, datasetGroupId }) => {
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
||||
const { mutateAsync: updateDatasetGroupUsers } = useUpdateDatasetGroupUsers(datasetGroupId);
|
||||
const { mutateAsync: updateDatasetGroupUsers } = useUpdateDatasetGroupUsers();
|
||||
|
||||
const onSelectAssigned = useMemoizedFn(async (params: { id: string; assigned: boolean }) => {
|
||||
await updateDatasetGroupUsers([params]);
|
||||
await updateDatasetGroupUsers({
|
||||
datasetGroupId,
|
||||
data: [params]
|
||||
});
|
||||
});
|
||||
|
||||
const columns: BusterListColumn[] = useMemo(
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
import {
|
||||
useUpdateDatasetGroupUsers,
|
||||
useUpdatePermissionGroupUsers,
|
||||
useUpdateUserDatasets
|
||||
} from '@/api/buster_rest';
|
||||
import { useUpdateDatasetGroupUsers } from '@/api/buster_rest';
|
||||
import { PermissionAssignedButton } from '@/components/features/PermissionComponents';
|
||||
import { BusterListSelectedOptionPopupContainer } from '@/components/ui/list';
|
||||
import { useMemoizedFn } from '@/hooks';
|
||||
import React from 'react';
|
||||
|
||||
export const DatasetGroupUsersSelectedPopup: React.FC<{
|
||||
|
@ -12,7 +9,14 @@ export const DatasetGroupUsersSelectedPopup: React.FC<{
|
|||
onSelectChange: (selectedRowKeys: string[]) => void;
|
||||
datasetGroupId: string;
|
||||
}> = 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 (
|
||||
<BusterListSelectedOptionPopupContainer
|
||||
|
@ -24,7 +28,7 @@ export const DatasetGroupUsersSelectedPopup: React.FC<{
|
|||
text="assigned"
|
||||
selectedRowKeys={selectedRowKeys}
|
||||
onSelectChange={onSelectChange}
|
||||
onUpdate={updateDatasetGroupUsers}
|
||||
onUpdate={onUpdate}
|
||||
/>
|
||||
]}
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue