-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added clone workflow definition button (#2594)
* feat: added clone workflow definition button * feat: added clone button to workflows table
- Loading branch information
1 parent
504e1b6
commit 97bc6fa
Showing
12 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
.../src/components/molecules/CloneWorkflowDefinitionButton/CloneWorkflowDefinitionButton.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,51 @@ | ||
import { Button } from '@/components/atoms/Button'; | ||
import { Dialog, DialogContent, DialogTrigger } from '@/components/atoms/Dialog'; | ||
import { | ||
formSchema, | ||
uiSchema, | ||
} from '@/components/molecules/CloneWorkflowDefinitionButton/form-schema'; | ||
import { useCloneWorkflowDefinitionMutation } from '@/pages/WorkflowDefinitions/hooks/useCloneWorkflowDefinitionMutation'; | ||
import { DynamicForm } from '@ballerine/ui'; | ||
import { FunctionComponent, useCallback, useEffect, useState } from 'react'; | ||
|
||
interface ICloneWorkflowDefinitionButtonProps { | ||
workflowDefinitionId: string; | ||
} | ||
|
||
export const CloneWorkflowDefinitionButton: FunctionComponent< | ||
ICloneWorkflowDefinitionButtonProps | ||
> = ({ workflowDefinitionId }) => { | ||
const [isDialogOpen, setIsDialogOpen] = useState(false); | ||
const { mutate, isLoading, isSuccess } = useCloneWorkflowDefinitionMutation(); | ||
|
||
const handleSubmit = useCallback( | ||
async (formData: Record<string, any>) => { | ||
const values: { name: string; displayName: string } = formData as any; | ||
|
||
mutate({ workflowDefinitionId, ...values }); | ||
}, | ||
[workflowDefinitionId, mutate], | ||
); | ||
|
||
useEffect(() => { | ||
if (isSuccess) { | ||
setIsDialogOpen(false); | ||
} | ||
}, [isSuccess]); | ||
|
||
return ( | ||
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}> | ||
<DialogTrigger asChild> | ||
<Button>Clone</Button> | ||
</DialogTrigger> | ||
<DialogContent> | ||
<DynamicForm | ||
schema={formSchema} | ||
uiSchema={uiSchema} | ||
disabled={isLoading} | ||
onSubmit={handleSubmit} | ||
/> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
...workflows-dashboard/src/components/molecules/CloneWorkflowDefinitionButton/form-schema.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,25 @@ | ||
import { RJSFSchema, UiSchema } from '@rjsf/utils'; | ||
|
||
export const formSchema: RJSFSchema = { | ||
type: 'object', | ||
required: ['name', 'displayName'], | ||
properties: { | ||
name: { | ||
type: 'string', | ||
}, | ||
displayName: { | ||
type: 'string', | ||
}, | ||
}, | ||
}; | ||
|
||
export const uiSchema: UiSchema = { | ||
name: { | ||
'ui:placeholder': 'ballerine', | ||
'ui:label': 'Name', | ||
}, | ||
displayName: { | ||
'ui:placeholder': 'Ballerine', | ||
'ui:label': 'Display Name', | ||
}, | ||
}; |
1 change: 1 addition & 0 deletions
1
apps/workflows-dashboard/src/components/molecules/CloneWorkflowDefinitionButton/index.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 @@ | ||
export * from './CloneWorkflowDefinitionButton'; |
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
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
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
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
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
1 change: 1 addition & 0 deletions
1
...dashboard/src/pages/WorkflowDefinitions/hooks/useCloneWorkflowDefinitionMutation/index.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 @@ | ||
export * from './useCloneWorkflowDefinitionMutation'; |
21 changes: 21 additions & 0 deletions
21
...efinitions/hooks/useCloneWorkflowDefinitionMutation/useCloneWorkflowDefinitionMutation.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,21 @@ | ||
import { | ||
cloneWorkflowDefinitionById, | ||
CloneWorkflowDefinitionByIdDto, | ||
} from '@/domains/workflow-definitions'; | ||
import { queryClient } from '@/lib/react-query/query-client'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { toast } from 'sonner'; | ||
|
||
export const useCloneWorkflowDefinitionMutation = () => { | ||
return useMutation({ | ||
mutationFn: async (dto: CloneWorkflowDefinitionByIdDto) => cloneWorkflowDefinitionById(dto), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ['workflowDefinitions'] }); | ||
|
||
toast.success('Workflow Definition cloned succesfully.'); | ||
}, | ||
onError: () => { | ||
toast.error('Failed to clone Workflow Definition.'); | ||
}, | ||
}); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.