Skip to content

Commit

Permalink
Merge pull request #2146 from undb-io/release/v1.0.0-121
Browse files Browse the repository at this point in the history
Release version v1.0.0-121
  • Loading branch information
nichenqin authored Nov 19, 2024
2 parents 67694ea + d2feba5 commit 35f21be
Show file tree
Hide file tree
Showing 83 changed files with 2,215 additions and 416 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-121


### 🏡 Chore

- Update config ([2de647e](https://github.com/undb-io/undb/commit/2de647e))

### ❤️ Contributors

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

## v1.0.0-120


Expand Down
34 changes: 33 additions & 1 deletion apps/backend/src/modules/openapi/record.openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import { CommandBus, QueryBus } from "@undb/cqrs"
import { inject, singleton } from "@undb/di"
import { Option, type ICommandBus, type IQueryBus, type PaginatedDTO } from "@undb/domain"
import { injectQueryBuilder, type IQueryBuilder } from "@undb/persistence"
import { GetPivotDataQuery, GetReadableRecordByIdQuery, GetReadableRecordsQuery } from "@undb/queries"
import {
GetAggregatesQuery,
GetPivotDataQuery,
GetReadableRecordByIdQuery,
GetReadableRecordsQuery,
} from "@undb/queries"
import { RecordDO, type IRecordReadableValueDTO } from "@undb/table"
import Elysia, { t } from "elysia"
import { withTransaction } from "../../db"
Expand Down Expand Up @@ -97,6 +102,33 @@ export class RecordOpenApi {
},
},
)
.get(
"/views/:viewName/records/aggregate",
async (ctx) => {
const baseName = decodeURIComponent(ctx.params.baseName)
const tableName = decodeURIComponent(ctx.params.tableName)
const viewName = decodeURIComponent(ctx.params.viewName)

const result = await this.queryBus.execute(
new GetAggregatesQuery({ baseName, tableName, viewName, isReadable: true }),
)
return {
data: result,
}
},
{
params: t.Object({
baseName: t.String(),
tableName: t.String(),
viewName: t.String(),
}),
detail: {
tags: ["Record", "Aggregate"],
summary: "Get record aggregate in view",
description: "Get record aggregate in view",
},
},
)
.get(
"/views/:viewName/records/:recordId",
async (ctx) => {
Expand Down
7 changes: 7 additions & 0 deletions apps/frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ type Base {

type CalendarOption {
field: String
timeScale: CalendarTimeScale
}

enum CalendarTimeScale {
day
month
week
}

type Dashboard {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
await tick()
await client.invalidateQueries({ queryKey: ["aggregate", table.id.value, widget.id] })
}
if (isDashboard) {
await invalidate(`undb:dashboard:${$dashboard.id.value}`)
await tick()
}
onSuccess()
},
onError(error, variables, context) {
Expand All @@ -61,7 +65,7 @@
mutationFn: trpc.dashboard.widget.update.mutate,
async onSuccess(data, variables, context) {
if (table) {
await invalidate(`dashboard:${$dashboard.id.value}`)
await invalidate(`undb:dashboard:${$dashboard.id.value}`)
await tick()
await client.invalidateQueries({ queryKey: ["aggregate", table.id.value, widget.id] })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { createMutation } from "@tanstack/svelte-query"
import { useQueryClient } from "@tanstack/svelte-query"
import { cn } from "$lib/utils"
import { monthStore } from "$lib/store/calendar.store"
import { calendarStore } from "$lib/store/calendar.store"
export let view: CalendarView
Expand Down Expand Up @@ -69,6 +69,6 @@
}
</script>

<button use:setupDropTarget class={cn("hidden transition-opacity", $monthStore.isDragging && "block")}>
<button use:setupDropTarget class={cn("hidden transition-opacity", $calendarStore.isDragging && "block")}>
<Trash2Icon class={cn("size-10 text-gray-600", isDraggedOver && "text-red-600")} />
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

<Dropdown.Root>
<Dropdown.Trigger asChild let:builder>
<Button variant="ghost" size="sm" class="gap-1" builders={[builder]} {...$$restProps}>
<Button variant="ghost" size="sm" class="group gap-1" builders={[builder]} {...$$restProps}>
<CalendarIcon class="text-muted-foreground mr-2 h-4 w-4 font-semibold" />
Calendar
{#if field}
<span>by</span>
<span class="inline-flex items-center gap-1 rounded-sm bg-gray-100 px-1.5 py-0.5">
<span class="inline-flex items-center gap-1 rounded-sm bg-gray-100 px-1.5 py-0.5 group-hover:bg-gray-200">
<FieldIcon type={field.type} {field} class="size-3 text-gray-700" />
{field.name.value}
</span>
Expand All @@ -38,6 +38,6 @@
Calendar view
{/if}
</Dropdown.Label>
<CalendarFieldForm {view} {readonly} />
<CalendarFieldForm bind:view {readonly} />
</Dropdown.Content>
</Dropdown.Root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<script lang="ts">
import Check from "svelte-radix/Check.svelte"
import CaretSort from "svelte-radix/CaretSort.svelte"
import { tick } from "svelte"
import * as Command from "$lib/components/ui/command/index.js"
import * as Popover from "$lib/components/ui/popover/index.js"
import * as Tooltip from "$lib/components/ui/tooltip"
import { Button } from "$lib/components/ui/button/index.js"
import { cn } from "$lib/utils.js"
import { LL } from "@undb/i18n/client"
import { calendarTimeScales, type CalendarTimeScale, type CalendarView } from "@undb/table"
import { createMutation } from "@tanstack/svelte-query"
import { trpc } from "$lib/trpc/client"
import { toast } from "svelte-sonner"
import { getTable } from "$lib/store/table.store"
import { invalidate } from "$app/navigation"
import { type ICalendarViewDTO } from "@undb/table"
export let view: CalendarView
const table = getTable()
let open = false
let search = ""
$: filtered = calendarTimeScales.filter((scale) => {
const label = $LL.table.timeScales[scale]() ?? scale
return label.toLowerCase().includes(search.toLowerCase())
})
$: selected = view.timeScale
$: selectedValue = selected ?? "Select time scale..."
function closeAndFocusTrigger(triggerId: string) {
open = false
tick().then(() => {
document.getElementById(triggerId)?.focus()
})
}
const updateViewMutation = createMutation({
mutationFn: trpc.table.view.update.mutate,
mutationKey: ["updateView"],
async onSuccess(data, variables, context) {
await invalidate(`undb:table:${$table.id.value}`)
},
})
function onSelect(scale: string) {
view.timeScale = scale as CalendarTimeScale
const json = view.toJSON() as ICalendarViewDTO
$updateViewMutation.mutate({
tableId: $table.id.value,
viewId: view.id.value,
...json,
calendar: {
...json.calendar,
timeScale: view.timeScale,
},
})
}
</script>

<Popover.Root bind:open let:ids portal="body">
<Popover.Trigger asChild let:builder={popoverBuilder}>
<Tooltip.Root portal="body">
<Tooltip.Trigger asChild let:builder>
<Button
size="sm"
builders={[popoverBuilder, builder]}
variant="outline"
role="combobox"
aria-expanded={open}
{...$$restProps}
class={cn("w-full justify-between", $$restProps.class)}
>
<span class="flex items-center overflow-hidden text-ellipsis" title={selectedValue}>
{#if selected}
<slot>
{$LL.table.timeScales[selected]() ?? selected}
</slot>
{/if}
</span>
<CaretSort class="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</Tooltip.Trigger>
<Tooltip.Content>
<p>Select time scale</p>
</Tooltip.Content>
</Tooltip.Root>
</Popover.Trigger>
<Popover.Content class="p-0">
<Command.Root shouldFilter={false}>
<Command.Input bind:value={search} placeholder="Search time scale..." class="h-9" />
<Command.Empty>No time scale found.</Command.Empty>
<Command.Group class="max-h-[300px] overflow-y-auto">
{#each filtered as scale}
<Command.Item
value={scale}
onSelect={(value) => {
onSelect(value)
closeAndFocusTrigger(ids.trigger)
}}
>
<Check class={cn("mr-2 h-4 w-4", selected !== scale && "text-transparent")} />
<span class="text-xs">
{$LL.table.timeScales[scale]() ?? scale}
</span>
</Command.Item>
{/each}
</Command.Group>
</Command.Root>
</Popover.Content>
</Popover.Root>
Loading

0 comments on commit 35f21be

Please sign in to comment.