-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
315 additions
and
53 deletions.
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
65 changes: 65 additions & 0 deletions
65
apps/frontend/src/lib/components/blocks/duplicate-table/duplicate-table.svelte
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,65 @@ | ||
<script lang="ts"> | ||
import { goto, invalidateAll } from "$app/navigation" | ||
import Button from "$lib/components/ui/button/button.svelte" | ||
import * as Dialog from "$lib/components/ui/dialog" | ||
import { closeModal, DUPLICATE_TABLE_MODAL, isModalOpen } from "$lib/store/modal.store" | ||
import { trpc } from "$lib/trpc/client" | ||
import { createMutation } from "@tanstack/svelte-query" | ||
import type { TableDo } from "@undb/table" | ||
import { LoaderCircleIcon } from "lucide-svelte" | ||
import { toast } from "svelte-sonner" | ||
export let table: TableDo | ||
const duplicateTableMutation = createMutation({ | ||
mutationFn: trpc.table.duplicate.mutate, | ||
onSuccess: async (data) => { | ||
await invalidateAll() | ||
closeModal(DUPLICATE_TABLE_MODAL) | ||
await goto(`/t/${data}`) | ||
}, | ||
onError: (error) => { | ||
toast.error(error.message) | ||
}, | ||
}) | ||
</script> | ||
|
||
<Dialog.Root | ||
open={$isModalOpen(DUPLICATE_TABLE_MODAL)} | ||
onOpenChange={(open) => { | ||
if (!open) { | ||
closeModal(DUPLICATE_TABLE_MODAL) | ||
} | ||
}} | ||
> | ||
<Dialog.Content> | ||
<Dialog.Header> | ||
<Dialog.Title>Duplicate Table {table.name.value}</Dialog.Title> | ||
<Dialog.Description> | ||
Create a new table with the same structure as {table.name.value} | ||
</Dialog.Description> | ||
</Dialog.Header> | ||
|
||
<div class="item-center flex justify-end gap-2"> | ||
<Button | ||
on:click={() => { | ||
closeModal(DUPLICATE_TABLE_MODAL) | ||
}} | ||
variant="outline" | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
disabled={$duplicateTableMutation.isPending} | ||
on:click={() => { | ||
$duplicateTableMutation.mutate({ tableId: table.id.value }) | ||
}} | ||
> | ||
{#if $duplicateTableMutation.isPending} | ||
<LoaderCircleIcon class="mr-2 h-5 w-5 animate-spin" /> | ||
{/if} | ||
Duplicate | ||
</Button> | ||
</div> | ||
</Dialog.Content> | ||
</Dialog.Root> |
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
20 changes: 20 additions & 0 deletions
20
packages/command-handlers/src/handlers/duplicate-table.command-handler.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,20 @@ | ||
import { DuplicateTableCommand } from "@undb/commands" | ||
import { commandHandler } from "@undb/cqrs" | ||
import { singleton } from "@undb/di" | ||
import type { ICommandHandler } from "@undb/domain" | ||
import { injectTableService, type ITableService } from "@undb/table" | ||
|
||
@commandHandler(DuplicateTableCommand) | ||
@singleton() | ||
export class DuplicateTableCommandHandler implements ICommandHandler<DuplicateTableCommand, any> { | ||
constructor( | ||
@injectTableService() | ||
private readonly service: ITableService, | ||
) {} | ||
|
||
async execute(command: DuplicateTableCommand): Promise<any> { | ||
const table = await this.service.duplicateTable(command.input) | ||
|
||
return table.id.value | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Command, type CommandProps } from "@undb/domain" | ||
import { duplicateTableDTO, type IDuplicateTableDTO } from "@undb/table" | ||
import { z } from "@undb/zod" | ||
|
||
export const duplicateTableCommand = duplicateTableDTO | ||
|
||
export type IDuplicateTableCommand = z.infer<typeof duplicateTableCommand> | ||
|
||
export class DuplicateTableCommand extends Command { | ||
public readonly input: IDuplicateTableDTO | ||
|
||
constructor(props: CommandProps<IDuplicateTableDTO>) { | ||
super(props) | ||
this.input = props | ||
} | ||
} |
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
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
Oops, something went wrong.