Skip to content

Commit

Permalink
add more validation
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Jan 2, 2025
1 parent 834d446 commit cfb301e
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/ui/src/components/core/content/CoreDataframe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ import {
} from "./CoreDataframe/constants";
import WdsButton from "@/wds/WdsButton.vue";
import { WdsColor } from "@/wds/tokens";
import {
validatorObjectRecordNotNested,
validatorPositiveNumber,
} from "@/constants/validators";
const description = "A component to display Pandas DataFrames.";
Expand Down Expand Up @@ -243,6 +247,7 @@ export default {
desc: "Define rows actions",
type: FieldType.KeyValue,
default: JSON.stringify({ remove: "Remove", open: "Open" }),
validator: validatorObjectRecordNotNested,
},
useMarkdown: {
name: "Use Markdown",
Expand All @@ -260,6 +265,7 @@ export default {
type: FieldType.Number,
category: FieldCategory.Style,
default: "10",
validator: validatorPositiveNumber,
},
wrapText: {
name: "Wrap text",
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/content/CoreDataframeLegacy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import WdsTextInput from "@/wds/WdsTextInput.vue";
import WdsControl from "@/wds/WdsControl.vue";
import BaseMarkdown from "../base/BaseMarkdown.vue";
import { WdsColor } from "@/wds/tokens";
import { validatorPositiveNumber } from "@/constants/validators";
const description = "A component to display Pandas DataFrames.";
const defaultDataframe = `data:application/vnd.apache.arrow.file;base64,QVJST1cxAAD/////iAMAABAAAAAAAAoADgAGAAUACAAKAAAAAAEEABAAAAAAAAoADAAAAAQACAAKAAAAlAIAAAQAAAABAAAADAAAAAgADAAEAAgACAAAAGwCAAAEAAAAXwIAAHsiaW5kZXhfY29sdW1ucyI6IFsiX19pbmRleF9sZXZlbF8wX18iXSwgImNvbHVtbl9pbmRleGVzIjogW3sibmFtZSI6IG51bGwsICJmaWVsZF9uYW1lIjogbnVsbCw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51bGx9XSwgImNyZWF0b3IiOiB7ImxpYnJhcnkiOiAicHlhcnJvdyIsICJ2ZXJzaW9uIjogIjEyLjAuMCJ9LCAicGFuZGFzX3ZlcnNpb24iOiAiMS41LjMifQAGAAAAcGFuZGFzAAADAAAAiAAAAEQAAAAEAAAAlP///wAAAQIQAAAAJAAAAAQAAAAAAAAAEQAAAF9faW5kZXhfbGV2ZWxfMF9fAAAAkP///wAAAAFAAAAA0P///wAAAQIQAAAAGAAAAAQAAAAAAAAABQAAAGNvbF9iAAAAwP///wAAAAFAAAAAEAAUAAgABgAHAAwAAAAQABAAAAAAAAECEAAAACAAAAAEAAAAAAAAAAUAAABjb2xfYQAAAAgADAAIAAcACAAAAAAAAAFAAAAAsAMAAEFSUk9XMQ==`;
Expand Down Expand Up @@ -187,6 +188,7 @@ export default {
type: FieldType.Number,
category: FieldCategory.Style,
default: "10",
validator: validatorPositiveNumber,
},
wrapText: {
name: "Wrap text",
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/content/CoreIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script lang="ts">
import { FieldCategory, FieldType } from "@/writerTypes";
import { cssClasses } from "@/renderer/sharedStyleFields";
import { validatorPositiveNumber } from "@/constants/validators";
export default {
writer: {
Expand All @@ -39,6 +40,7 @@ export default {
desc: `Icon size in px`,
category: FieldCategory.Style,
default: "14",
validator: validatorPositiveNumber,
},
color: {
name: "Icon color",
Expand Down
10 changes: 5 additions & 5 deletions src/ui/src/components/core/content/CoreJsonViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
FieldType,
WriterComponentDefinition,
} from "@/writerTypes";
import { validatorCssSize } from "@/constants/validators";
import {
validatorCssSize,
validatorPositiveNumber,
} from "@/constants/validators";
const description = "A component to explore JSON data as a hierarchy.";
Expand Down Expand Up @@ -55,10 +58,7 @@ const definition: WriterComponentDefinition = {
desc: "Sets the initial viewing depth of the JSON tree hierarchy. Use -1 to display the full hierarchy.",
type: FieldType.Number,
init: "0",
validator: {
type: "number",
minimum: 0,
},
validator: validatorPositiveNumber,
},
hideRoot: {
name: "Hide root",
Expand Down
1 change: 1 addition & 0 deletions src/ui/src/components/core/content/CoreTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default {
description,
category: "Content",
fields: {
// TODO: validate
tags: {
name: "Tags",
desc: "Key-value object with tags. Must be a JSON string or a state reference to a dictionary.",
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/content/CoreVideoPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Afterwards, you can reference the video using the syntax \`@{vid_f}\`.
<script lang="ts">
import { FieldType } from "@/writerTypes";
import { cssClasses } from "@/renderer/sharedStyleFields";
import { validatorUri } from "@/constants/validators";
const description =
"A video player component that can play various video formats.";
Expand All @@ -41,6 +42,7 @@ export default {
desc: "The URL of the video file. Alternatively, you can pass a file via state.",
default: "",
type: FieldType.Text,
validator: validatorUri,
},
controls: {
name: "Controls",
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/embed/CoreIFrame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script lang="ts">
import { FieldType } from "@/writerTypes";
import { cssClasses, separatorColor } from "@/renderer/sharedStyleFields";
import { validatorUri } from "@/constants/validators";
const description = "A component to embed an external resource in an iframe.";
Expand All @@ -37,6 +38,7 @@ export default {
default: "",
desc: "A valid URL",
type: FieldType.Text,
validator: validatorUri,
},
separatorColor,
cssClasses,
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/input/CoreDropdownInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { cssClasses } from "@/renderer/sharedStyleFields";
import BaseInputWrapper from "../base/BaseInputWrapper.vue";
import WdsDropdownInput from "@/wds/WdsDropdownInput.vue";
import { ComponentPublicInstance } from "vue";
import { validatorObjectRecordNotNested } from "@/constants/validators";
const description =
"A user input component that allows users to select a single value from a list of options using a dropdown menu.";
Expand Down Expand Up @@ -60,6 +61,7 @@ export default {
desc: "Key-value object with options. Must be a JSON string or a state reference to a dictionary.",
type: FieldType.KeyValue,
default: JSON.stringify(defaultOptions, null, 2),
validator: validatorObjectRecordNotNested,
},
cssClasses,
},
Expand Down
16 changes: 16 additions & 0 deletions src/ui/src/components/core/input/CoreRatingInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
primaryTextColor,
} from "@/renderer/sharedStyleFields";
import BaseInputWrapper from "../base/BaseInputWrapper.vue";
import { validatorPositiveNumber } from "@/constants/validators";

Check warning on line 60 in src/ui/src/components/core/input/CoreRatingInput.vue

View workflow job for this annotation

GitHub Actions / build (3.9)

'validatorPositiveNumber' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 60 in src/ui/src/components/core/input/CoreRatingInput.vue

View workflow job for this annotation

GitHub Actions / build (3.9)

'validatorPositiveNumber' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 60 in src/ui/src/components/core/input/CoreRatingInput.vue

View workflow job for this annotation

GitHub Actions / build (3.10)

'validatorPositiveNumber' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 60 in src/ui/src/components/core/input/CoreRatingInput.vue

View workflow job for this annotation

GitHub Actions / build (3.11)

'validatorPositiveNumber' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 60 in src/ui/src/components/core/input/CoreRatingInput.vue

View workflow job for this annotation

GitHub Actions / build (3.12)

'validatorPositiveNumber' is defined but never used. Allowed unused vars must match /^_/u
const description =
"A user input component that allows users to provide a rating.";
Expand Down Expand Up @@ -94,18 +95,33 @@ export default {
type: FieldType.Number,
default: "1",
desc: "Valid values are 0 and 1.",
validator: {
type: "number",
minimum: 0,
maximum: 1,
},
},
maxValue: {
name: "Max value",
type: FieldType.Number,
default: "5",
desc: "Valid values are between 2 and 11.",
validator: {
type: "number",
minimum: 2,
maximum: 11,
},
},
valueStep: {
name: "Step",
type: FieldType.Number,
default: "1",
desc: "Valid values are between 0.25 and 1.",
validator: {
type: "number",
minimum: 0.25,
maximum: 1,
},
},
accentColor,
primaryTextColor,
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/input/CoreSelectInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import BaseInputWrapper from "../base/BaseInputWrapper.vue";
import { ComponentPublicInstance } from "vue";
import { WdsColor } from "@/wds/tokens";
import { validatorObjectRecordNotNested } from "@/constants/validators";
import { validatorPositiveNumber } from "@/constants/validators";
const description =
"A user input component that allows users to select a single value from a searchable list of options.";
Expand Down Expand Up @@ -71,6 +72,7 @@ export default {
desc: "The maximum allowable number of selected options. Set to zero for unlimited.",
type: FieldType.Number,
default: "0",
validator: validatorPositiveNumber,
},
accentColor,
chipTextColor: {
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/input/CoreSliderInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ComponentPublicInstance } from "vue";
import { accentColor, cssClasses } from "@/renderer/sharedStyleFields";
import { FieldCategory, FieldType } from "@/writerTypes";
import BaseInputWrapper from "../base/BaseInputWrapper.vue";
import { validatorPositiveNumber } from "@/constants/validators";
const description =
"A user input component that allows users to select numeric values using a slider with optional constraints like min, max, and step.";
Expand Down Expand Up @@ -59,6 +60,7 @@ export default {
type: FieldType.Number,
default: "1",
init: "1",
validator: validatorPositiveNumber,
},
accentColor,
popoverColor: {
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/input/CoreSliderRangeInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ComponentPublicInstance } from "vue";
import { accentColor, cssClasses } from "@/renderer/sharedStyleFields";
import { FieldCategory, FieldType } from "@/writerTypes";
import BaseInputWrapper from "../base/BaseInputWrapper.vue";
import { validatorPositiveNumber } from "../../../constants/validators";
const description =
"A user input component that allows users to select numeric values range using a range slider with optional constraints like min, max, and step.";
Expand Down Expand Up @@ -59,6 +60,7 @@ export default {
type: FieldType.Number,
default: "1",
init: "1",
validator: validatorPositiveNumber,
},
accentColor,
popoverColor: {
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/input/CoreTextareaInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { FieldControl, FieldType } from "@/writerTypes";
import { cssClasses } from "@/renderer/sharedStyleFields";
import BaseInputWrapper from "../base/BaseInputWrapper.vue";
import { ComponentPublicInstance } from "vue";
import { validatorPositiveNumber } from "@/constants/validators";
const description =
"A user input component that allows users to enter multi-line text values.";
Expand Down Expand Up @@ -63,6 +64,7 @@ export default {
type: FieldType.Number,
init: "5",
default: "5",
validator: validatorPositiveNumber,
},
cssClasses,
},
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/layout/CoreColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
startCollapsed,
isCollapsible as isCollapsibleField,
} from "@/renderer/sharedStyleFields";
import { validatorPositiveNumber } from "@/constants/validators";
const description =
"A layout component that organizes its child components in columns. Must be inside a Column Container component.";
Expand All @@ -71,6 +72,7 @@ export default {
type: FieldType.Number,
desc: "Relative size when compared to other columns in the same container. A column of width 2 will be double the width of one with width 1.",
category: FieldCategory.Style,
validator: validatorPositiveNumber,
},
isSticky: {
name: "Sticky",
Expand Down
4 changes: 4 additions & 0 deletions src/ui/src/components/core/other/CorePagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

<script lang="ts">
import { FieldType } from "@/writerTypes";
import { validatorPositiveNumber } from "../../../constants/validators";
const pageChangeStub = `
def handle_page_change(state, payload):
Expand Down Expand Up @@ -106,18 +107,21 @@ export default {
default: "1",
type: FieldType.Number,
desc: "The current page number.",
validator: validatorPositiveNumber,
},
pageSize: {
name: "Page Size",
default: "10",
type: FieldType.Number,
desc: "The number of items per page.",
validator: validatorPositiveNumber,
},
totalItems: {
name: "Total Items",
default: "10",
type: FieldType.Number,
desc: "The total number of items",
validator: validatorPositiveNumber,
},
pageSizeOptions: {
name: "Page Size Options",
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/other/CoreTimer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<script lang="ts">
import { FieldType } from "@/writerTypes";
import { accentColor, cssClasses } from "@/renderer/sharedStyleFields";
import { validatorPositiveNumber } from "@/constants/validators";
const description =
"A component that emits an event repeatedly at specified time intervals, enabling time-based refresh.";
Expand All @@ -31,6 +32,7 @@ export default {
desc: "How much time to wait between ticks. A tick is considered finished when its event is handled.",
default: "200",
type: FieldType.Number,
validator: validatorPositiveNumber,
},
isActive: {
name: "Active",
Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/components/core/other/CoreWebcamCapture.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from "@/renderer/sharedStyleFields";
import WdsButton from "@/wds/WdsButton.vue";
import WdsDropdownInput from "@/wds/WdsDropdownInput.vue";
import { validatorPositiveNumber } from "@/constants/validators";
const description =
"A user input component that allows users to capture images using their webcam.";
Expand Down Expand Up @@ -69,6 +70,7 @@ export default {
default: "200",
desc: "Set to 0 for manual capture.",
type: FieldType.Number,
validator: validatorPositiveNumber,
},
buttonColor,
buttonTextColor,
Expand Down
5 changes: 5 additions & 0 deletions src/ui/src/constants/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ export const validatorPositiveNumber: SchemaObject = {
type: "number",
minimum: 0,
};

export const validatorUri = {
type: "string",
format: "uri",
};

0 comments on commit cfb301e

Please sign in to comment.