Skip to content

Commit

Permalink
Merge pull request #2065 from undb-io/release/v1.0.0-89
Browse files Browse the repository at this point in the history
Release version v1.0.0-89
  • Loading branch information
nichenqin authored Sep 24, 2024
2 parents 3f9a94a + 471e740 commit c7e2d9a
Show file tree
Hide file tree
Showing 25 changed files with 780 additions and 24 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-89


### 🩹 Fixes

- Fix import table data ([6f3c4ec](https://github.com/undb-io/undb/commit/6f3c4ec))

### ❤️ Contributors

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

## v1.0.0-88


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import CreateRecord from "./create-record.svelte"
import Button from "$lib/components/ui/button/button.svelte"
import { formId } from "$lib/store/tab.store"
import { modal, CREATE_RECORD_MODAL, closeModal } from "$lib/store/modal.store"
import { isModalOpen, CREATE_RECORD_MODAL, closeModal } from "$lib/store/modal.store"
import { ScrollArea } from "$lib/components/ui/scroll-area"
import { getTable } from "$lib/store/table.store"
import { useIsMutating } from "@tanstack/svelte-query"
Expand All @@ -24,7 +24,7 @@
</script>

<Sheet.Root
open={$modal?.includes(CREATE_RECORD_MODAL) ?? false}
open={$isModalOpen(CREATE_RECORD_MODAL)}
onOpenChange={(open) => {
if (!open) {
closeModal(CREATE_RECORD_MODAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { defaultRecordValues, getRecordsStore } from "$lib/store/records.store"
import { useMediaQuery } from "$lib/store/media-query.store"
import IdControl from "../field-control/id-control.svelte"
import type { ICreateRecordCommandOutput } from "@undb/commands"
// beforeNavigate(({ cancel }) => {
// if ($tainted) {
Expand Down Expand Up @@ -42,7 +43,7 @@
derived([table], ([$table]) => ({
mutationFn: trpc.record.create.mutate,
mutationKey: [$table.id.value, "createRecord"],
onSuccess: (data) => {
onSuccess: (data: ICreateRecordCommandOutput) => {
client.invalidateQueries({
queryKey: ["records", $table.id.value],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,14 @@
</Label>
<Label class="flex items-center gap-2">
<Checkbox disabled={$createTable.isPending || $createRecords.isPending} bind:checked={importData} />
Import Data
<span>Import Data</span>

{#if (data?.data.length ?? 0) > 1}
<span>({(data?.data.length ?? 0) - 1} rows)</span>
{/if}
</Label>
{#if data && file && schema}
<div class="p-3">
<div class="space-y-2">
<Label class="flex items-center gap-2">
<div>Name</div>
<Input disabled={$createTable.isPending || $createRecords.isPending} class="text-sm" bind:value={tableName} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
derived([table, viewId, q], ([$table, $viewId, $q]) => {
const view = $table.views.getViewById($viewId)
return {
queryKey: [$table.id.value, $viewId, fieldId, "getRecords", option?.id, $q],
queryKey: ["records", $table.id.value, $viewId, fieldId, option?.id, $q],
queryFn: ({ pageParam = 1 }) => {
if (shareId) {
return trpc.shareData.records.query({
Expand Down Expand Up @@ -315,7 +315,7 @@
>
{#if !readonly && $hasPermission("record:create")}
{#if $query.isFetchedAfterMount}
{#if $query.data?.pages[0]?.total > 0}
{#if recordDos.length > 0}
<Button on:click={onCreateRecord} variant="outline" size="sm" class="w-full">
<PlusIcon class="text-muted-foreground mr-2 h-4 w-4 font-semibold" />
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
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
Expand Up @@ -79,19 +79,21 @@
<Collapsible.Root bind:open={open[base.id]}>
<div
class={cn(
"group flex h-8 items-center justify-between gap-1 pl-4 pr-2 transition-all",
"group flex h-8 items-center justify-between gap-1 overflow-hidden pl-4 pr-2 transition-all",
active && !tableId && !viewId ? "text-background rounded-md bg-gray-800/90" : "hover:bg-gray-100",
)}
>
<a
class={cn(
"flex h-full flex-1 items-center font-normal text-gray-600",
"flex h-full flex-1 items-center overflow-hidden font-normal text-gray-600",
active && !tableId && !viewId && "text-background font-medium",
)}
href={`/bases/${base.id}`}
>
<HardDriveIcon class="mr-2 h-4 w-4" />
{base.name}
<span class="truncate">
{base.name}
</span>
</a>

<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
const table = getTable()
$: filter = $table.views.getViewById($viewId).filter.into(undefined)
$: console.log($viewId, filter)
$: count = filter?.count ?? 0
const value = writable<MaybeConditionGroup<IViewFilterOptionSchema> | undefined>()
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-88",
"version": "1.0.0-89",
"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["projectManagement"]
const template = templates["officeInventoryManagement"]

const spaceId = mustGetCurrentSpaceId()
const result = await this.templateService.createBase(template, spaceId)
Expand Down
6 changes: 5 additions & 1 deletion packages/commands/src/create-record.command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Command, type CommandProps } from "@undb/domain"
import type { IRecordValues } from "@undb/table"
import { createRecordDTO, uniqueTableDTO } from "@undb/table"
import { createRecordDTO, recordId, uniqueTableDTO } from "@undb/table"
import { z } from "@undb/zod"

export const createRecordCommand = createRecordDTO.merge(uniqueTableDTO)

export type ICreateRecordCommand = z.infer<typeof createRecordCommand>

export const createRecordCommandOutput = recordId

export type ICreateRecordCommandOutput = z.infer<typeof createRecordCommandOutput>

export class CreateRecordCommand extends Command implements ICreateRecordCommand {
public readonly id?: string | null
public readonly tableId?: string
Expand Down
5 changes: 4 additions & 1 deletion packages/table/src/modules/records/record/record.do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export class RecordDO extends AggregateRoot<IRecordEvent> {
}

static create(table: TableDo, dto: ICreateRecordDTO) {
const record = new RecordDO(RecordIdVO.fromStringOrCreate(dto.id), RecordValuesVO.create(table, dto.values))
const record = new RecordDO(
RecordIdVO.fromStringOrCreate(dto.id ?? undefined),
RecordValuesVO.create(table, dto.values),
)

const event = RecordCreatedEvent.create(table, record)
record.addDomainEvent(event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { IFieldVisitor } from "../../field.visitor"
import { AbstractField, baseFieldDTO, createBaseFieldDTO } from "../abstract-field.vo"
import { createAbstractDateConditionMather } from "../abstractions/abstract-date-field.condition"
import { abstractDateAggregate } from "../abstractions/abstract-date.aggregate"
import { DateFieldConstraint } from "./date-field-constraint.vo"
import { dateFieldConstraint, DateFieldConstraint } from "./date-field-constraint.vo"
import { dateFieldValue, DateFieldValue } from "./date-field-value.vo"
import {
createDateFieldCondition,
Expand All @@ -22,6 +22,7 @@ export const DATE_TYPE = "date" as const

export const createDateFieldDTO = createBaseFieldDTO.extend({
type: z.literal(DATE_TYPE),
constraint: dateFieldConstraint.optional(),
defaultValue: dateFieldValue,
})

Expand All @@ -33,6 +34,7 @@ export type IUpdateDateFieldDTO = z.infer<typeof updateDateFieldDTO>

export const dateFieldDTO = baseFieldDTO.extend({
type: z.literal(DATE_TYPE),
constraint: dateFieldConstraint.optional(),
defaultValue: dateFieldValue,
})

Expand All @@ -41,6 +43,9 @@ export type IDateFieldDTO = z.infer<typeof dateFieldDTO>
export class DateField extends AbstractField<DateFieldValue> {
constructor(dto: IDateFieldDTO) {
super(dto)
if (dto.constraint) {
this.constraint = Some(new DateFieldConstraint(dto.constraint))
}
if (dto.defaultValue) {
this.defaultValue = new DateFieldValue(dto.defaultValue)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/table/src/modules/views/dto/create-view.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "@undb/zod"
import { tableId } from "../../../table-id.vo"
import { viewColorGroup, viewFields, viewFilterGroup, viewOption, viewSort } from "../view"
import { viewAggregate, viewColorGroup, viewFields, viewFilterGroup, viewOption, viewSort } from "../view"
import { galleryOption } from "../view/variants/gallery-view.vo"
import { kanbanOption } from "../view/variants/kanban-view.vo"
import { viewId } from "../view/view-id.vo"
Expand All @@ -17,6 +17,7 @@ export const createBaseViewDTO = z.object({
color: viewColorGroup.optional(),
sort: viewSort.optional(),
fields: viewFields.optional(),
aggregate: viewAggregate.optional(),
})

export const createGridViewDTO = createBaseViewDTO.extend({
Expand Down
4 changes: 2 additions & 2 deletions packages/table/src/modules/views/views.vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export class Views extends ValueObject {
getViewById(id: string | undefined): View {
let view: View | undefined
if (!id) {
view = this.views.at(0)
view = this.getDefaultView()
} else {
const viewId = new ViewIdVo(id)
view = this.views.find((view) => view.id.equals(viewId)) ?? this.views.at(0)
view = this.views.find((view) => view.id.equals(viewId)) ?? this.getDefaultView()
}
return Option(view).expect("View not found")
}
Expand Down
2 changes: 1 addition & 1 deletion packages/template/src/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./template.dto"
export * from "./template-schema.dto"
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/template/src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./template.schema"
export * from "./template-schema.schema"
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
viewFilterGroup,
} from "@undb/table"
import zodToJsonSchema from "zod-to-json-schema"
import { baseTemplateDTO } from "../dto/template.dto"
import { baseTemplateDTO } from "../dto/template-schema.dto"

export const baseTemplateSchema = zodToJsonSchema(baseTemplateDTO, {
errorMessages: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/template/src/template.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TableFactory,
} from "@undb/table"
import { getNextName } from "@undb/utils"
import { type IBaseTemplateDTO } from "./dto/template.dto"
import { type IBaseTemplateDTO } from "./dto/template-schema.dto"

export class TemplateFactory {
static create(
Expand Down
Loading

0 comments on commit c7e2d9a

Please sign in to comment.