Skip to content

Commit

Permalink
Merge pull request #2042 from undb-io/release/v1.0.0-78
Browse files Browse the repository at this point in the history
Release version v1.0.0-78
  • Loading branch information
nichenqin authored Sep 18, 2024
2 parents 38f01cb + 057b824 commit 2d5be4c
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 54 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v1.0.0-78


### 🩹 Fixes

- Fix import date field type ([724c8b5](https://github.com/undb-io/undb/commit/724c8b5))

### ❤️ Contributors

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

## v1.0.0-77


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
let open = false
export let value: FieldType | undefined = undefined
export let onValueChange: (value: FieldType) => void = () => {}
export let filter: (value: FieldType) => boolean = () => true
let search = ""
$: filtered =
fieldTypes.filter((f) => {
const label = $LL.table.fieldTypes[f]()
return label.toLowerCase().includes(search.toLowerCase())
}) ?? []
fieldTypes
.filter((f) => {
const label = $LL.table.fieldTypes[f]()
return label.toLowerCase().includes(search.toLowerCase())
})
.filter(filter) ?? []
$: selected = allFieldTypes.find((f) => f === value)
$: selectedValue = selected ?? "Select a field type..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
onOpenChange={(open) => toggleModal(IMPORT_TABLE_MODAL)}
>
<Dialog.Content class="max-w-5xl">
<Dialog.Header>Import Data - CSV / JSON / Excel</Dialog.Header>
<Dialog.Header class="text-lg font-medium text-gray-600">Import Data - CSV / JSON / Excel</Dialog.Header>
<ImportTable {tableNames} />
</Dialog.Content>
</Dialog.Root>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
import { Label } from "$lib/components/ui/label"
import { Checkbox } from "$lib/components/ui/checkbox"
import { parse, type ImportDataExtensions, type SheetData } from "$lib/import/import.helper"
import { FileIcon, XIcon, ArrowRightIcon, ArrowLeftIcon, LoaderCircleIcon, SettingsIcon } from "lucide-svelte"
import {
FileIcon,
XIcon,
ArrowRightIcon,
ArrowLeftIcon,
LoaderCircleIcon,
SettingsIcon,
ImportIcon,
} from "lucide-svelte"
import * as Table from "$lib/components/ui/table"
import { invalidate, goto } from "$app/navigation"
import { baseId, currentBase } from "$lib/store/base.store"
Expand Down Expand Up @@ -39,6 +47,7 @@
let importData = true
let tableName: string | undefined = undefined
let schema: ICreateSchemaDTO | undefined
let selectedFields: string[] = []
const createRecords = createMutation({
mutationKey: ["table", "import", "records"],
Expand Down Expand Up @@ -66,9 +75,14 @@
for (let j = 0; j < r.length; j++) {
const field = schema?.[j]
if (!field) {
if (!field || !field.id) {
continue
}
if (!selectedFields.includes(field.id)) {
continue
}
const value = castFieldValue(field, r[j])
record.values[field.id!] = value
}
Expand All @@ -82,7 +96,7 @@
})
} else {
await invalidate("undb:tables")
await goto(`/t/${data}`)
await goto(`/t/${tableId}`)
closeModal(IMPORT_TABLE_MODAL)
baseId.set(null)
}
Expand All @@ -92,8 +106,13 @@
},
})
async function setData() {
if (!file) return
async function handleFile() {
if (!file) {
data = undefined
schema = undefined
selectedFields = []
return
}
const parsed = await parse(file)
if (firstRowAsHeader) {
Expand All @@ -118,6 +137,8 @@
}
handleSchemaChange()
selectedFields = (schema?.map((field) => field.id).filter((id) => !!id) as string[]) ?? []
step = 1
}
function handleSchemaChange() {
Expand All @@ -141,13 +162,17 @@
file = f
tableName = getNextName(tableNames, file.name)
await setData()
await handleFile()
}
function removeFile() {
file = undefined
handleFile()
}
$: filteredSchema = (schema?.filter((field) => !!field.id && selectedFields.includes(field.id)) ??
[]) as ICreateSchemaDTO
function handleClickImport() {
if (!schema) return
Expand All @@ -165,18 +190,12 @@
id: tableId,
name: tableName!,
baseId,
schema,
schema: filteredSchema,
})
return
}
}
function removeField(index: number) {
if (data) {
data.data = data.data.map((r) => r.filter((_, i) => i !== index))
}
}
</script>

