-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend/rest): add batch actions for workflows
- Loading branch information
Showing
16 changed files
with
942 additions
and
143 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
frontend/src/features/myWorkflows/api/runs/useStartRuns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { type MutationConfig } from "@services/clients/react-query.client"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { type AxiosError } from "axios"; | ||
import { type IBatchWorkflowActionResponse } from "features/myWorkflows/types/workflow"; | ||
import { toast } from "react-toastify"; | ||
import { dominoApiClient } from "services/clients/domino.client"; | ||
|
||
interface StartRunsParams { | ||
workflowIds: number[]; | ||
} | ||
|
||
interface UseStartRuns { | ||
workspaceId?: string; | ||
} | ||
|
||
export const useStartRuns = ( | ||
{ workspaceId }: UseStartRuns, | ||
config: MutationConfig<StartRunsParams, IBatchWorkflowActionResponse> = {}, | ||
) => { | ||
return useMutation({ | ||
mutationFn: async ({ workflowIds }) => { | ||
if (!workflowIds) throw new Error("No workflow selected"); | ||
return await postWorkflowRunIds({ workflowIds, workspaceId }); | ||
}, | ||
onError: (e: AxiosError<{ detail: string }>) => { | ||
const message = | ||
(e.response?.data?.detail ?? e?.message) || "Something went wrong"; | ||
|
||
toast.error(message, { | ||
toastId: message, | ||
}); | ||
}, | ||
...config, | ||
}); | ||
}; | ||
|
||
const postWorkflowRunIds = async ({ | ||
workflowIds, | ||
workspaceId, | ||
}: StartRunsParams & UseStartRuns): Promise<IBatchWorkflowActionResponse> => { | ||
return await dominoApiClient.post( | ||
`/batch/workspaces/${workspaceId}/workflows/runs`, | ||
workflowIds, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { type MutationConfig } from "@services/clients/react-query.client"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { type AxiosError } from "axios"; | ||
import { type IBatchWorkflowActionResponse } from "features/myWorkflows/types/workflow"; | ||
import { toast } from "react-toastify"; | ||
import { dominoApiClient } from "services/clients/domino.client"; | ||
|
||
interface StopRunsParams { | ||
workflowIds: number[]; | ||
} | ||
|
||
interface UseStopRuns { | ||
workspaceId?: string; | ||
} | ||
|
||
export const useStopRuns = ( | ||
{ workspaceId }: UseStopRuns, | ||
config: MutationConfig<StopRunsParams, IBatchWorkflowActionResponse> = {}, | ||
) => { | ||
return useMutation({ | ||
mutationFn: async ({ workflowIds }) => { | ||
if (!workflowIds) throw new Error("No workflow selected"); | ||
return await postWorkflowStopIds({ workflowIds, workspaceId }); | ||
}, | ||
onError: (e: AxiosError<{ detail: string }>) => { | ||
const message = | ||
(e.response?.data?.detail ?? e?.message) || "Something went wrong"; | ||
|
||
toast.error(message, { | ||
toastId: message, | ||
}); | ||
}, | ||
...config, | ||
}); | ||
}; | ||
|
||
const postWorkflowStopIds = async ({ | ||
workflowIds, | ||
workspaceId, | ||
}: StopRunsParams & UseStopRuns): Promise<IBatchWorkflowActionResponse> => { | ||
return await dominoApiClient.patch( | ||
`/batch/workspaces/${workspaceId}/workflows/runs`, | ||
workflowIds, | ||
); | ||
}; |
59 changes: 59 additions & 0 deletions
59
frontend/src/features/myWorkflows/api/workflow/useDeleteWorkflows.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { type MutationConfig } from "@services/clients/react-query.client"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { type AxiosError } from "axios"; | ||
import { type IBatchWorkflowActionResponse } from "features/myWorkflows/types/workflow"; | ||
import { toast } from "react-toastify"; | ||
import { dominoApiClient } from "services/clients/domino.client"; | ||
|
||
interface DeleteWorkflowsParams { | ||
workflowIds: number[]; | ||
} | ||
|
||
interface UseDeleteWorkflows { | ||
workspaceId?: string; | ||
} | ||
|
||
export const useDeleteWorkflows = ( | ||
{ workspaceId }: UseDeleteWorkflows, | ||
config: MutationConfig< | ||
DeleteWorkflowsParams, | ||
IBatchWorkflowActionResponse | ||
> = {}, | ||
) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: async ({ workflowIds }) => { | ||
if (!workspaceId) throw new Error("No workspace selected"); | ||
return await deleteWorkflowByIds({ workflowIds, workspaceId }); | ||
}, | ||
onSuccess: async (_, { workflowIds }) => { | ||
await queryClient.invalidateQueries({ | ||
queryKey: ["WORKFLOWS", workspaceId], | ||
}); | ||
await queryClient.invalidateQueries({ | ||
queryKey: ["WORKFLOW", workspaceId, workflowIds], | ||
}); | ||
}, | ||
onError: (e: AxiosError<{ detail: string }>) => { | ||
const message = | ||
(e.response?.data?.detail ?? e?.message) || "Something went wrong"; | ||
|
||
toast.error(message, { | ||
toastId: message, | ||
}); | ||
}, | ||
...config, | ||
}); | ||
}; | ||
|
||
const deleteWorkflowByIds = async ( | ||
params: DeleteWorkflowsParams & UseDeleteWorkflows, | ||
): Promise<IBatchWorkflowActionResponse> => { | ||
return await dominoApiClient.delete( | ||
`/batch/workspaces/${params.workspaceId}/workflows`, | ||
{ | ||
data: params.workflowIds, | ||
}, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
frontend/src/features/myWorkflows/components/WorkflowsList/FailureDetailsModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { type IBatchWorkflowActionDetail } from "@features/myWorkflows/types"; | ||
import { Dialog, DialogContent, DialogTitle } from "@mui/material"; | ||
import { DataGrid, type GridColDef } from "@mui/x-data-grid"; | ||
import { useCallback } from "react"; | ||
|
||
interface Props { | ||
isOpen: boolean; | ||
title: string; | ||
data: IBatchWorkflowActionDetail[]; | ||
cancelCb: () => void; | ||
} | ||
|
||
const columns: Array<GridColDef<IBatchWorkflowActionDetail>> = [ | ||
{ field: "id", headerName: "ID", width: 90 }, | ||
{ | ||
field: "message", | ||
headerName: "Message", | ||
width: 400, | ||
}, | ||
]; | ||
|
||
export const FailureDetailsModal: React.FC<Props> = ({ | ||
isOpen, | ||
title, | ||
data, | ||
cancelCb, | ||
}) => { | ||
const cancel = useCallback(() => { | ||
cancelCb(); | ||
}, [cancelCb]); | ||
return ( | ||
<Dialog | ||
open={isOpen} | ||
onClose={cancel} | ||
aria-labelledby="alert-dialog-title" | ||
aria-describedby="alert-dialog-description" | ||
> | ||
<DialogTitle id="alert-dialog-title">{title}</DialogTitle> | ||
<DialogContent> | ||
<DataGrid | ||
density="compact" | ||
columns={columns} | ||
rows={data} | ||
disableDensitySelector | ||
disableRowSelectionOnClick | ||
hideFooterSelectedRowCount | ||
disableColumnMenu | ||
disableColumnSelector | ||
/> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
Oops, something went wrong.