Skip to content

Commit

Permalink
feat: added clone definition button & controller (#2593)
Browse files Browse the repository at this point in the history
  • Loading branch information
chesterkmr committed Jul 31, 2024
1 parent f303f89 commit 504e1b6
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CopyUIDefinitionDto,
GetUIDefinitionByIdDto,
IUIDefinition,
UpdateUIDefinitionDto,
Expand All @@ -19,6 +20,10 @@ export const updateUIDefinition = async (dto: UpdateUIDefinitionDto) => {
return result.data;
};

export const copyUIDefinition = async (dto: CopyUIDefinitionDto) => {
const result = await request.post(`/ui-definition/${dto.uiDefinitionId}/copy`);
};

export const fetchUIDefinition = async (dto: GetUIDefinitionByIdDto) => {
const result = await request.get<IUIDefinition>(`/internal/ui-definition/${dto.uiDefinitionId}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface UpdateUIDefinitionDto {
uiDefinition: IUIDefinition;
}

export interface CopyUIDefinitionDto {
uiDefinitionId: string;
}
export interface GetUIDefinitionByIdDto {
uiDefinitionId: string;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JSONViewButton } from '@/components/molecules/JSONViewButton';
import { IUIDefinition } from '@/domains/ui-definitions';
import { CloneUIDefinitionButton } from '@/pages/UIDefinitions/components/UIDefinitionsTable/components/CloneUIDefinitionButton';
import { formatDate } from '@/utils/format-date';
import { createColumnHelper } from '@tanstack/react-table';
import { ArrowRightCircleIcon, Eye } from 'lucide-react';
Expand Down Expand Up @@ -62,6 +63,10 @@ export const uiDefinitionTableColumnns = [
cell: info => formatDate(info.getValue<Date>()),
header: () => 'Created At',
}),
columnHelper.accessor('id', {
cell: info => <CloneUIDefinitionButton uiDefinitionId={info.getValue()} />,
header: () => '',
}),
columnHelper.accessor('id', {
cell: info => (
<Link to={`/ui-definitions/${info.row.original.id}`}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Button } from '@/components/atoms/Button';
import { useCloneUIDefinitionMutation } from '@/pages/UIDefinitions/hooks/useCloneUIDefinitionMutation';
import { FunctionComponent } from 'react';

interface ICLoneUIDefinitionButtonProps {
uiDefinitionId: string;
}

export const CloneUIDefinitionButton: FunctionComponent<ICLoneUIDefinitionButtonProps> = ({
uiDefinitionId,
}) => {
const { mutate, isLoading } = useCloneUIDefinitionMutation();

return (
<Button onClick={() => mutate({ uiDefinitionId })} disabled={isLoading}>
Clone
</Button>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CloneUIDefinitionButton';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useCloneUIDefinitionMutation';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
copyUIDefinition,
CopyUIDefinitionDto,
uiDefinitionsQueryKeys,
} from '@/domains/ui-definitions';
import { queryClient } from '@/lib/react-query/query-client';
import { useMutation } from '@tanstack/react-query';
import { toast } from 'sonner';

export const useCloneUIDefinitionMutation = () => {
return useMutation({
mutationFn: async (dto: CopyUIDefinitionDto) => copyUIDefinition(dto),
onSuccess: () => {
const { queryKey } = uiDefinitionsQueryKeys.list();

queryClient.invalidateQueries({ queryKey, exact: true });

toast.success('UI Definition cloned succesfully.');
},
onError: () => {
toast.error('Failed to clone ui definition.');
},
});
};
108 changes: 54 additions & 54 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from '@sinclair/typebox';
import { IsString } from 'class-validator';

export class UIDefinitionWhereUniqueInput {
@ApiProperty({
required: true,
type: String,
})
@IsString()
id!: string;
}

export const UIDefinitionWhereUniqueInputSchema = Type.String({
description: "The workflow's id",
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as swagger from '@nestjs/swagger';
@swagger.ApiExcludeController()
@common.Controller('internal/ui-definition')
@Injectable()
export class UiDefinitionController {
export class UiDefinitionControllerInternal {
constructor(
protected readonly service: UiDefinitionService,
protected readonly projectScopeService: ProjectScopeService,
Expand Down
Loading

0 comments on commit 504e1b6

Please sign in to comment.