Skip to content

Commit

Permalink
Merge pull request #2069 from undb-io/release/v1.0.0-91
Browse files Browse the repository at this point in the history
Release version v1.0.0-91
  • Loading branch information
nichenqin authored Sep 27, 2024
2 parents 305f03b + b0fe94b commit 48f1336
Show file tree
Hide file tree
Showing 24 changed files with 1,468 additions and 191 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-91


### 🩹 Fixes

- Template create record with referecegst ([b8fe6d7](https://github.com/undb-io/undb/commit/b8fe6d7))

### ❤️ Contributors

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

## v1.0.0-90


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { CREATE_TABLE_MODAL, IMPORT_TABLE_MODAL, openModal, toggleModal } from "$lib/store/modal.store"
import { CREATE_TABLE_MODAL, IMPORT_TABLE_MODAL, openModal } from "$lib/store/modal.store"
import { DatabaseIcon, ImportIcon, PlusCircleIcon, PlusIcon, SquareMousePointer } from "lucide-svelte"
import * as Table from "$lib/components/ui/table"
import { goto } from "$app/navigation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
import ForeignRecordsPickerDropdown from "../reference/foreign-records-picker-dropdown.svelte"
import { Button } from "$lib/components/ui/button"
import { writable } from "svelte/store"
import { onMount } from "svelte"
export let value: string[] | null
export let field: ReferenceField
export let tableId: string
export let recordId: string | undefined
$: selected = writable<string[]>(value ?? [])
let selected = writable<string[]>(value ?? [])
let hasValue = Array.isArray(value) && value.length > 0
$: selected, (hasValue = Array.isArray(value) && value.length > 0)
onMount(() => {
selected.set(value ?? [])
})
$: $selected, (value = $selected)
let hasValue = Array.isArray($selected) && $selected.length > 0
$: hasValueReactive = Array.isArray($selected) && $selected.length > 0
$: if (hasValue && !hasValueReactive) {
hasValue = hasValueReactive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
getKanbanBgColor(option?.color ?? "gray"),
)}
>
{#if $hasPermission("record:create")}
{#if $hasPermission("record:create")}
{#if $query.isFetchedAfterMount}
{#if recordDos.length > 0}
<Button on:click={onCreateRecord} variant="outline" size="sm" class="w-full">
Expand Down Expand Up @@ -400,7 +400,7 @@
</div>

{#if option && $hasPermission("field:update")}
<Dialog.Root bind:open={updateOptionDialogOpen}>
<Dialog.Root bind:open={updateOptionDialogOpen} portal="body">
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Update option</Dialog.Title>
Expand All @@ -415,7 +415,7 @@
{/if}

{#if option && $hasPermission("field:update")}
<AlertDialog.Root bind:open={deleteOptionDialogOpen}>
<AlertDialog.Root bind:open={deleteOptionDialogOpen} portal="body">
<AlertDialog.Content>
<AlertDialog.Header>
<AlertDialog.Title>Delete Option <Option {option} /></AlertDialog.Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@
{#if r}
{@const values = r.flatten()}
{@const displayValues = r.displayValues?.toJSON() ?? {}}
<div class="flex items-center gap-2">
<div class="flex w-full flex-1 items-center gap-2">
{#if fields.length}
{@const field = fields[0]}
<div class="flex-1 space-y-1">
<Tooltip.Root>
<Tooltip.Root portal="body">
<Tooltip.Trigger asChild let:builder>
<span
class="inline-flex items-center px-3 pt-2"
class="inline-flex max-w-80 items-center overflow-hidden px-3 pt-2"
use:builderActions={{ builders: [builder] }}
{...getAttrs([builder])}
>
Expand All @@ -222,7 +222,8 @@
value={values[field.id.value]}
type={field.type}
displayValue={displayValues[field.id.value]}
class="font-semibold"
class="truncate font-semibold"
title={values[field.id.value]}
placeholder="-"
/>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ViewFilterEditor from "../view-filter-editor/view-filter-editor.svelte"
import ViewColorEditor from "../view-color-editor/view-color-editor.svelte"
import ViewSort from "../view-sort/view-sort.svelte"
import ViewFields from "../view-fields/view-fields.svelte"
import RecordsSearch from "../search/records-search.svelte"
</script>

Expand All @@ -10,6 +11,7 @@
<ViewFilterEditor readonly />
<ViewColorEditor readonly />
<ViewSort readonly />
<ViewFields readonly />
<slot></slot>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { invalidateAll, goto } from "$app/navigation"
import { IMPORT_TEMPLATE_MODAL, closeModal } from "$lib/store/modal.store"
import { FullscreenIcon } from "lucide-svelte"
import { LoaderCircleIcon } from "lucide-svelte"
import * as Dialog from "$lib/components/ui/dialog"
import TemplatePreview from "./template-preview.svelte"
import { Checkbox } from "$lib/components/ui/checkbox/index.js"
Expand Down Expand Up @@ -52,7 +53,7 @@
<p>Card Content</p>
</Card.Content> -->
<Card.Footer class="p-0">
<Dialog.Root>
<Dialog.Root portal="body">
<Dialog.Trigger asChild let:builder>
<Button
builders={[builder]}
Expand Down Expand Up @@ -84,9 +85,8 @@
>
{#if $createFromTemplate.isPending}
<LoaderCircleIcon class="mr-2 size-4 animate-spin" />
{:else}
Use this Template
{/if}
Use this Template
</Button>

<div class="flex items-center space-x-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import { cn } from "$lib/utils"
import { HardDriveIcon, DatabaseIcon, ViewIcon, ChevronRightIcon } from "lucide-svelte"
import * as Collapsible from "$lib/components/ui/collapsible"
import { setTemplate } from "$lib/store/template.store"
export let template: ITemplateDTO
let t = TemplateFactory.create(template.template.template, [], "")
setTemplate(writable(template))
let t = TemplateFactory.create(template.template.template, [],"preview")
let tables = t.flatMap((base) => base.tables.map(({ table }) => table))
let bases = t.map((base) => base.base)
Expand Down
15 changes: 15 additions & 0 deletions apps/frontend/src/lib/store/template.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ITemplateDTO } from "@undb/template"
import { getContext, setContext } from "svelte"
import { type Writable, derived } from "svelte/store"

export function setTemplate(template: Writable<ITemplateDTO>) {
setContext("template", template)
}

export function getTemplate() {
return getContext<Writable<ITemplateDTO | undefined>>("template")
}

export function getIsTemplate() {
return derived([getTemplate()], ([$template]) => !!$template)
}
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-90",
"version": "1.0.0-91",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
11 changes: 11 additions & 0 deletions packages/persistence/src/template/template-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ export const templateData: ITemplateDTO[] = [
template: templates.officeInventoryManagement as IBaseTemplateDTO,
},
},
{
id: "6ba7b814-9dad-11d1-80b4-00c04fd430c8",
icon: "💼",
name: "CRM",
category: "sales",
description: "A template for managing customer relationships, deals, and activities.",
template: {
type: "base",
template: templates.crm as IBaseTemplateDTO,
},
},
]
1 change: 1 addition & 0 deletions packages/table/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./table-id.vo"
export * from "./table-name.vo"
export * from "./table.builder"
export * from "./table.do"
export * from "./table.factory"
export * from "./table.outbox-service"
export * from "./table.outbox-service.provider"
export * from "./table.query-repository.provider"
Expand Down
2 changes: 1 addition & 1 deletion packages/table/src/methods/duplicate-table.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { getNextName } from "@undb/utils"
import type { IDuplicateTableDTO } from "../dto/duplicate-table.dto"
import { DuplicatedTableSpecification } from "../specifications"
import { TableIdVo } from "../table-id.vo"
import { TableFactory } from "../table.builder"
import { TableDo } from "../table.do"
import { TableFactory } from "../table.factory"

export function duplicateTableMethod(
this: TableDo,
Expand Down
7 changes: 3 additions & 4 deletions packages/table/src/modules/records/record/record-values.vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ export class RecordValuesVO extends ValueObject {
static fromJSON(table: TableDo, dto: IRecordValues) {
const values: RecordValues = {}

for (const [id, value] of Object.entries(dto)) {
const fieldId = new FieldIdVo(id)
const field = table.schema.getFieldById(fieldId).into(null)
for (const [idOrName, value] of Object.entries(dto)) {
const field = table.schema.getFieldByIdOrName(idOrName).into(null)
if (!field) continue

const fieldValue = FieldValueFactory.fromJSON(field, value)
if (fieldValue.isSome()) {
Reflect.set(values, fieldId.value, fieldValue.unwrap())
Reflect.set(values, field.id.value, fieldValue.unwrap())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { and, Option } from "@undb/domain"
import type { TableDo } from "../../../../table.do"
import { ReferenceEqual, ReferenceFieldValue } from "../../../schema"
import type { RecordComositeSpecification, RecordDO } from "../../record"
import type { RecordsService } from "../records.service"

export async function createTablesRecordsMethod(
this: RecordsService,
input: { table: TableDo; records: RecordDO[] }[],
): Promise<void> {
for (const { table, records } of input) {
await this.repo.bulkInsert(table, records)
}

for (const { table, records } of input) {
const referenceFields = table.schema.getReferenceFields()
for (const record of records) {
let specs: RecordComositeSpecification[] = []
for (const field of referenceFields) {
const value = record.getValue(field.id)
if (value.isNone()) {
continue
}
const referecneValue = value.unwrap() as ReferenceFieldValue
if (referecneValue.value?.length) {
const spec = new ReferenceEqual(value.unwrap() as ReferenceFieldValue, field.id)
specs.push(spec)
}
}

if (specs.length) {
const spec = and(...specs) as Option<RecordComositeSpecification>
await this.repo.updateOneById(table, record, spec)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { singleton } from "@undb/di"
import type { Option } from "@undb/domain"
import type { IUniqueTableDTO } from "../../../dto"
import type { TableDo } from "../../../table.do"
import type { ITableRepository } from "../../../table.repository"
import { injectTableRepository } from "../../../table.repository.provider"
import {
Expand All @@ -22,6 +23,7 @@ import { bulkduplicateRecordsMethod } from "./methods/bulk-duplicate-records.met
import { bulkUpdateRecordsMethod } from "./methods/bulk-update-records.method"
import { createRecordMethod } from "./methods/create-record.method"
import { createRecordsMethod } from "./methods/create-records.method"
import { createTablesRecordsMethod } from "./methods/create-tables-records.method"
import { deleteRecordMethod } from "./methods/delete-record.method"
import { duplicateRecordMethod } from "./methods/duplicate-record.method"
import { submitFormMethod } from "./methods/submit-form.method"
Expand All @@ -39,6 +41,7 @@ export interface IRecordsService {
bulkDeleteRecords(table: IUniqueTableDTO, dto: IBulkDeleteRecordsDTO): Promise<RecordDO[]>
duplicateRecord(table: IUniqueTableDTO, dto: IDuplicateRecordDTO): Promise<RecordDO>
bulkDuplicateRecords(table: IUniqueTableDTO, dto: IBulkDuplicateRecordsDTO): Promise<RecordDO[]>
createTablesRecords(input: { table: TableDo; records: RecordDO[] }[]): Promise<void>
}

@singleton()
Expand All @@ -60,4 +63,5 @@ export class RecordsService implements IRecordsService {
bulkDeleteRecords = bulkdeleteRecordsMethod
duplicateRecord = duplicateRecordMethod
bulkDuplicateRecords = bulkduplicateRecordsMethod
createTablesRecords = createTablesRecordsMethod
}
2 changes: 1 addition & 1 deletion packages/table/src/services/table.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
type View,
} from "../modules"
import type { ICreateTableFormDTO } from "../modules/forms/dto/create-form.dto"
import { TableFactory } from "../table.builder"
import type { TableDo } from "../table.do"
import { TableFactory } from "../table.factory"
import type { ITableRepository } from "../table.repository"
import { injectTableRepository } from "../table.repository.provider"
import { createTableFieldMethod } from "./methods/create-table-field.method"
Expand Down
Loading

0 comments on commit 48f1336

Please sign in to comment.