Skip to content

Commit

Permalink
Merge pull request #2061 from undb-io/release/v1.0.0-87
Browse files Browse the repository at this point in the history
Release version v1.0.0-87
  • Loading branch information
nichenqin authored Sep 23, 2024
2 parents 2aee5c1 + 2bd91b2 commit 18f04b7
Show file tree
Hide file tree
Showing 69 changed files with 1,124 additions and 197 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-87


### 🏡 Chore

- Remove buttong ([a74b338](https://github.com/undb-io/undb/commit/a74b338))

### ❤️ Contributors

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

## v1.0.0-86


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{/if}
{/if}
</div>
{#if (isSelected || isEditing) && ((!Array.isArray(value) && !!value) || (Array.isArray(value) && value.length))}
{#if (isSelected || isEditing) && ((!Array.isArray(value) && !!value) || (Array.isArray(value) && value.length)) && field.fn === "lookup"}
<Popover.Root>
<Popover.Trigger asChild let:builder>
<Button builders={[builder]} variant="link" class="min-w-4 pl-2 pr-0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,33 @@
setRecordsStore(recordsStore)
</script>

<TableTools>
{#if !shareId}
<KanbanOptionButton {view} />
{/if}
</TableTools>
{#if view.type === "kanban"}
{#if field?.type === "select"}
{#if field.isSingle}
<SelectKanbanView {view} {shareId} {viewId} />
{:else}
<section class="flex h-full w-full items-center justify-center">
<SelectKanbanRequiresSingle {view} {field} {shareId} />
{#key $table.id.value}
<TableTools>
{#if !shareId}
<KanbanOptionButton {view} />
{/if}
</TableTools>
{#if view.type === "kanban"}
{#if field?.type === "select"}
{#if field.isSingle}
<SelectKanbanView {view} {shareId} {viewId} />
{:else}
<section class="flex h-full w-full items-center justify-center">
<SelectKanbanRequiresSingle {view} {field} {shareId} />
</section>
{/if}
{:else if !shareId}
<section class="bg-muted flex h-full w-full items-center justify-center">
<SelectKanbanField {view} />
</section>
{/if}
{:else if !shareId}
<section class="bg-muted flex h-full w-full items-center justify-center">
<SelectKanbanField {view} />
</section>
{/if}
{/if}

{#await import("$lib/components/blocks/create-record/create-record-sheet.svelte") then { default: CreateRecordSheet }}
<CreateRecordSheet />
{/await}
{#await import("$lib/components/blocks/create-record/create-record-sheet.svelte") then { default: CreateRecordSheet }}
<CreateRecordSheet />
{/await}

{#await import("$lib/components/blocks/record-detail/table-record-detail-sheet.svelte") then { default: TableRecordDetailSheet }}
<TableRecordDetailSheet />
{/await}
{#await import("$lib/components/blocks/record-detail/table-record-detail-sheet.svelte") then { default: TableRecordDetailSheet }}
<TableRecordDetailSheet />
{/await}
{/key}
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,13 @@
{:else}
<div class="flex h-full w-full flex-col items-center justify-center space-y-3">
<p class="text-sm font-semibold">No records</p>
<p class="text-muted-foreground text-xs">
Create a new record of this option <Option
option={option ?? { id: "", name: "No Option", color: "gray" }}
/>
</p>
<div class="text-muted-foreground space-y-2 text-xs">
<p>Create a new record of this option</p>

<div class="flex w-full items-center justify-center">
<Option option={option ?? { id: "", name: "No Option", color: "gray" }} />
</div>
</div>
<Button on:click={onCreateRecord} variant="outline" size="sm">
<PlusIcon class="text-muted-foreground mr-2 h-4 w-4 font-semibold" />
New Record
Expand Down
21 changes: 17 additions & 4 deletions apps/frontend/src/lib/components/blocks/share/share-button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<Input
value={url}
readonly
class="flex-1 cursor-pointer"
class="flex-1 cursor-pointer text-gray-600"
on:click={(e) => {
copy()
e.target.select()
Expand Down Expand Up @@ -194,7 +194,7 @@
copyIFrame()
e.target.select()
}}
class="flex-1 cursor-pointer"
class="flex-1 cursor-pointer text-gray-600"
value={iframe}
/>
<button type="button" on:click={copyIFrame}>
Expand All @@ -211,8 +211,21 @@
<div class="space-y-2">
<p class="text-xs font-semibold">Share ID</p>
<div class="flex items-center gap-2">
<Input value={share?.id} readonly />
<button type="button" on:click={copyShareId}>
<Input
on:click={(e) => {
copyShareId()
e.target.select()
}}
value={share?.id}
readonly
class="cursor-pointer text-gray-600"
/>
<button
type="button"
on:click={(e) => {
copyShareId()
}}
>
{#if shareIdCopied}
<CopyCheckIcon class="h-4 w-4" />
{:else}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
DELETE_VIEW,
DUPLICATE_TABLE_MODAL,
DUPLICATE_VIEW,
SET_DEFAULT_VIEW,
UPDATE_TABLE_MODAL,
UPDATE_VIEW,
toggleModal,
Expand Down Expand Up @@ -227,6 +228,10 @@
</DropdownMenu.SubContent>
</DropdownMenu.Sub>
{#if !view.isDefault}
<DropdownMenu.Item class="text-xs " on:click={() => toggleModal(SET_DEFAULT_VIEW)}>
<PencilIcon class="mr-2 h-3 w-3" />
Set as Default View
</DropdownMenu.Item>
<DropdownMenu.Item
class="text-xs text-red-500 hover:bg-red-200 hover:text-red-500"
on:click={() => toggleModal(DELETE_VIEW)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CREATE_TABLE_MODAL,
DELETE_VIEW,
DUPLICATE_VIEW,
SET_DEFAULT_VIEW,
toggleModal,
UPDATE_VIEW,
} from "$lib/store/modal.store"
Expand Down Expand Up @@ -214,8 +215,12 @@
Duplicate View
</DropdownMenu.Item>
{#if !view.isDefault}
<DropdownMenu.Item class="text-xs" on:click={() => toggleModal(SET_DEFAULT_VIEW)}>
<PencilIcon class="mr-2 h-3 w-3" />
Set as Default View
</DropdownMenu.Item>
<DropdownMenu.Item
class="text-xs text-red-500 hover:bg-red-200 hover:text-red-500"
class="text-xs text-red-500 hover:!bg-red-200 hover:!text-red-500"
on:click={() => toggleModal(DELETE_VIEW)}
>
<CopyPlusIcon class="mr-2 h-3 w-3" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script lang="ts">
import * as AlertDialog from "$lib/components/ui/alert-dialog"
import { isModalOpen, SET_DEFAULT_VIEW, toggleModal, closeModal } from "$lib/store/modal.store"
import { trpc } from "$lib/trpc/client"
import { getTable, viewId } from "$lib/store/table.store"
import { createMutation } from "@tanstack/svelte-query"
import { derived } from "svelte/store"
import { invalidateAll } from "$app/navigation"
import { toast } from "svelte-sonner"
import { goto } from "$app/navigation"
const table = getTable()
let view = derived([table, viewId], ([$table, $viewId]) => $table.views.getViewById($viewId))
const setAsDefaultViewMutation = createMutation({
mutationFn: trpc.table.view.setDefault.mutate,
async onSuccess(data, variables, context) {
closeModal(SET_DEFAULT_VIEW)
await invalidateAll()
toast.success("View set as default")
await goto(`/t/${$table.id.value}`)
},
onError(error, variables, context) {
toast.error(error.message)
},
})
</script>

<AlertDialog.Root open={$isModalOpen(SET_DEFAULT_VIEW)} onOpenChange={() => toggleModal(SET_DEFAULT_VIEW)}>
<AlertDialog.Content>
<AlertDialog.Header>
<AlertDialog.Title>Set {$view.name.value} as default view</AlertDialog.Title>
<AlertDialog.Description>The original view will be replaced.</AlertDialog.Description>
</AlertDialog.Header>
<AlertDialog.Footer>
<AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
<AlertDialog.Action
disabled={$setAsDefaultViewMutation.isPending}
on:click={() => $setAsDefaultViewMutation.mutate({ tableId: $table.id.value, viewId: $viewId })}
>
Continue
</AlertDialog.Action>
</AlertDialog.Footer>
</AlertDialog.Content>
</AlertDialog.Root>
2 changes: 2 additions & 0 deletions apps/frontend/src/lib/store/modal.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const CREATE_WEBHOOK_MODAL = "createWebhook" as const
export const CREATE_RLS_MODAL = "createRLS" as const
export const UPDATE_VIEW = "updateView" as const
export const DUPLICATE_VIEW = "duplicateView" as const
export const SET_DEFAULT_VIEW = "setDefaultView" as const
export const DELETE_VIEW = "deleteView" as const
export const CREATE_BASE_MODAL = "createBase" as const
export const DUPLICATE_BASE_MODAL = "duplicateBase" as const
Expand All @@ -34,6 +35,7 @@ type ModalType =
| typeof UPDATE_VIEW
| typeof DUPLICATE_VIEW
| typeof DELETE_VIEW
| typeof SET_DEFAULT_VIEW
| typeof CREATE_BASE_MODAL
| typeof UPDATE_BASE_MODAL
| typeof DELETE_TABLE_MODAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
{#await import("$lib/components/blocks/view/duplicate-view-dialog.svelte") then { default: DuplicateViewDialog }}
<DuplicateViewDialog />
{/await}
{#await import("$lib/components/blocks/view/set-as-default-view.svelte") then { default: SetAsDefaultView }}
<SetAsDefaultView />
{/await}
{#await import("$lib/components/blocks/view/delete-view-dialog.svelte") then { default: DeleteViewDialog }}
<DeleteViewDialog />
{/await}
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-86",
"version": "1.0.0-87",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class CreateFromTemplateCommandHandler
async execute(command: CreateFromTemplateCommand): Promise<ICreateFromTemplateCommandOutput> {
this.logger.info(`create from template command received: ${command.templateName}`)

const template = templates["test"]
const template = templates["projectManagement"]

const spaceId = mustGetCurrentSpaceId()
const result = await this.templateService.createBase(template, spaceId)
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 @@ -33,6 +33,7 @@ import { DuplicateViewCommandHandler } from "./duplicate-view.command-handler"
import { EnableShareCommandHandler } from "./enable-share.command-handler"
import { ExportViewCommandHandler } from "./export-view.command-handler"
import { InviteCommandHandler } from "./invite.command-handler"
import { SetDefaultViewCommandHandler } from "./set-default-view.command-handler"
import { SetFieldWidthCommandHandler } from "./set-field-width.command-handler"
import { SetTableFormCommandHandler } from "./set-table-form.command-handler"
import { SetTableRLSCommandHandler } from "./set-table-rls.command-handler"
Expand Down Expand Up @@ -108,4 +109,5 @@ export const commandHandlers = [
SetFieldWidthCommandHandler,
DuplicateTableFormCommandHandler,
CreateFromTemplateCommandHandler,
SetDefaultViewCommandHandler,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SetDefaultViewCommand } 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 { TableIdVo, injectTableRepository, type ITableRepository } from "@undb/table"

@commandHandler(SetDefaultViewCommand)
@singleton()
export class SetDefaultViewCommandHandler implements ICommandHandler<SetDefaultViewCommand, any> {
public readonly logger = createLogger(SetDefaultViewCommandHandler.name)
constructor(
@injectTableRepository()
private readonly repo: ITableRepository,
) {}

async execute(command: SetDefaultViewCommand): Promise<any> {
const table = (await this.repo.findOneById(new TableIdVo(command.tableId))).unwrap()

const spec = table.$setDefaultView(command)

if (spec.isSome()) {
await this.repo.updateOneById(table, spec)
}
}
}
1 change: 1 addition & 0 deletions packages/commands/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export * from "./duplicate-view.command"
export * from "./enable-share.command"
export * from "./export-view.command"
export * from "./invite.command"
export * from "./set-default-view.command"
export * from "./set-field-width.command"
export * from "./set-table-form.command"
export * from "./set-table-rls.command"
Expand Down
18 changes: 18 additions & 0 deletions packages/commands/src/set-default-view.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Command, type CommandProps } from "@undb/domain"
import { setDefaultViewDTO, tableId } from "@undb/table"
import { z } from "@undb/zod"

export const setDefaultViewCommand = setDefaultViewDTO.merge(z.object({ tableId: tableId }))

export type ISetDefaultViewCommand = z.infer<typeof setDefaultViewCommand>

export class SetDefaultViewCommand extends Command {
public readonly tableId: string
public readonly viewId: string

constructor(props: CommandProps<ISetDefaultViewCommand>) {
super(props)
this.tableId = props.tableId
this.viewId = props.viewId
}
}
4 changes: 2 additions & 2 deletions packages/persistence/src/qb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function createQueryBuilderWithDialect(dialect: Dialect) {
logger.debug(
{
query: event.query.sql,
// params: event.query.parameters,
params: event.query.parameters,
duration: event.queryDurationMillis,
},
"kysely.query",
Expand All @@ -27,7 +27,7 @@ export function createQueryBuilderWithDialect(dialect: Dialect) {
{
error: event.error,
query: event.query.sql,
// params: event.query.parameters,
params: event.query.parameters,
duration: event.queryDurationMillis,
},
"kysely.error",
Expand Down
3 changes: 3 additions & 0 deletions packages/persistence/src/table/table.mutation-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class TableMutationVisitor extends AbstractQBMutationVisitor implements I
table_id: this.table.id.value,
subject_id: field.id.value,
})
.onConflict((ob) => ob.doNothing())
.compile()
this.addSql(sql)

Expand Down Expand Up @@ -164,6 +165,7 @@ export class TableMutationVisitor extends AbstractQBMutationVisitor implements I
table_id: this.table.id.value,
subject_id: views.view.id.value,
})
.onConflict((ob) => ob.doNothing())
.compile()

this.addSql(sql)
Expand Down Expand Up @@ -212,6 +214,7 @@ export class TableMutationVisitor extends AbstractQBMutationVisitor implements I
table_id: this.table.id.value,
subject_id: views.form.id,
})
.onConflict((ob) => ob.doNothing())
.compile()

this.addSql(sql)
Expand Down
6 changes: 5 additions & 1 deletion packages/persistence/src/table/table.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ export class TableRepository implements ITableRepository {
.concat(formIds)
.concat(fieldsIds)
.map((id) => ({ table_id: table.id.value, subject_id: id }))
await trx.insertInto("undb_table_id_mapping").values(mapping).execute()
await trx
.insertInto("undb_table_id_mapping")
.values(mapping)
.onConflict((ob) => ob.doNothing())
.execute()

await this.underlyingTableService.create(table)
await this.outboxService.save(table)
Expand Down
Loading

0 comments on commit 18f04b7

Please sign in to comment.