Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version v1.0.0-69 #2020

Merged
merged 17 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-69


### 🩹 Fixes

- Fix record ui ([76d26f5](https://github.com/undb-io/undb/commit/76d26f5))

### ❤️ Contributors

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

## v1.0.0-68


Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ UNDB is a no-code platform that can also serve as a Backend as a Service (BaaS).

## Screenshot

![kanban](./docs/images/kanban.jpeg)
![gallery](./docs/images/gallery.jpeg)
![form](./docs/images/form.jpeg)
![openapi](./docs/images/openapi.jpeg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

const table = getTable()

$: visibleFields = $table.getOrderedVisibleFields()
$: visibleFields = $table?.getOrderedVisibleFields() ?? []

export let disabled: boolean | undefined
export let option: IButtonFieldOption = {
Expand All @@ -41,7 +41,7 @@
},
}
const value = writable<MaybeConditionGroup<ZodUndefined> | undefined>()
$: validValue = $value ? parseValidViewFilter($table.schema, $value) : undefined
$: validValue = $table && $value ? parseValidViewFilter($table.schema, $value) : undefined
$: if (validValue) {
option.disabled = validValue
}
Expand All @@ -53,9 +53,10 @@
})

$: selectedFields = option.action.values.map((v) => v.field)
$: selectableFields = $table.schema.fields.filter(
(f) => getIsMutableFieldType(f.type) && f.type !== "attachment" && !selectedFields.includes(f.id.value),
)
$: selectableFields =
$table?.schema.fields.filter(
(f) => getIsMutableFieldType(f.type) && f.type !== "attachment" && !selectedFields.includes(f.id.value),
) ?? []
</script>

