Skip to content

Commit

Permalink
Merge pull request #1889 from undb-io/release/v1.0.0-16
Browse files Browse the repository at this point in the history
Release version v1.0.0-16
  • Loading branch information
nichenqin authored Aug 16, 2024
2 parents 2cd3d1a + 1ecd079 commit 4cbacaf
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 18 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog


## v1.0.0-16


### 🩹 Fixes

- Fix duplicate table bugs ([1d15a68](https://github.com/undb-io/undb/commit/1d15a68))

### ❤️ Contributors

- Nichenqin ([@nichenqin](http://github.com/nichenqin))

## v1.0.0-15


Expand Down
21 changes: 12 additions & 9 deletions apps/frontend/src/lib/components/blocks/base/duplicate-base.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import { createMutation } from "@tanstack/svelte-query"
import type { Base, IBaseDTO } from "@undb/base"
import { duplicateBaseCommand } from "@undb/commands"
import { LoaderCircleIcon } from "lucide-svelte"
import { LoaderCircleIcon, SirenIcon } from "lucide-svelte"
import { toast } from "svelte-sonner"
import { defaults, superForm } from "sveltekit-superforms"
import { zodClient } from "sveltekit-superforms/adapters"
import { Checkbox } from "$lib/components/ui/checkbox"
import * as Alert from "$lib/components/ui/alert"
export let base: Omit<IBaseDTO, "spaceId">
Expand Down Expand Up @@ -71,7 +72,7 @@
<Dialog.Description>Create a new base include all tables in base.</Dialog.Description>
</Dialog.Header>

<form method="POST" use:enhance>
<form method="POST" use:enhance class="space-y-4">
<Form.Field {form} name="name">
<Form.Control let:attrs>
<Form.Label>Name</Form.Label>
Expand All @@ -91,7 +92,14 @@
</Form.Control>
</Form.Field>

<div class="mt-4 flex items-center justify-end gap-2">
<Alert.Root>
<Alert.Description class="flex items-center text-xs">
<SirenIcon class="mr-2 h-4 w-4" />
System fields will be updated to the current user and timestamp.
</Alert.Description>
</Alert.Root>

<div class=" flex items-center justify-end gap-2">
<Button
on:click={() => {
closeModal(DUPLICATE_BASE_MODAL)
Expand All @@ -100,12 +108,7 @@
>
Cancel
</Button>
<Form.Button
disabled={$duplicateBaseMutation.isPending}
on:click={() => {
$duplicateBaseMutation.mutate({ id: base.id })
}}
>
<Form.Button disabled={$duplicateBaseMutation.isPending}>
{#if $duplicateBaseMutation.isPending}
<LoaderCircleIcon class="mr-2 h-5 w-5 animate-spin" />
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
import { createMutation } from "@tanstack/svelte-query"
import { duplicateTableCommand } from "@undb/commands"
import type { TableDo } from "@undb/table"
import { LoaderCircleIcon } from "lucide-svelte"
import { LoaderCircleIcon, SirenIcon } from "lucide-svelte"
import { toast } from "svelte-sonner"
import { defaults, superForm } from "sveltekit-superforms"
import { zodClient } from "sveltekit-superforms/adapters"
import * as Form from "$lib/components/ui/form"
import { Input } from "$lib/components/ui/input"
import { Checkbox } from "$lib/components/ui/checkbox"
import * as Alert from "$lib/components/ui/alert"
import { getTable } from "$lib/store/table.store"
export let table: TableDo
const table = getTable()
const form = superForm(
defaults(
{
tableId: table.id.value,
tableId: $table.id.value,
name: "",
includeData: true,
},
Expand Down Expand Up @@ -67,13 +69,13 @@
>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Duplicate Table {table.name.value}</Dialog.Title>
<Dialog.Title>Duplicate Table {$table.name.value}</Dialog.Title>
<Dialog.Description>
Create a new table with the same structure as {table.name.value}
Create a new table with the same structure as {$table.name.value}
</Dialog.Description>
</Dialog.Header>

<form method="POST" use:enhance>
<form method="POST" use:enhance class="space-y-4">
<Form.Field {form} name="name">
<Form.Control let:attrs>
<Form.Label>Name</Form.Label>
Expand All @@ -92,7 +94,15 @@
<input name={attrs.name} value={$formData.includeData} hidden />
</Form.Control>
</Form.Field>
<div class="item-center mt-2 flex justify-end gap-2">

<Alert.Root>
<Alert.Description class="flex items-center text-xs">
<SirenIcon class="mr-2 h-4 w-4" />
System fields will be updated to the current user and timestamp.
</Alert.Description>
</Alert.Root>

<div class="item-center flex justify-end gap-2">
<Button
on:click={() => {
closeModal(DUPLICATE_TABLE_MODAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,4 @@
</div>
</header>

<DuplicateTable table={$table} />
<DuplicateTable />
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "undb",
"version": "1.0.0-15",
"version": "1.0.0-16",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { getCurrentUserId } from "@undb/context/server"
import { WontImplementException, type ISpecification, type ISpecVisitor } from "@undb/domain"
import {
CREATED_AT_TYPE,
CREATED_BY_TYPE,
ReferenceField,
UPDATED_AT_TYPE,
UPDATED_BY_TYPE,
type DuplicatedTableSpecification,
type ITableSpecVisitor,
type SelectField,
Expand Down Expand Up @@ -140,6 +145,18 @@ export class UnderlyingTableSpecVisitor implements ITableSpecVisitor {

this.addSql(duplicateDataSql)

const userId = getCurrentUserId()
const updateSql = this.qb
.updateTable(duplicatedTable.id.value)
.set((eb) => ({
[UPDATED_AT_TYPE]: new Date().getTime(),
[CREATED_AT_TYPE]: new Date().getTime(),
[UPDATED_BY_TYPE]: userId,
[CREATED_BY_TYPE]: userId,
}))
.compile()
this.addSql(updateSql)

const referenceFields = duplicatedTable.schema.getReferenceFields()

for (const field of referenceFields) {
Expand Down

0 comments on commit 4cbacaf

Please sign in to comment.