Skip to content

Commit

Permalink
feat: create from shared base
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Oct 9, 2024
1 parent f03c7b5 commit f26eb0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
<form method="POST" use:enhance>
<Card.Root class="mx-auto">
<Card.Header>
<Card.Title class="text-2xl">Create from template</Card.Title>
<Card.Description>Create a new base from a template.</Card.Description>
<Card.Title class="text-2xl">Create from share</Card.Title>
<Card.Description>Create a new base from a shared base.</Card.Description>
</Card.Header>
<Card.Content>
<div class="grid gap-2">
Expand Down
10 changes: 3 additions & 7 deletions apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import type { PaneAPI } from "paneforge"
import type { LayoutData } from "./$types"
import Logo from "$lib/images/logo.svg"
import { Button } from "$lib/components/ui/button"
import { page } from "$app/stores"
export let data: LayoutData
Expand Down Expand Up @@ -34,13 +36,7 @@
<span class="font-bold"> Undb </span>
</a>

<!-- <button on:click={() => (collapsed = !collapsed)}>
{#if collapsed}
<PanelLeftOpenIcon class="h-5 w-5" />
{:else}
<PanelLeftCloseIcon class="h-5 w-5" />
{/if}
</button> -->
<Button href={`/create-from-share/${$page.params.shareId}`} size="sm">Use this template</Button>
</div>
<div class="w-full flex-1 overflow-y-auto">
<ShareBaseNav {base} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { type ICommandHandler } from "@undb/domain"
import { createLogger } from "@undb/logger"
import { injectShareRepository, WithShareId, type IShareRepository } from "@undb/share"
import { injectTableService, type ITableService } from "@undb/table"
import { getNextName } from "@undb/utils"

@commandHandler(CreateFromShareCommand)
@singleton()
Expand Down Expand Up @@ -44,12 +45,15 @@ export class CreateFromShareCommandHandler implements ICommandHandler<CreateFrom
const member = (await this.spaceMemberService.getSpaceMember(userId, targetSpaceId)).expect("Member not found")
checkPermission(member.props.role, ["base:create"])

const bases = await this.baseRepository.find(new WithBaseSpaceId(spaceId))
const baseNames = bases.map((base) => base.name.value)

const spec = new WithBaseId(new BaseId(baseId)).and(new WithBaseSpaceId(spaceId))
const base = (await this.baseRepository.findOne(spec)).expect("Base not found")

const duplicatedBase = await this.tableService.duplicateBase(base, spaceId, targetSpaceId, {
id: baseId,
name: command.name,
name: getNextName(baseNames, command.name),
includeData: command.includeData,
})

Expand Down

0 comments on commit f26eb0f

Please sign in to comment.