{#if step === 0}
Expand All @@ -189,7 +208,7 @@
/>
{#if file}
<div class="flex items-center justify-between gap-2 rounded-sm border p-3">
<div class="flex items-center gap-2">
<div class="flex items-center gap-2 text-gray-600">
<FileIcon class="text-muted-foreground h-4 w-4" />
<p>
{tableName}
Expand All @@ -205,7 +224,7 @@
<Checkbox
disabled={$createTable.isPending || $createRecords.isPending}
bind:checked={firstRowAsHeader}
onCheckedChange={setData}
onCheckedChange={handleFile}
/>
First row as header
</Label>
Expand All @@ -218,7 +237,7 @@
<Checkbox
disabled={$createTable.isPending || $createRecords.isPending}
bind:checked={firstRowAsHeader}
onCheckedChange={setData}
onCheckedChange={handleFile}
/>
First row as header
</Label>
Expand All @@ -232,29 +251,49 @@
<div>Name</div>
<Input disabled={$createTable.isPending || $createRecords.isPending} class="text-sm" bind:value={tableName} />
</Label>

<p class="text-sm text-gray-500">
{selectedFields.length} fields selected
</p>
</div>
<div class="rounded-sm border">
<Table.Root>
<Table.Header>
<Table.Row>
<Table.Root class="flex h-[400px] flex-col overflow-hidden">
<Table.Header class="flex w-full">
<Table.Row class="w-full">
<Table.Head class="w-[40px]"></Table.Head>
<Table.Head class="w-[200px]">Field Name</Table.Head>
<Table.Head class="flex-1">Field Type</Table.Head>
<Table.Head class="text-right">Action</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Body class="w-full flex-1 overflow-y-auto">
{#each schema as field, idx}
<Table.Row class="group">
<Table.Cell class="font-medium">
<Table.Row data-field-id={field.id} class="group flex w-full">
<Table.Cell class="flex w-[40px] items-center justify-center font-medium">
{#if !!field.id}
<Checkbox
checked={selectedFields.includes(field.id)}
onCheckedChange={() => {
if (selectedFields.includes(field.id)) {
selectedFields = selectedFields.filter((id) => id !== field.id)
} else {
selectedFields = [...selectedFields, field.name]
}
}}
disabled={$createTable.isPending || $createRecords.isPending}
/>
{/if}
</Table.Cell>
<Table.Cell class="w-[200px] font-medium">
<Input
class="text-sm"
bind:value={data.data[0][idx]}
disabled={$createTable.isPending || $createRecords.isPending}
/>
</Table.Cell>
<Table.Cell class="flex items-center gap-2">
<Table.Cell class="flex flex-1 items-center gap-2">
<FieldTypePicker
disabled={$createTable.isPending || $createRecords.isPending}
filter={(type) => type !== "reference" && type !== "rollup"}
bind:value={schema[idx].type}
onValueChange={() => {}}
tabIndex={-1}
Expand All @@ -281,20 +320,6 @@
</Dialog.Header>
</Dialog.Content>
</Dialog.Root>

<!-- <div class="flex items-center">
<FieldIcon type={field.type} class="mr-2 h-4 w-4" />
{field.type}
</div> -->
</Table.Cell>
<Table.Cell class="text-right">
<button
disabled={$createTable.isPending || $createRecords.isPending}
on:click={() => removeField(idx)}
class="rounded-full p-1 opacity-0 transition-colors hover:bg-gray-200 group-hover:opacity-100"
>
<XIcon class="text-muted-foreground h-4 w-4" />
</button>
</Table.Cell>
</Table.Row>
{/each}
Expand All @@ -318,17 +343,21 @@
{/if}
<Button
disabled={(step === 0 && !file) ||
(step === 1 && schema.length < 1) ||
(step === 1 && (!schema || schema.length < 1)) ||
$createTable.isPending ||
$createRecords.isPending}
$createRecords.isPending ||
selectedFields.length < 1}
on:click={handleClickImport}
class="min-w-32"
size="sm"
>
{#if step === 0}
Next step <ArrowRightIcon class="ml-2 h-4 w-4" />
{:else}
{#if $createTable.isPending || $createRecords.isPending}
<LoaderCircleIcon class="mr-2 h-4 w-4 animate-spin" />
{:else}
<ImportIcon class="mr-2 size-4" />
{/if}
Import
{/if}
Expand Down
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-77",
"version": "1.0.0-78",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
3 changes: 2 additions & 1 deletion packages/table/src/modules/schema/fields/dto/field.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { autoIncrementFieldDTO } from "../variants/autoincrement-field"
import { checkboxFieldDTO, createCheckboxFieldDTO } from "../variants/checkbox-field"
import { createdAtFieldDTO } from "../variants/created-at-field"
import { createdByFieldDTO } from "../variants/created-by-field"
import { currencyFieldDTO } from "../variants/currency-field"
import { createCurrencyFieldDTO, currencyFieldDTO } from "../variants/currency-field"
import { createEmailFieldDTO, emailFieldDTO } from "../variants/email-field"
import { idFieldDTO } from "../variants/id-field/id-field.vo"
import { createLongTextFieldDTO, longTextFieldDTO } from "../variants/long-text-field"
Expand Down Expand Up @@ -63,6 +63,7 @@ export const inferCreateFieldDTO = z.discriminatedUnion("type", [
createStringFieldDTO.omit({ id: true, name: true }),
createNumberFieldDTO.omit({ id: true, name: true }),
createEmailFieldDTO.omit({ id: true, name: true }),
createCurrencyFieldDTO.omit({ id: true, name: true }),
createDateFieldDTO.omit({ id: true, name: true }),
createJsonFieldDTO.omit({ id: true, name: true }),
createCheckboxFieldDTO.omit({ id: true, name: true }),
Expand Down
Loading

0 comments on commit 2d5be4c

Please sign in to comment.