Skip to content

Commit

Permalink
feat(web/library): Bulk actions connected to API
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Oct 9, 2023
1 parent 23d5b25 commit 1a0f08f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 12 additions & 0 deletions frontend/web/layouts/library/LibraryWorkflowTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,24 @@ const LibraryWorkflowTable = () => {
}
};

const updateAllWorkflows = async () => {
const fetchedWorkflows = await services.workflows.getAll();
if (fetchedWorkflows.error || fetchedWorkflows.data === null) return;

setWorkflows(fetchedWorkflows.data);

const fetchedWorkflowIds = fetchedWorkflows.data.map((workflow) => workflow.id);
setSelectedWorkflows((prev) => prev.filter((workflowId) => fetchedWorkflowIds.includes(workflowId)));
};

const onToggleAll = async (status: boolean) => {
await services.workflows.toggleBulk(selectedWorkflows, status);
await updateAllWorkflows();
};

const onDeleteAll = async () => {
await services.workflows.deleteBulk(selectedWorkflows);
await updateAllWorkflows();
};

const onWorkflowChange = async (workflowId: string) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/services/workflows/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const deleteOne = async (workflowId: string): Promise<ServiceReturn<void>

export const deleteBulk = async (workflowIds: string[]): Promise<ServiceReturn<void>> => {
try {
const response = await axiosInstance.delete<void>(`/workflows/bulk}`, { data: { workflows: workflowIds } });
const response = await axiosInstance.delete<void>(`/workflows/bulk`, { data: { workflows: workflowIds } });
return { data: response.data, error: undefined };
} catch (error) {
return { data: null, error: SERVICE_ERROR_UNKNOWN };
Expand Down
10 changes: 4 additions & 6 deletions frontend/web/services/workflows/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ToggleWorkflowReturn = {
export const toggleOne = async (workflowId: string, active: boolean): Promise<ServiceReturn<ToggleWorkflowReturn>> => {
try {
const response = await axiosInstance.patch<ToggleWorkflowReturn>(`/workflows/toggle/${workflowId}`, {
data: { newState: active },
newState: active,
});
return { data: response.data, error: undefined };
} catch (error) {
Expand All @@ -18,11 +18,9 @@ export const toggleOne = async (workflowId: string, active: boolean): Promise<Se

export const toggleBulk = async (workflowIds: string[], active: boolean): Promise<ServiceReturn<void>> => {
try {
const response = await axiosInstance.patch<void>(`/workflows/toggle/bulk}`, {
data: {
workflows: workflowIds,
newState: active,
},
const response = await axiosInstance.patch<void>(`/workflows/toggle/bulk`, {
workflows: workflowIds,
newState: active,
});
return { data: response.data, error: undefined };
} catch (error) {
Expand Down

0 comments on commit 1a0f08f

Please sign in to comment.