<div class="space-y-2">
Expand All @@ -74,7 +75,8 @@
<div class="space-y-2 rounded-md border px-4 py-3">
<p class="text-xs font-semibold">Update Value when Click Button</p>
{#each option.action.values as value, index}
{@const field = value.field ? $table.schema.getFieldById(new FieldIdVo(value.field)).unwrap() : undefined}
{@const field =
value.field && $table ? $table.schema.getFieldById(new FieldIdVo(value.field)).unwrap() : undefined}
<FieldPicker
class="w-full"
bind:value={value.field}
Expand All @@ -90,7 +92,7 @@
placeholder="Value to update..."
bind:value={value.value}
{field}
tableId={$table.id.value}
tableId={$table?.id.value}
/>
{/if}
{#if index !== option.action.values.length - 1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</script>

{#if v}
<div class={cn("text-sm", $$restProps.class)}>
<div class={cn("truncate text-left text-sm", $$restProps.class)}>
{v}
</div>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
export let disabled = false
export let readonly = false

$: filteredFields = table.getOrderedVisibleFields().filter((f) => filter({ id: f.id.value, type: f.type }))
$: filteredFields = table?.getOrderedVisibleFields().filter((f) => filter({ id: f.id.value, type: f.type })) ?? []
export let disableGroup = false

$: isEven = level % 2 === 0
Expand Down Expand Up @@ -103,7 +103,7 @@
{#each value.children as child, i (child.id)}
{#if isMaybeFieldCondition(child)}
{@const field = child.field
? table.schema.getFieldById(new FieldIdVo(child.field)).into(undefined)
? table?.schema.getFieldById(new FieldIdVo(child.field)).into(undefined)
: undefined}
<div class="grid grid-cols-12 items-center gap-2">
{#if i === 0 || disableGroup}
Expand All @@ -122,7 +122,7 @@
<FilterField
{disabled}
{readonly}
table={writable(table)}
table={table ? writable(table) : undefined}
{sameWidth}
onValueChange={(type, prev) => {
if (type !== prev) {
Expand All @@ -135,7 +135,13 @@
bind:value={child.field}
class={cn("col-span-4 rounded-r-none border-r-0")}
/>
<FieldFilterControl class="col-span-8 overflow-hidden" {disabled} {field} bind:op={child.op} bind:value={child.value} />
<FieldFilterControl
class="col-span-8 overflow-hidden"
{disabled}
{field}
bind:op={child.op}
bind:value={child.value}
/>
</div>
<div class="col-span-1 flex items-center gap-2">
{#if !readonly && $hasPermission("table:update")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,26 @@
on:click={() => ($r = record.id.value)}
disabled={readonly}
data-record-id={record.id.value}
class={cn("relative mb-2 flex w-full flex-col space-y-2 rounded bg-white p-2 shadow", isMatch && "pl-3")}
class={cn(
"relative mb-2 flex w-full flex-col space-y-2 overflow-hidden rounded bg-white p-2 shadow",
isMatch && "pl-3",
)}
>
{#if isMatch}
<div class={cn("absolute left-0 top-0 h-full w-1", condition && getBgColor(condition.option.color))}></div>
{/if}
{#each fields as field}
<div class="flex items-center gap-2">
<div class="flex w-full items-center gap-2">
<Tooltip.Root>
<Tooltip.Trigger>
<Tooltip.Trigger class="w-full">
<FieldValue
{field}
tableId={$table.id.value}
recordId={record.id.value}
value={values[field.id.value]}
type={field.type}
displayValue={displayValues[field.id.value]}
class="w-full truncate"
/>
</Tooltip.Trigger>
<Tooltip.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
{/if}
</div>
</Form.Label>
<div class="h-9 flex-1 overflow-hidden">
<div class="min-h-9 flex-1 overflow-hidden">
{#if field.isSystem || !field.isMutable}
<FieldValue
{field}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { LayoutData } from "./$types"
import { writable } from "svelte/store"
import { shareStore } from "$lib/store/share.store"
import Logo from "$lib/images/logo.svg"

export let data: LayoutData
$: tableStore = data.getFormShareData
Expand All @@ -26,7 +27,13 @@
</script>

{#if $table}
<slot />
<main class="relative h-full w-full">
<slot />
<div class="text-muted-foreground absolute bottom-5 right-5 flex items-center justify-center text-sm">
<img src={Logo} alt="undb" class="mr-2 h-4 w-4" />
Powered by <a href="https://undb.io" class="text-primary underline">&nbsp;undb</a>
</div>
</main>
{/if}

<style>
Expand Down
Binary file added docs/images/gallery.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/intro.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/kanban.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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-68",
"version": "1.0.0-69",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
2 changes: 2 additions & 0 deletions packages/command-handlers/src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { SetViewFieldsCommandHandler } from "./set-view-fields.command-handler"
import { SetViewFilterCommandHandler } from "./set-view-filter.command-handler"
import { SetViewOptionCommandHandler } from "./set-view-option.command-handler"
import { SetViewSortCommandHandler } from "./set-view-sort.command-handler"
import { SubmitFormCommandHandler } from "./submit-form.command-handler"
import { TriggerRecordButtonCommandHandler } from "./trigger-record-button.command-handler"
import { UpdateAccountCommandHandler } from "./update-account.command-handler"
import { UpdateBaseCommandHandler } from "./update-base.command-handler"
Expand Down Expand Up @@ -100,4 +101,5 @@ export const commandHandlers = [
DeleteBaseCommandHandler,
TriggerRecordButtonCommandHandler,
DeleteFormCommandHandler,
SubmitFormCommandHandler,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { SubmitFormCommand } from "@undb/commands"
import { commandHandler } from "@undb/cqrs"
import { singleton } from "@undb/di"
import type { ICommandHandler } from "@undb/domain"
import { createLogger } from "@undb/logger"
import { injectRecordsService, type IRecordsService } from "@undb/table"

@commandHandler(SubmitFormCommand)
@singleton()
export class SubmitFormCommandHandler implements ICommandHandler<SubmitFormCommand, any> {
logger = createLogger(SubmitFormCommandHandler.name)
constructor(
@injectRecordsService()
private readonly service: IRecordsService,
) {}

async execute(command: SubmitFormCommand): Promise<any> {
this.logger.debug(command, "executing submit form command")
const record = await this.service.submitForm(command, { formId: command.formId, values: command.values })

return record.id.value
}
}
1 change: 1 addition & 0 deletions packages/commands/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export * from "./set-view-fields.command"
export * from "./set-view-filter.command"
export * from "./set-view-option.command"
export * from "./set-view-sort.command"
export * from "./submit-form.command"
export * from "./trigger-record-button.command"
export * from "./update-account.command"
export * from "./update-base.command"
Expand Down
25 changes: 25 additions & 0 deletions packages/commands/src/submit-form.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Command, type CommandProps } from "@undb/domain"
import type { IRecordValues } from "@undb/table"
import { submitFormDTO, uniqueTableDTO } from "@undb/table"
import { z } from "@undb/zod"

export const submitFormCommand = submitFormDTO.merge(uniqueTableDTO)

export type ISubmitFormCommand = z.infer<typeof submitFormCommand>

export class SubmitFormCommand extends Command implements ISubmitFormCommand {
public readonly tableId?: string
public readonly formId: string
public readonly baseName?: string
public readonly tableName?: string
public readonly values: IRecordValues

constructor(props: CommandProps<ISubmitFormCommand>) {
super(props)
this.tableId = props.tableId
this.formId = props.formId
this.baseName = props.baseName
this.tableName = props.tableName
this.values = props.values
}
}
17 changes: 3 additions & 14 deletions packages/persistence/src/record/record.query-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { inject, singleton } from "@undb/di"
import { None, Option, Some, type PaginatedDTO } from "@undb/domain"
import {
AUTO_INCREMENT_TYPE,
FieldIdVo,
ID_TYPE,
TableIdVo,
injectTableRepository,
Expand Down Expand Up @@ -86,11 +85,7 @@ export class RecordQueryRepository implements IRecordQueryRepository {
const select = q?.select.into(undefined)
const view = q?.ignoreView ? undefined : q?.view

const selectFields = select
? select.map((f) => table.schema.getFieldById(new FieldIdVo(f)).into(undefined)).filter((f) => !!f)
: view
? table.getOrderedVisibleFields(view.id.value)
: table.schema.fields
const selectFields = table.getSelectFields(view, select)

const foreignTables = await this.getForeignTables(table, selectFields)
const qb = this.helper.createQuery(table, foreignTables, selectFields, None)
Expand All @@ -115,11 +110,7 @@ export class RecordQueryRepository implements IRecordQueryRepository {
const pagination = query.into(undefined)?.pagination.into(undefined)
const select = query.into(undefined)?.select.into(undefined)

const selectFields = select
? select.map((f) => table.schema.getFieldById(new FieldIdVo(f)).into(undefined)).filter((f) => !!f)
: ignoreView
? table.schema.fields
: table.getOrderedVisibleFields(view.id.value)
const selectFields = table.getSelectFields(ignoreView ? undefined : view, select)
const foreignTables = await this.getForeignTables(table, selectFields)
const qb = this.helper.createQuery(table, foreignTables, selectFields, spec)

Expand Down Expand Up @@ -159,9 +150,7 @@ export class RecordQueryRepository implements IRecordQueryRepository {
const spec = table.getQuerySpec({ viewId: view.id.value, userId, filter })

const select = query.into(undefined)?.select.into(undefined)
const selectFields = select
? select.map((f) => table.schema.getFieldById(new FieldIdVo(f)).into(undefined)).filter((f) => !!f)
: table.getOrderedVisibleFields(view.id.value)
const selectFields = table.getSelectFields(view, select)

const foreignTables = await this.getForeignTables(table, selectFields)
const qb = this.helper.createQueryCreator(table, foreignTables, selectFields, spec)
Expand Down
1 change: 1 addition & 0 deletions packages/table/src/modules/records/record/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export * from "./create-record.dto"
export * from "./delete-record.dto"
export * from "./duplicate-record.dto"
export * from "./record.dto"
export * from "./submit-form.dto"
export * from "./update-record.dto"
12 changes: 12 additions & 0 deletions packages/table/src/modules/records/record/dto/submit-form.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { z } from "@undb/zod"
import { formId } from "../../../forms/form/form-id.vo"
import { recordId } from "../record-id.vo"
import { recordValues } from "../record-values.vo"

export const submitFormDTO = z.object({
id: recordId.optional(),
formId: formId,
values: recordValues,
})

export type ISubmitFormDTO = z.infer<typeof submitFormDTO>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Some } from "@undb/domain"
import type { IUniqueTableDTO } from "../../../../dto"
import { withUniqueTable } from "../../../../specifications"
import { RecordDO, type ISubmitFormDTO } from "../../record"
import type { RecordsService } from "../records.service"

export async function submitFormMethod(
this: RecordsService,
t: IUniqueTableDTO,
dto: ISubmitFormDTO,
): Promise<RecordDO> {
const spec = withUniqueTable(t).unwrap()
const table = (await this.tableRepository.findOne(Some(spec))).expect("Table not found")

const record = RecordDO.create(table, dto)
await this.repo.insert(table, record)

return record
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { group } from "radash"
import type { TableDo } from "../../../table.do"
import type { ITableRepository } from "../../../table.repository"
import { injectTableRepository } from "../../../table.repository.provider"
import { FieldIdVo, type IAttachmentFieldValue } from "../../schema"
import { type IAttachmentFieldValue } from "../../schema"
import { injectObjectStorage, type IObjectStorage } from "../../storage"
import type { AggregateResult, ICountRecordsDTO, IGetAggregatesDTO, IGetRecordByIdDTO, IGetRecordsDTO } from "../dto"
import {
Expand Down Expand Up @@ -73,9 +73,7 @@ export class RecordsQueryService implements IRecordsQueryService {
table: TableDo,
value: IRecordDTO["values"],
): Promise<IRecordDTO["values"]> {
const fields = dto.select?.length
? dto.select.map((fieldId) => table.schema.getFieldById(new FieldIdVo(fieldId)).unwrap())
: table.schema.fields
const fields = table.getSelectFields(undefined, dto.select)
const attachmentFields = fields.filter((field) => field.type === "attachment")
if (!attachmentFields.length) {
return value
Expand Down
Loading
Loading