Skip to content

Commit 4809ee8

Browse files
authored
Merge pull request #2102 from undb-io/release/v1.0.0-105
Release version v1.0.0-105
2 parents d1fe2ff + e8bb127 commit 4809ee8

30 files changed

+522
-72
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## v1.0.0-105
4+
5+
6+
### 🩹 Fixes
7+
8+
- Fix loading delete record ([002a59d](https://github.com/undb-io/undb/commit/002a59d))
9+
10+
### ❤️ Contributors
11+
12+
- Nichenqin ([@nichenqin](http://github.com/nichenqin))
13+
314
## v1.0.0-104
415

516

apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<script lang="ts">
2-
import { getTable } from "$lib/store/table.store"
32
import { trpc } from "$lib/trpc/client"
43
import { cn } from "$lib/utils"
54
import { createQuery } from "@tanstack/svelte-query"
65
import { ID_TYPE, isValidWidget, type IAggregate, type IWidgetDTO } from "@undb/table"
76
import { derived } from "svelte/store"
87
import { TriangleAlertIcon } from "lucide-svelte"
98
import * as Tooltip from "$lib/components/ui/tooltip"
10-
11-
const table = getTable()
9+
import type { TableDo } from "@undb/table"
1210
1311
export let tableId: string | undefined
12+
export let table: TableDo | undefined
1413
export let viewId: string | undefined
1514
export let shareId: string | undefined
1615
export let ignoreView: boolean = false
@@ -22,6 +21,7 @@
2221
2322
const getAggregate = createQuery({
2423
queryKey: ["aggregate", widget.id],
24+
enabled: !!tableId,
2525
queryFn: () => {
2626
const agg =
2727
aggregate.type === "count"
@@ -30,15 +30,15 @@
3030
if (shareId) {
3131
return trpc.shareData.aggregate.query({
3232
shareId,
33-
tableId,
33+
tableId: tableId!,
3434
viewId,
3535
aggregate: agg,
3636
condition: aggregate.condition,
3737
ignoreView,
3838
})
3939
}
4040
return trpc.record.aggregate.query({
41-
tableId,
41+
tableId: tableId!,
4242
viewId,
4343
aggregate: agg,
4444
condition: aggregate.condition,
@@ -51,13 +51,13 @@
5151
if (aggregate.type === "count") {
5252
return ($data.data as any)?.[ID_TYPE]
5353
}
54-
if (aggregate.config.field) {
55-
const field = $table.schema.getFieldByIdOrName(aggregate.config.field)
54+
if (aggregate.config.field && table) {
55+
const field = table.schema.getFieldByIdOrName(aggregate.config.field)
5656
if (field.isSome()) {
5757
return field.unwrap().formatAggregate(aggregate.type, ($data.data as any)?.[aggregate.config.field])
5858
}
5959
}
60-
return null
60+
return undefined
6161
})
6262
$: isPending = $getAggregate.isPending
6363
</script>

apps/frontend/src/lib/components/blocks/aggregate/config/aggregate-config.svelte

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import { tick } from "svelte"
2424
import { toast } from "svelte-sonner"
2525
import { getDashboard, getIsDashboard } from "$lib/store/dashboard.store"
26+
import type { TableDo } from "@undb/table"
2627
28+
export let table: TableDo | undefined
2729
export let viewId: string | undefined
2830
export let tableId: string | undefined
2931
export let widget: IWidgetDTO
@@ -33,22 +35,21 @@
3335
const isDashboard = getIsDashboard()
3436
const dashboard = getDashboard()
3537
36-
const table = getTable()
3738
const value = writable<MaybeConditionGroup<IAggregateCondition> | undefined>(
3839
toMaybeConditionGroup(aggregate.condition),
3940
)
40-
$: validValue = $value && $table ? parseValidAggregateCondition($table.schema, $value) : undefined
41-
$: visibleFields = $table?.getOrderedVisibleFields()
41+
$: validValue = $value && table ? parseValidAggregateCondition(table.schema, $value) : undefined
42+
$: visibleFields = table?.getOrderedVisibleFields() ?? []
4243
4344
const client = useQueryClient()
4445
4546
const updateWidgetMutation = createMutation({
4647
mutationFn: trpc.table.view.widget.update.mutate,
4748
async onSuccess(data, variables, context) {
48-
if ($table) {
49-
await invalidate(`table:${$table.id.value}`)
49+
if (table) {
50+
await invalidate(`table:${table.id.value}`)
5051
await tick()
51-
await client.invalidateQueries({ queryKey: ["aggregate", $table.id.value, widget.id] })
52+
await client.invalidateQueries({ queryKey: ["aggregate", table.id.value, widget.id] })
5253
}
5354
onSuccess()
5455
},
@@ -60,10 +61,10 @@
6061
const updateDashboardWidget = createMutation({
6162
mutationFn: trpc.dashboard.widget.update.mutate,
6263
async onSuccess(data, variables, context) {
63-
if ($table) {
64+
if (table) {
6465
await invalidate(`dashboard:${$dashboard.id.value}`)
6566
await tick()
66-
await client.invalidateQueries({ queryKey: ["aggregate", $table.id.value, widget.id] })
67+
await client.invalidateQueries({ queryKey: ["aggregate", table.id.value, widget.id] })
6768
}
6869
onSuccess()
6970
},
@@ -94,11 +95,11 @@
9495
},
9596
})
9697
} else {
97-
if (!viewId || !$table) {
98+
if (!viewId || !table) {
9899
return
99100
}
100101
$updateWidgetMutation.mutate({
101-
tableId: $table.id.value,
102+
tableId: table.id.value,
102103
viewId,
103104
widget: {
104105
...widget,
@@ -153,12 +154,15 @@
153154
bind:value={widget.item.aggregate.type}
154155
onValueChange={() => (widget.item.aggregate.config.field = undefined)}
155156
/>
156-
<FieldPicker
157-
bind:value={widget.item.aggregate.config.field}
158-
class="w-full flex-1"
159-
placeholder="Select a field to aggregate..."
160-
filter={(field) => filterAggregateField(field.type, widget.item.aggregate?.type)}
161-
/>
157+
{#if table}
158+
<FieldPicker
159+
table={writable(table)}
160+
bind:value={widget.item.aggregate.config.field}
161+
class="w-full flex-1"
162+
placeholder="Select a field to aggregate..."
163+
filter={(field) => filterAggregateField(field.type, widget.item.aggregate?.type)}
164+
/>
165+
{/if}
162166
{/if}
163167
</Tabs.Content>
164168
</Tabs.Root>
@@ -168,11 +172,12 @@
168172
<div class="text-sm font-medium">Filters</div>
169173
</div>
170174

171-
{#if $table}
175+
{#if table}
172176
<FiltersEditor
173177
bind:value={$value}
174-
table={$table}
175-
filter={(field) => visibleFields.some((f) => f.id.value === field.id) && getIsFilterableFieldType(field.type)}
178+
{table}
179+
filter={(field) =>
180+
visibleFields?.some((f) => f.id.value === field.id) && getIsFilterableFieldType(field.type)}
176181
class="rounded-md border"
177182
></FiltersEditor>
178183
{/if}

apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { TableFactory, type IWidgetDTO } from "@undb/table"
33
import { GetDashboardWidgetTableStore } from "$houdini"
44
import { onMount } from "svelte"
5-
import { GripVerticalIcon } from "lucide-svelte"
65
import Widget from "../widget/widget.svelte"
76
import { setTable } from "$lib/store/table.store"
87
import { writable } from "svelte/store"
@@ -13,18 +12,17 @@
1312
export let resizePointerDown: ((e: Event) => void) | undefined = undefined
1413
1514
const store = new GetDashboardWidgetTableStore()
16-
onMount(() => {
17-
if (tableId) {
18-
store.fetch({ variables: { tableId } })
19-
}
20-
})
15+
16+
$: if (tableId) {
17+
store.fetch({ variables: { tableId } })
18+
}
2119
2220
$: table = $store.data?.table
21+
$: tableDo = table ? new TableFactory().fromJSON(table) : undefined
2322
24-
$: if (table) {
25-
const t = new TableFactory().fromJSON(table)
26-
setTable(writable(t))
23+
$: if (tableDo) {
24+
setTable(writable(tableDo))
2725
}
2826
</script>
2927

30-
<Widget {widget} {tableId} {movePointerDown} {resizePointerDown} />
28+
<Widget table={tableDo} {widget} {tableId} {movePointerDown} {resizePointerDown} />

apps/frontend/src/lib/components/blocks/delete-record/confirm-delete-record.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import { createMutation, useQueryClient } from "@tanstack/svelte-query"
88
import { queryParam } from "sveltekit-search-params"
99
import { toast } from "svelte-sonner"
10+
import Button from "$lib/components/ui/button/button.svelte"
11+
import { Loader2Icon } from "lucide-svelte"
1012
1113
const deleteRecordId = queryParam("deleteRecordId")
1214
@@ -61,8 +63,13 @@
6163
>
6264
Cancel
6365
</AlertDialog.Cancel>
64-
<AlertDialog.Action class="text-background bg-red-500 hover:bg-red-600" on:click={onDelete}>
65-
Delete
66+
<AlertDialog.Action asChild>
67+
<Button on:click={onDelete} variant="destructive" disabled={$deleteRecordMutation.isPending}>
68+
{#if $deleteRecordMutation.isPending}
69+
<Loader2Icon class="mr-2 size-3 animate-spin" />
70+
{/if}
71+
Delete
72+
</Button>
6673
</AlertDialog.Action>
6774
</AlertDialog.Footer>
6875
</AlertDialog.Content>

apps/frontend/src/lib/components/blocks/view-widget/view-widget-sheet.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@
6666
{#if $widgets.length}
6767
<div class="flex-1 space-y-3 overflow-y-auto" bind:this={widgetsContainer}>
6868
{#each $widgets as widget}
69-
<Widget {shareId} {widget} viewId={$view.id.value} tableId={$table.id.value} class="h-[180px]" />
69+
<Widget
70+
table={$table}
71+
{shareId}
72+
{widget}
73+
viewId={$view.id.value}
74+
tableId={$table.id.value}
75+
class="h-[180px]"
76+
/>
7077
{/each}
7178
</div>
7279
{:else}

apps/frontend/src/lib/components/blocks/widget/widget.svelte

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import type { IWidgetDTO } from "@undb/table"
2+
import type { IWidgetDTO, TableDo } from "@undb/table"
33
import { EllipsisIcon, PencilIcon, Maximize2Icon } from "lucide-svelte"
44
import Aggregate from "../aggregate/aggregate.svelte"
55
import AggregateConfig from "../aggregate/config/aggregate-config.svelte"
@@ -19,7 +19,7 @@
1919
import { GripVerticalIcon, ChevronRightIcon } from "lucide-svelte"
2020
2121
export let tableId: string | undefined
22-
const table = getTable()
22+
export let table: TableDo | undefined
2323
2424
export let widget: IWidgetDTO
2525
export let viewId: string | undefined = undefined
@@ -40,7 +40,7 @@
4040
mutationFn: trpc.table.view.widget.delete.mutate,
4141
onSuccess: async () => {
4242
confirmDelete = false
43-
if ($table) {
43+
if (table) {
4444
await invalidate(`table:${tableId}`)
4545
}
4646
},
@@ -63,7 +63,7 @@
6363
})
6464
</script>
6565

66-
<div class={cn("group absolute flex h-full w-full flex-col rounded-sm border", $$restProps.class)}>
66+
<div class={cn("group flex h-full w-full flex-col rounded-sm border", $$restProps.class)}>
6767
<div class="flex items-center justify-between p-2">
6868
<div class="flex items-center gap-0.5">
6969
{#if movePointerDown}
@@ -102,8 +102,9 @@
102102

103103
<div class="flex h-full flex-1">
104104
<div class="w-3/4 pr-4">
105-
{#if widget.item.type === "aggregate"}
105+
{#if widget.item.type === "aggregate" && table}
106106
<Aggregate
107+
{table}
107108
{tableId}
108109
{widget}
109110
{viewId}
@@ -116,8 +117,9 @@
116117
</div>
117118
<div class="flex w-1/4 flex-col border-l px-4 py-2">
118119
<div class="flex-1">
119-
{#if widget.item.type === "aggregate"}
120+
{#if widget.item.type === "aggregate" && table}
120121
<AggregateConfig
122+
{table}
121123
{tableId}
122124
{viewId}
123125
{widget}
@@ -157,8 +159,8 @@
157159
</div>
158160
{/if}
159161
</div>
160-
{#if widget.item.type === "aggregate"}
161-
<Aggregate {tableId} {ignoreView} {widget} {viewId} {shareId} aggregate={widget.item.aggregate} />
162+
{#if widget.item.type === "aggregate" && table}
163+
<Aggregate {table} {tableId} {ignoreView} {widget} {viewId} {shareId} aggregate={widget.item.aggregate} />
162164
{/if}
163165

164166
{#if resizePointerDown}

0 commit comments

Comments
 (0)