-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
680 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ enum FieldType { | |
createdBy | ||
currency | ||
date | ||
duration | ||
id | ||
json | ||
|
27 changes: 27 additions & 0 deletions
27
apps/frontend/src/lib/components/blocks/duration/duration-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts"> | ||
import { durationToMilliseconds, isDurationString, millisecondsToDuration } from "@undb/table" | ||
export let value: number | undefined | ||
export let onValueChange: ((value: number) => void) | undefined = undefined | ||
let internalValue = value ? millisecondsToDuration(value) : "" | ||
export let isValid = true | ||
function onChange(event: Event) { | ||
const valueString = (event.target as HTMLInputElement).value | ||
if (!isDurationString(valueString)) { | ||
isValid = false | ||
return | ||
} | ||
isValid = true | ||
internalValue = valueString | ||
value = durationToMilliseconds(valueString) | ||
onValueChange?.(value) | ||
} | ||
</script> | ||
|
||
<input value={internalValue} on:change={onChange} {...$$restProps} /> |
17 changes: 17 additions & 0 deletions
17
apps/frontend/src/lib/components/blocks/field-control/duration-control.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
import { cn } from "$lib/utils" | ||
import DurationInput from "$lib/components/blocks/duration/duration-input.svelte" | ||
export let readonly = false | ||
export let value: number | ||
</script> | ||
|
||
<DurationInput | ||
bind:value | ||
disabled={readonly} | ||
{...$$restProps} | ||
class={cn( | ||
"border-input placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-md border bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50", | ||
$$restProps.class, | ||
)} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
apps/frontend/src/lib/components/blocks/field-options/duration-field-option.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<script lang="ts"> | ||
import { Checkbox } from "$lib/components/ui/checkbox" | ||
import NumberInput from "$lib/components/ui/input/number-input.svelte" | ||
import { Label } from "$lib/components/ui/label/index.js" | ||
import { Separator } from "$lib/components/ui/separator" | ||
import { DurationFieldConstraint, type IDurationFieldConstraint } from "@undb/table" | ||
import * as Alert from "$lib/components/ui/alert/index.js" | ||
export let constraint: IDurationFieldConstraint | undefined | ||
export let display: boolean | undefined | ||
export let defaultValue: number | undefined | ||
export let disabled = false | ||
$: c = constraint ? new DurationFieldConstraint(constraint) : undefined | ||
$: isDefaultValueValid = c && defaultValue ? c.schema.safeParse(defaultValue).success : true | ||
</script> | ||
|
||
<div class="space-y-2"> | ||
<div class="space-y-1"> | ||
<Label for="defaultValue" class="text-xs font-normal">Default value</Label> | ||
<NumberInput | ||
{disabled} | ||
id="defaultValue" | ||
class="bg-background flex-1 text-xs" | ||
placeholder="Default value..." | ||
bind:value={defaultValue} | ||
/> | ||
</div> | ||
|
||
{#if !isDefaultValueValid} | ||
<Alert.Root class="border-yellow-500 bg-yellow-50"> | ||
<Alert.Title>Invalid default value</Alert.Title> | ||
<Alert.Description>Your default value is invalid. Default value will not be saved.</Alert.Description> | ||
</Alert.Root> | ||
{/if} | ||
{#if constraint} | ||
<div class="grid grid-cols-2 gap-2"> | ||
<div class="space-y-1"> | ||
<Label for="min" class="text-xs font-normal">Min</Label> | ||
<NumberInput | ||
{disabled} | ||
id="min" | ||
min={0} | ||
max={constraint.max} | ||
step={1} | ||
bind:value={constraint.min} | ||
placeholder="Min value..." | ||
class="bg-background text-xs" | ||
/> | ||
</div> | ||
<div class="space-y-1"> | ||
<Label for="max" class="text-xs font-normal">Max</Label> | ||
<NumberInput | ||
{disabled} | ||
id="max" | ||
min={constraint.min || 0} | ||
step={1} | ||
bind:value={constraint.max} | ||
placeholder="Max value..." | ||
class="bg-background text-xs" | ||
/> | ||
</div> | ||
</div> | ||
|
||
<div class="pt-2"> | ||
<Separator /> | ||
</div> | ||
<div class="flex items-center space-x-2"> | ||
<Checkbox id="required" {disabled} bind:checked={constraint.required} /> | ||
<Label for="required" class="text-xs font-normal">Mark as required field.</Label> | ||
</div> | ||
|
||
<div class="flex items-center space-x-2"> | ||
<Checkbox id="display" {disabled} bind:checked={display} /> | ||
<Label for="display" class="text-xs font-normal">Mark as display field.</Label> | ||
</div> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
apps/frontend/src/lib/components/blocks/field-value/duration-field.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script lang="ts"> | ||
import { millisecondsToDuration } from "@undb/table" | ||
export let value: number | undefined = undefined | ||
</script> | ||
|
||
<span class={$$restProps.class}>{value ? millisecondsToDuration(value) : ""}</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
apps/frontend/src/lib/components/blocks/grid-view/editable-cell/duration-cell.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script lang="ts"> | ||
import { trpc } from "$lib/trpc/client" | ||
import { cn } from "$lib/utils" | ||
import { createMutation } from "@tanstack/svelte-query" | ||
import { DurationField, millisecondsToDuration } from "@undb/table" | ||
import { toast } from "svelte-sonner" | ||
import { debounce, isNumber } from "radash" | ||
import { gridViewStore } from "../grid-view.store" | ||
import DurationInput from "$lib/components/blocks/duration/duration-input.svelte" | ||
export let tableId: string | ||
export let field: DurationField | ||
export let value: number | ||
export let isEditing: boolean | ||
export let recordId: string | ||
export let onValueChange: (value: number) => void | ||
const updateCell = createMutation({ | ||
mutationKey: ["record", tableId, field.id.value, recordId], | ||
mutationFn: trpc.record.update.mutate, | ||
onSuccess(data, variables, context) { | ||
gridViewStore.exitEditing() | ||
}, | ||
onError(error: Error) { | ||
toast.error(error.message) | ||
}, | ||
}) | ||
const onChange = (value: number) => { | ||
onValueChange(value) | ||
$updateCell.mutate({ | ||
tableId, | ||
id: recordId, | ||
values: { [field.id.value]: value }, | ||
}) | ||
} | ||
</script> | ||
|
||
{#if isEditing} | ||
<DurationInput | ||
onValueChange={debounce({ delay: 300 }, onChange)} | ||
max={field.max} | ||
min={field.min} | ||
class={cn($$restProps.class, "focus-visible:ring-ring w-full rounded-none border-none outline-none focus:bg-white")} | ||
{value} | ||
/> | ||
{:else} | ||
<div class={$$restProps.class}> | ||
{#if isNumber(value)} | ||
{millisecondsToDuration(value)} | ||
{/if} | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,7 @@ export class Graphql { | |
json | ||
checkbox | ||
user | ||
duration | ||
} | ||
type Field { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.