-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
41 changed files
with
521 additions
and
12 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 |
---|---|---|
|
@@ -42,6 +42,7 @@ enum FieldType { | |
json | ||
longText | ||
number | ||
percentage | ||
rating | ||
reference | ||
rollup | ||
|
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
29 changes: 29 additions & 0 deletions
29
apps/frontend/src/lib/components/blocks/field-control/percentage-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,29 @@ | ||
<script lang="ts"> | ||
import { Slider } from "$lib/components/ui/slider" | ||
import * as Tooltip from "$lib/components/ui/tooltip" | ||
export let readonly = false | ||
export let value: number | undefined | ||
function onChange(nums: number[]) { | ||
value = nums[0] / 100 | ||
} | ||
</script> | ||
|
||
<Tooltip.Root> | ||
<Tooltip.Trigger class="w-full"> | ||
<div class="flex h-full items-center"> | ||
<Slider | ||
disabled={readonly} | ||
value={[(value ?? 0) * 100]} | ||
onValueChange={onChange} | ||
max={100} | ||
step={1} | ||
{...$$restProps} | ||
/> | ||
</div> | ||
</Tooltip.Trigger> | ||
<Tooltip.Content> | ||
<p>{value}</p> | ||
</Tooltip.Content> | ||
</Tooltip.Root> |
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/percentage-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 { PercentageFieldConstraint, type IPercentageFieldConstraint } from "@undb/table" | ||
import * as Alert from "$lib/components/ui/alert/index.js" | ||
export let constraint: IPercentageFieldConstraint | undefined | ||
export let display: boolean | undefined | ||
export let defaultValue: number | undefined | ||
export let disabled = false | ||
$: c = constraint ? new PercentageFieldConstraint(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
62 changes: 62 additions & 0 deletions
62
apps/frontend/src/lib/components/blocks/grid-view/editable-cell/percentage-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,62 @@ | ||
<script lang="ts"> | ||
import { trpc } from "$lib/trpc/client" | ||
import { cn } from "$lib/utils" | ||
import { createMutation } from "@tanstack/svelte-query" | ||
import { NumberField } from "@undb/table" | ||
import { toast } from "svelte-sonner" | ||
import { debounce, isNumber } from "radash" | ||
import { gridViewStore } from "../grid-view.store" | ||
import { Slider } from "$lib/components/ui/slider" | ||
import * as Tooltip from "$lib/components/ui/tooltip" | ||
export let tableId: string | ||
export let field: NumberField | ||
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) { | ||
el?.blur() | ||
gridViewStore.exitEditing() | ||
}, | ||
onError(error: Error) { | ||
toast.error(error.message) | ||
}, | ||
}) | ||
let el: HTMLInputElement | ||
$: if (isEditing) { | ||
if (el) { | ||
el.focus() | ||
} | ||
} | ||
const onChange = (nums: number[]) => { | ||
const value = nums[0] / 100 | ||
onValueChange(value) | ||
$updateCell.mutate({ | ||
tableId, | ||
id: recordId, | ||
values: { [field.id.value]: value }, | ||
}) | ||
} | ||
</script> | ||
|
||
<Tooltip.Root> | ||
<Tooltip.Trigger class="w-full"> | ||
<div class={$$restProps.class}> | ||
{#if isEditing} | ||
<Slider value={[(value ?? 0) * 100]} onValueChange={debounce({ delay: 300 }, onChange)} /> | ||
{:else if isNumber(value) || value === undefined || value === null} | ||
<Slider disabled value={[value * 100]} /> | ||
{/if} | ||
</div> | ||
</Tooltip.Trigger> | ||
<Tooltip.Content> | ||
<p>{value}</p> | ||
</Tooltip.Content> | ||
</Tooltip.Root> |
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 |
---|---|---|
|
@@ -108,6 +108,7 @@ export class Graphql { | |
checkbox | ||
user | ||
duration | ||
percentage | ||
} | ||
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
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
Oops, something went wrong.