Skip to content

Commit

Permalink
fix: fix duration field display
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Sep 19, 2024
1 parent 01afb82 commit 761387f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import Input from "$lib/components/ui/input/input.svelte"
import { durationToMilliseconds, isDurationString, millisecondsToDuration } from "@undb/table"
export let value: number | undefined
Expand All @@ -24,4 +25,4 @@
}
</script>

<input value={internalValue} on:change={onChange} {...$$restProps} />
<Input placeholder="hh:mm" value={internalValue} on:change={onChange} {...$$restProps} />
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import IdFilterInput from "./variants/id-filter-input.svelte"
import OptionFilterInput from "./variants/option-filter-input.svelte"
import OptionsFilterInput from "./variants/options-filter-input.svelte"
import type { ComponentIcon } from "lucide-svelte"
import DurationInput from "$lib/components/blocks/duration/duration-input.svelte"
export let field: Field | undefined
export let recordId: string | undefined = undefined
Expand Down Expand Up @@ -188,8 +188,12 @@
}
const duration: Record<IDurationFieldConditionOp, ComponentType | null> = {
eq: NumberInput,
neq: NumberInput,
eq: DurationInput,
neq: DurationInput,
gt: DurationInput,
gte: DurationInput,
lt: DurationInput,
lte: DurationInput,
is_empty: null,
is_not_empty: null,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
onValueChange={debounce({ delay: 300 }, onChange)}
max={field.max}
min={field.min}
autofocus
class={cn($$restProps.class, "focus-visible:ring-ring w-full rounded-none border-none outline-none focus:bg-white")}
{value}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { z } from "@undb/zod"

export const durationFieldAggregate = z.enum([
//
"count",
"sum",
"avg",
"max",
"min",
"count_empty",
"count_uniq",
"count_not_empty",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export function createDurationFieldCondition<ItemType extends z.ZodTypeAny>(item
return z.union([
z.object({ op: z.literal("eq"), value: z.number() }).merge(base),
z.object({ op: z.literal("neq"), value: z.number() }).merge(base),
// TODO: gt lt etc
z.object({ op: z.literal("gt"), value: z.number() }).merge(base),
z.object({ op: z.literal("gte"), value: z.number() }).merge(base),
z.object({ op: z.literal("lt"), value: z.number() }).merge(base),
z.object({ op: z.literal("lte"), value: z.number() }).merge(base),
z.object({ op: z.literal("is_empty"), value: z.undefined() }).merge(base),
z.object({ op: z.literal("is_not_empty"), value: z.undefined() }).merge(base),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { RecordComositeSpecification } from "../../../../records/record/rec
import { fieldId, FieldIdVo } from "../../field-id.vo"
import type { IFieldVisitor } from "../../field.visitor"
import { AbstractField, baseFieldDTO, createBaseFieldDTO } from "../abstract-field.vo"
import { NumberGT, NumberGTE, NumberLT, NumberLTE } from "../abstractions/abstract-number-value.specification"
import { StringEmpty } from "../string-field"
import { DurationFieldConstraint, durationFieldConstraint } from "./duration-field-constraint.vo"
import { durationFieldValue, DurationFieldValue } from "./duration-field-value.vo"
Expand Down Expand Up @@ -95,6 +96,10 @@ export class DurationField extends AbstractField<DurationFieldValue, DurationFie
const spec = match(condition)
.with({ op: "eq" }, ({ value }) => new DurationEqual(value, this.id))
.with({ op: "neq" }, ({ value }) => new DurationEqual(value, this.id).not())
.with({ op: "gt" }, ({ value }) => new NumberGT(value, this.id))
.with({ op: "gte" }, ({ value }) => new NumberGTE(value, this.id))
.with({ op: "lt" }, ({ value }) => new NumberLT(value, this.id))
.with({ op: "lte" }, ({ value }) => new NumberLTE(value, this.id))
.with({ op: "is_empty" }, () => new StringEmpty(this.id))
.with({ op: "is_not_empty" }, () => new StringEmpty(this.id).not())
.exhaustive()
Expand Down

0 comments on commit 761387f

Please sign in to comment.