Skip to content

Commit

Permalink
fix: fix circul reference
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Nov 13, 2024
1 parent 75884a1 commit 1e57d4a
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import * as Form from "$lib/components/ui/form"
import { getTable } from "$lib/store/table.store"
import { updatePivotViewDTO, type PivotView } from "@undb/table"
import { isValidColumnLabel, isValidRowLabel, updatePivotViewDTO, type PivotView } from "@undb/table"
import FieldPicker from "../field-picker/field-picker.svelte"
import { defaults, superForm } from "sveltekit-superforms"
import { zodClient } from "sveltekit-superforms/adapters"
Expand Down Expand Up @@ -55,6 +55,19 @@
const { enhance, form: formData } = form
$: columnLabel = $formData.pivot?.columnLabel
$: rowLabel = $formData.pivot?.rowLabel
$: columnField = $columnFields.find((f) => f.id.value === columnLabel)
$: rowField = $rowFields.find((f) => f.id.value === rowLabel)
$: swapEnabled =
columnField &&
rowField &&
columnField.id.value !== rowField.id.value &&
isValidColumnLabel(rowField) &&
isValidRowLabel(columnField)
const updateViewMutation = createMutation({
mutationFn: trpc.table.view.update.mutate,
mutationKey: ["updateView"],
Expand Down Expand Up @@ -102,6 +115,7 @@
<Tooltip.Trigger>
<button
type="button"
disabled={!swapEnabled}
on:click={() => {
if (!$formData.pivot) return
const columnLabel = $formData.pivot?.columnLabel
Expand Down
4 changes: 3 additions & 1 deletion packages/table/src/modules/aggregate/aggregate.vo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ValueObject } from "@undb/domain"
import { z } from "@undb/zod"
import { fieldId, fieldName, type FieldType } from "../schema"
import { createConditionGroup } from "../schema/fields/condition/condition.type"
import { parseValidCondition } from "../schema/fields/condition/condition.util"
import { fieldId } from "../schema/fields/field-id.vo"
import { fieldName } from "../schema/fields/field-name.vo"
import type { FieldType } from "../schema/fields/field.type"

const aggregateCondition = z.undefined()
export type IAggregateCondition = typeof aggregateCondition
Expand Down
2 changes: 1 addition & 1 deletion packages/table/src/modules/chart/chart.vo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValueObject } from "@undb/domain"
import { z } from "@undb/zod"
import { fieldId } from "../schema"
import { fieldId } from "../schema/fields/field-id.vo"

const pieChart = z.object({
type: z.literal("pie"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "@undb/zod"
import { uniqueTableDTO } from "../../../dto/unique-table.dto"
import { fieldId } from "../../schema"
import { fieldId } from "../../schema/fields/field-id.vo"
import { viewId } from "../../views/view/view-id.vo"
import { viewName } from "../../views/view/view-name.vo"
import { recordId } from "../record"
Expand Down
2 changes: 1 addition & 1 deletion packages/table/src/modules/records/dto/get-records.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pagniationSchema } from "@undb/domain"
import { z } from "@undb/zod"
import { uniqueTableDTO } from "../../../dto/unique-table.dto"
import { fieldId } from "../../schema"
import { fieldId } from "../../schema/fields/field-id.vo"
import { viewFilterGroup, viewId, viewName } from "../../views"

export const getRecordsDTO = z
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from "@undb/zod"
import { tableName } from "../../../table-name.vo"
import { fieldId, fieldName } from "../../schema"
import { fieldId } from "../../schema/fields/field-id.vo"
import { fieldName } from "../../schema/fields/field-name.vo"

export const recordEventTableMeta = z.object({
name: tableName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from "@undb/zod"
import { fieldId, fieldName } from "../../../schema"
import { fieldId } from "../../../schema/fields/field-id.vo"
import { fieldName } from "../../../schema/fields/field-name.vo"
import { recordId } from "../record-id.vo"

export const triggerRecordButtonDTO = z.object({
Expand Down
16 changes: 5 additions & 11 deletions packages/table/src/modules/schema/schema.vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
import type { TableDo } from "../../table.do"
import type { FormVO } from "../forms"
import type { IRecordValues } from "../records/record/record-values.vo"
import type { IPivotAggregate, View } from "../views"
import { type IPivotAggregate, type View } from "../views"
import { isValidColumnLabel, isValidRowLabel, isValidValueField } from "../views/view/variants/pivot-view.vo"
import type { ICreateSchemaDTO } from "./dto"
import type { ISchemaDTO } from "./dto/schema.dto"
import {
Expand Down Expand Up @@ -371,20 +372,13 @@ export class Schema extends ValueObject<Field[]> {

getPivotFields(type: "column" | "row", fields: Field[] = this.fields) {
if (type === "column") {
return fields.filter((f) => (f.type === "select" && f.isSingle) || (f.type === "user" && f.isSingle))
return fields.filter(isValidColumnLabel)
}

return fields.filter(
(f) => f.type === "string" || (f.type === "select" && f.isSingle) || (f.type === "user" && f.isSingle),
)
return fields.filter(isValidRowLabel)
}

getPivotValueFields(aggregate: IPivotAggregate, fields: Field[] = this.fields) {
if (aggregate === "count") {
return fields
}
return fields.filter(
(f) => f.type === "number" || f.type === "percentage" || f.type === "currency" || f.type === "rating",
)
return fields.filter((field) => isValidValueField(aggregate, field))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import type { Field } from "../../../schema"
import { WidgetVO, widgetDTO, type IWidgetDTO } from "../../../widgets/widget.vo"
import type { IViewDTO } from "../dto"
import { ViewAggregateVO, viewAggregate, type IViewAggregate } from "../view-aggregate/view-aggregate.vo"
import { ViewColor, viewColorGroup, type IRootViewColor } from "../view-color"
import { ViewFields, viewFields, type IViewFields } from "../view-fields"
import { ViewColor, viewColorGroup, type IRootViewColor } from "../view-color/view-color.vo"
import { ViewFields, viewFields, type IViewFields } from "../view-fields/view-fields.vo"
import { ViewFilter, viewFilterGroup, type IRootViewFilter } from "../view-filter/view-filter.vo"
import { ViewIdVo, viewId, type ViewId } from "../view-id.vo"
import { ViewNameVo, viewName } from "../view-name.vo"
import { ViewOption, viewOption, type IViewOption } from "../view-option.vo"
import { ViewSort, viewSort, type IViewSort } from "../view-sort"
import { ViewSort, viewSort, type IViewSort } from "../view-sort/view-sort.vo"
import type { View, ViewType } from "../view.type"

export const createBaseViewDTO = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from "@undb/zod"
import type { IDuplicateViewDTO } from "../../../../dto/duplicate-view.dto"
import { WithNewView, WithView } from "../../../../specifications/table-view.specification"
import type { TableDo } from "../../../../table.do"
import { fieldId } from "../../../schema"
import { fieldId } from "../../../schema/fields/field-id.vo"
import { ViewIdVo } from "../view-id.vo"
import { AbstractView, baseViewDTO, createBaseViewDTO, updateBaseViewDTO } from "./abstract-view.vo"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from "@undb/zod"
import type { IDuplicateViewDTO } from "../../../../dto/duplicate-view.dto"
import { WithNewView, WithView } from "../../../../specifications/table-view.specification"
import type { TableDo } from "../../../../table.do"
import { fieldId } from "../../../schema"
import { fieldId } from "../../../schema/fields/field-id.vo"
import { ViewIdVo } from "../view-id.vo"
import { AbstractView, baseViewDTO, createBaseViewDTO, updateBaseViewDTO } from "./abstract-view.vo"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from "@undb/zod"
import type { IDuplicateViewDTO } from "../../../../dto/duplicate-view.dto"
import { WithNewView, WithView } from "../../../../specifications/table-view.specification"
import type { TableDo } from "../../../../table.do"
import { fieldId } from "../../../schema"
import { fieldId } from "../../../schema/fields/field-id.vo"
import { ViewIdVo } from "../view-id.vo"
import { AbstractView, baseViewDTO, createBaseViewDTO, updateBaseViewDTO } from "./abstract-view.vo"

Expand Down
20 changes: 19 additions & 1 deletion packages/table/src/modules/views/view/variants/pivot-view.vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { z } from "@undb/zod"
import type { IDuplicateViewDTO } from "../../../../dto/duplicate-view.dto"
import { WithNewView, WithView } from "../../../../specifications/table-view.specification"
import type { TableDo } from "../../../../table.do"
import { fieldId } from "../../../schema"
import { fieldId } from "../../../schema/fields/field-id.vo"
import type { Field } from "../../../schema/fields/field.type"
import { ViewIdVo } from "../view-id.vo"
import { AbstractView, baseViewDTO, createBaseViewDTO, updateBaseViewDTO } from "./abstract-view.vo"

Expand Down Expand Up @@ -147,3 +148,20 @@ export class PivotView extends AbstractView {
return { ...super.toJSON(), pivot: this.pivot.into(undefined) }
}
}

export function isValidColumnLabel(field: Field) {
return (field.type === "select" && field.isSingle) || (field.type === "user" && field.isSingle)
}

export function isValidRowLabel(field: Field) {
return (
field.type === "string" || (field.type === "select" && field.isSingle) || (field.type === "user" && field.isSingle)
)
}

export function isValidValueField(aggregate: IPivotAggregate, field: Field) {
if (aggregate === "count") {
return true
}
return field.type === "number" || field.type === "percentage" || field.type === "currency" || field.type === "rating"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ValueObject } from "@undb/domain"
import { z } from "@undb/zod"
import { isEqual } from "radash"
import type { TableDo } from "../../../../table.do"
import { fieldId, type Field } from "../../../schema"
import { fieldId } from "../../../schema/fields/field-id.vo"
import type { Field } from "../../../schema/fields/field.type"

export const viewField = z.object({
fieldId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ValueObject } from "@undb/domain"
import { z } from "@undb/zod"
import { isEqual } from "radash"
import { fieldId, type Field } from "../../../schema"
import { fieldId } from "../../../schema/fields/field-id.vo"
import type { Field } from "../../../schema/fields/field.type"

export const viewSortOption = z.object({
fieldId,
Expand Down

0 comments on commit 1e57d4a

Please sign in to comment.