A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: mo.ui.dataframe filtering (#3853)
Myles Scolnickaf5176f56c6e
diff --git a/frontend/src/components/editor/database/add-database-form.tsx b/frontend/src/components/editor/database/add-database-form.tsxindex c557a05ce5..50db3e5d61 100644--- a/frontend/src/components/editor/database/add-database-form.tsx+++ b/frontend/src/components/editor/database/add-database-form.tsx@@ -139,7 +139,7 @@ const DatabaseForm: React.FC<{return (<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">- <ZodForm schema={schema} form={form}>+ <ZodForm schema={schema} form={form} renderers={undefined}><FormErrorsBanner /></ZodForm><div className="flex gap-2 justify-between">diff --git a/frontend/src/components/forms/form-utils.ts b/frontend/src/components/forms/form-utils.tsindex f9066d83ce..cdcefeee43 100644--- a/frontend/src/components/forms/form-utils.ts+++ b/frontend/src/components/forms/form-utils.ts@@ -1,4 +1,5 @@/* Copyright 2024 Marimo. All rights reserved. */+import { Logger } from "@/utils/Logger";import { z } from "zod";/**@@ -77,5 +78,6 @@ export function getUnionLiteral<T extends z.ZodType<unknown>>(if (schema instanceof z.ZodUnion) {return getUnionLiteral(schema._def.options[0]);}- throw new Error("Invalid schema");+ Logger.warn(schema);+ throw new Error(`Invalid schema: ${schema._type}`);}diff --git a/frontend/src/components/forms/form.tsx b/frontend/src/components/forms/form.tsxindex 1d09c3954a..76889e1758 100644--- a/frontend/src/components/forms/form.tsx+++ b/frontend/src/components/forms/form.tsx@@ -58,7 +58,7 @@ interface Props<T extends FieldValues> {form: UseFormReturn<T>;schema: z.ZodType;path?: Path<T>;- renderers?: Array<FormRenderer<T>>;+ renderers: Array<FormRenderer<T>> | undefined;children?: React.ReactNode;}@@ -322,6 +322,7 @@ export function renderZodSchema<T extends FieldValues, S>(path={path}key={path}minLength={schema._def.minLength?.value}+ renderers={renderers}/></div>);@@ -404,10 +405,12 @@ const FormArray = ({form,path,minLength,+ renderers,}: {schema: z.ZodType<unknown>;form: UseFormReturn<any>;path: Path<any>;+ renderers: FormRenderer[];minLength?: number;}) => {const { label, description } = FieldOptions.parse(@@ -435,7 +438,7 @@ const FormArray = ({key={field.id}onKeyDown={Events.onEnter((e) => e.preventDefault())}>- {renderZodSchema(schema, form, `${path}[${index}]`, [])}+ {renderZodSchema(schema, form, `${path}[${index}]`, renderers)}{canRemove && (<Trash2IconclassName="w-4 h-4 ml-2 my-1 text-muted-foreground hover:text-destructive cursor-pointer absolute right-0 top-5"diff --git a/frontend/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap b/frontend/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snapindex 167011babe..1193fe51b6 100644--- a/frontend/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap+++ b/frontend/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap@@ -1,139 +1,14 @@// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html-exports[`renderZodSchema > should render a form 1`] = `+exports[`renderZodSchema > should render a form aggregate 1`] = `<DocumentFragment><div- class="flex flex-col gap-6"- >- <input- name="type"- type="hidden"- value="filter_rows"- />- <div- class="flex flex-row align-start"- >- <div- class="flex flex-col gap-1"- >- <div- aria-describedby=":r0:-form-item-description"- aria-invalid="false"- aria-required="false"- class="flex flex-row gap-2 pt-1 items-center"- dir="ltr"- id=":r0:-form-item"- role="radiogroup"- style="outline: none;"- tabindex="0"- >- <div- class="flex items-center gap-1"- >- <button- aria-checked="false"- class="h-[16px] w-[16px] transition-shadow data-[state=unchecked]:shadow-xsSolid rounded-full border border-input text-primary ring-offset-background focus:outline-none focus:shadow-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:shadow-none"- data-radix-collection-item=""- data-state="unchecked"- id="operation-keep_rows"- role="radio"- tabindex="-1"- type="button"- value="keep_rows"- />- <label- class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 whitespace-pre"- for="operation-keep_rows"- >- Keep Rows- </label>- </div>- <div- class="flex items-center gap-1"- >- <button- aria-checked="false"- class="h-[16px] w-[16px] transition-shadow data-[state=unchecked]:shadow-xsSolid rounded-full border border-input text-primary ring-offset-background focus:outline-none focus:shadow-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:shadow-none"- data-radix-collection-item=""- data-state="unchecked"- id="operation-remove_rows"- role="radio"- tabindex="-1"- type="button"- value="remove_rows"- />- <label- class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 whitespace-pre"- for="operation-remove_rows"- >- Remove Rows- </label>- </div>- </div>- </div>- </div>- <div- class="flex flex-row align-start"- >- <div- class="flex flex-col gap-1"- >- <label- class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- />- <div- class="flex flex-col gap-2 min-w-[220px]"- >- <div- class="text-destructive text-xs font-semibold"- >- <div>- At least 1 required.- </div>- </div>- <div>- <button- class="disabled:opacity-50 disabled:pointer-events-none inline-flex items-center justify-center font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 ring-offset-background opacity-80 hover:opacity-100 active:opacity-100 h-7 px-2 rounded-md text-xs hover:text-accent-foreground"- data-testid="marimo-plugin-data-frames-add-array-item"- >- <svg- class="lucide lucide-plus w-3.5 h-3.5 mr-1"- fill="none"- height="24"- stroke="currentColor"- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- viewBox="0 0 24 24"- width="24"- xmlns="http://www.w3.org/2000/svg"- >- <path- d="M5 12h14"- />- <path- d="M12 5v14"- />- </svg>- Add- </button>- </div>- </div>- </div>- </div>- </div>-</DocumentFragment>-`;--exports[`renderZodSchema > should render a form 2`] = `-<DocumentFragment>- <div- class="flex flex-col gap-6"+ class="flex flex-row gap-6 items-start"><inputname="type"type="hidden"- value="select_columns"+ value="aggregate"/><divclass="flex flex-row align-start"@@ -143,18 +18,18 @@ exports[`renderZodSchema > should render a form 2`] = `><labelclass="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r3:-form-item"+ for=":r26:-form-item">Columns</label><div- aria-describedby=":r3:-form-item-description"+ aria-describedby=":r26:-form-item-description"aria-invalid="false"class="relative"- id=":r3:-form-item"+ id=":r26:-form-item"><div- aria-controls="radix-:r4:"+ aria-controls="radix-:r27:"aria-expanded="false"aria-haspopup="dialog"class="flex h-6 w-fit mb-1 shadow-xsSolid items-center justify-between rounded-sm border border-input bg-transparent px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground hover:shadow-smSolid focus:outline-none focus:ring-1 focus:ring-ring focus:border-primary focus:shadow-mdSolid disabled:cursor-not-allowed disabled:opacity-50 min-w-[180px]"@@ -185,20 +60,6 @@ exports[`renderZodSchema > should render a form 2`] = `</div></div></div>- </div>-</DocumentFragment>-`;--exports[`renderZodSchema > should render a form 3`] = `-<DocumentFragment>- <div- class="flex flex-col gap-6"- >- <input- name="type"- type="hidden"- value="rename_column"- /><divclass="flex flex-row align-start">@@ -206,63 +67,45 @@ exports[`renderZodSchema > should render a form 3`] = `class="flex flex-col gap-1"><label- class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r5:-form-item"+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 whitespace-pre"+ for=":r28:-form-item">- Column+ Aggregations</label>- <button- aria-autocomplete="none"- aria-controls="radix-:r6:"- aria-expanded="false"- class="flex h-6 w-fit items-center justify-between rounded-sm bg-background px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer shadow-xsSolid border border-input hover:shadow-smSolid focus:border-primary focus:shadow-mdSolid disabled:hover:shadow-xsSolid mb-0 min-w-[180px]"- data-placeholder=""- data-state="closed"- dir="ltr"- role="combobox"- type="button"- >- <span- style="pointer-events: none;"- >- --- </span>- <svg- aria-hidden="true"- class="lucide lucide-chevron-down h-4 w-4 opacity-50"- fill="none"- height="24"- stroke="currentColor"- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- viewBox="0 0 24 24"- width="24"- xmlns="http://www.w3.org/2000/svg"- >- <path- d="m6 9 6 6 6-6"- />- </svg>- </button>- </div>- </div>- <div- class="flex flex-row align-start"- >- <div- class="flex flex-col gap-1"- ><div+ aria-describedby=":r28:-form-item-description"+ aria-invalid="false"class="relative"+ id=":r28:-form-item">- <input- aria-describedby=":r7:-form-item-description"- aria-invalid="false"- class="shadow-xsSolid hover:shadow-smSolid disabled:shadow-xsSolid focus-visible:shadow-mdSolid flex h-6 w-full rounded-sm border border-input bg-background px-1.5 py-1 text-sm font-code ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:border-primary disabled:cursor-not-allowed disabled:opacity-50 my-0"- id=":r7:-form-item"- name="new_column_id"- value=""+ <div+ aria-controls="radix-:r29:"+ aria-expanded="false"+ aria-haspopup="dialog"+ class="flex h-6 w-fit mb-1 shadow-xsSolid items-center justify-between rounded-sm border border-input bg-transparent px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground hover:shadow-smSolid focus:outline-none focus:ring-1 focus:ring-ring focus:border-primary focus:shadow-mdSolid disabled:cursor-not-allowed disabled:opacity-50 min-w-[180px]"+ data-state="closed"+ type="button"+ >+ Select aggregations+ <svg+ class="lucide lucide-chevron-down ml-3 w-4 h-4 opacity-50"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="m6 9 6 6 6-6"+ />+ </svg>+ </div>+ <div+ class="flex flex-col gap-1 items-start"/></div></div>@@ -271,7 +114,7 @@ exports[`renderZodSchema > should render a form 3`] = `</DocumentFragment>`;-exports[`renderZodSchema > should render a form 4`] = `+exports[`renderZodSchema > should render a form column_conversion 1`] = `<DocumentFragment><divclass="flex flex-col gap-6"@@ -449,7 +292,7 @@ exports[`renderZodSchema > should render a form 4`] = `</DocumentFragment>`;-exports[`renderZodSchema > should render a form 5`] = `+exports[`renderZodSchema > should render a form expand_dict 1`] = `<DocumentFragment><divclass="flex flex-col gap-6"@@ -457,7 +300,7 @@ exports[`renderZodSchema > should render a form 5`] = `<inputname="type"type="hidden"- value="sort_column"+ value="expand_dict"/><divclass="flex flex-row align-start"@@ -467,13 +310,13 @@ exports[`renderZodSchema > should render a form 5`] = `><labelclass="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r1f:-form-item"+ for=":r2q:-form-item">Column</label><buttonaria-autocomplete="none"- aria-controls="radix-:r1g:"+ aria-controls="radix-:r2r:"aria-expanded="false"class="flex h-6 w-fit items-center justify-between rounded-sm bg-background px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer shadow-xsSolid border border-input hover:shadow-smSolid focus:border-primary focus:shadow-mdSolid disabled:hover:shadow-xsSolid mb-0 min-w-[180px]"data-placeholder=""@@ -507,55 +350,97 @@ exports[`renderZodSchema > should render a form 5`] = `</button></div></div>+ </div>+</DocumentFragment>+`;++exports[`renderZodSchema > should render a form explode_columns 1`] = `+<DocumentFragment>+ <div+ class="flex flex-col gap-6"+ >+ <input+ name="type"+ type="hidden"+ value="explode_columns"+ /><divclass="flex flex-row align-start"><divclass="flex flex-col gap-1">- <div- class="flex flex-row items-start space-x-2"+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ for=":r2o:-form-item">- <label- class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r1h:-form-item"- >- Ascending- </label>- <button- aria-checked="false"- aria-describedby=":r1h:-form-item-description"- aria-invalid="false"- class="flex items-center justify-center peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground"- data-state="unchecked"- data-testid="marimo-plugin-data-frames-boolean-checkbox"- id=":r1h:-form-item"- role="checkbox"+ Columns+ </label>+ <div+ aria-describedby=":r2o:-form-item-description"+ aria-invalid="false"+ class="relative"+ id=":r2o:-form-item"+ >+ <div+ aria-controls="radix-:r2p:"+ aria-expanded="false"+ aria-haspopup="dialog"+ class="flex h-6 w-fit mb-1 shadow-xsSolid items-center justify-between rounded-sm border border-input bg-transparent px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground hover:shadow-smSolid focus:outline-none focus:ring-1 focus:ring-ring focus:border-primary focus:shadow-mdSolid disabled:cursor-not-allowed disabled:opacity-50 min-w-[180px]"+ data-state="closed"type="button"- value="on"+ >+ Select columns+ <svg+ class="lucide lucide-chevron-down ml-3 w-4 h-4 opacity-50"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="m6 9 6 6 6-6"+ />+ </svg>+ </div>+ <div+ class="flex flex-col gap-1 items-start"/></div></div></div>+ </div>+</DocumentFragment>+`;++exports[`renderZodSchema > should render a form filter_rows 1`] = `+<DocumentFragment>+ <div+ class="flex flex-col gap-6"+ >+ <input+ name="type"+ type="hidden"+ value="filter_rows"+ /><divclass="flex flex-row align-start"><divclass="flex flex-col gap-1">- <label- class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r1i:-form-item"- >- N/A position- </label><div- aria-describedby=":r1i:-form-item-description"+ aria-describedby=":r0:-form-item-description"aria-invalid="false"aria-required="false"class="flex flex-row gap-2 pt-1 items-center"dir="ltr"- id=":r1i:-form-item"+ id=":r0:-form-item"role="radiogroup"style="outline: none;"tabindex="0"@@ -568,17 +453,17 @@ exports[`renderZodSchema > should render a form 5`] = `class="h-[16px] w-[16px] transition-shadow data-[state=unchecked]:shadow-xsSolid rounded-full border border-input text-primary ring-offset-background focus:outline-none focus:shadow-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:shadow-none"data-radix-collection-item=""data-state="unchecked"- id="na_position-first"+ id="operation-keep_rows"role="radio"tabindex="-1"type="button"- value="first"+ value="keep_rows"/><labelclass="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 whitespace-pre"- for="na_position-first"+ for="operation-keep_rows">- First+ Keep Rows</label></div><div@@ -589,27 +474,76 @@ exports[`renderZodSchema > should render a form 5`] = `class="h-[16px] w-[16px] transition-shadow data-[state=unchecked]:shadow-xsSolid rounded-full border border-input text-primary ring-offset-background focus:outline-none focus:shadow-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:shadow-none"data-radix-collection-item=""data-state="unchecked"- id="na_position-last"+ id="operation-remove_rows"role="radio"tabindex="-1"type="button"- value="last"+ value="remove_rows"/><labelclass="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 whitespace-pre"- for="na_position-last"+ for="operation-remove_rows">- Last+ Remove Rows</label></div></div></div></div>+ <div+ class="flex flex-row align-start"+ >+ <div+ class="flex flex-col gap-1"+ >+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ />+ <div+ class="flex flex-col gap-2 min-w-[220px]"+ >+ <div+ class="text-destructive text-xs font-semibold"+ >+ <div>+ At least 1 required.+ </div>+ </div>+ <div>+ <button+ class="disabled:opacity-50 disabled:pointer-events-none inline-flex items-center justify-center font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 ring-offset-background opacity-80 hover:opacity-100 active:opacity-100 h-7 px-2 rounded-md text-xs hover:text-accent-foreground"+ data-testid="marimo-plugin-data-frames-add-array-item"+ >+ <svg+ class="lucide lucide-plus w-3.5 h-3.5 mr-1"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M5 12h14"+ />+ <path+ d="M12 5v14"+ />+ </svg>+ Add+ </button>+ </div>+ </div>+ </div>+ </div></div></DocumentFragment>`;-exports[`renderZodSchema > should render a form 6`] = `+exports[`renderZodSchema > should render a form group_by 1`] = `<DocumentFragment><divclass="flex flex-col gap-6"@@ -751,15 +685,15 @@ exports[`renderZodSchema > should render a form 6`] = `</DocumentFragment>`;-exports[`renderZodSchema > should render a form 7`] = `+exports[`renderZodSchema > should render a form rename_column 1`] = `<DocumentFragment><div- class="flex flex-row gap-6 items-start"+ class="flex flex-col gap-6"><inputname="type"type="hidden"- value="aggregate"+ value="rename_column"/><divclass="flex flex-row align-start"@@ -769,48 +703,80 @@ exports[`renderZodSchema > should render a form 7`] = `><labelclass="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r26:-form-item"+ for=":r5:-form-item">- Columns+ Column</label>+ <button+ aria-autocomplete="none"+ aria-controls="radix-:r6:"+ aria-expanded="false"+ class="flex h-6 w-fit items-center justify-between rounded-sm bg-background px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer shadow-xsSolid border border-input hover:shadow-smSolid focus:border-primary focus:shadow-mdSolid disabled:hover:shadow-xsSolid mb-0 min-w-[180px]"+ data-placeholder=""+ data-state="closed"+ dir="ltr"+ role="combobox"+ type="button"+ >+ <span+ style="pointer-events: none;"+ >+ --+ </span>+ <svg+ aria-hidden="true"+ class="lucide lucide-chevron-down h-4 w-4 opacity-50"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="m6 9 6 6 6-6"+ />+ </svg>+ </button>+ </div>+ </div>+ <div+ class="flex flex-row align-start"+ >+ <div+ class="flex flex-col gap-1"+ ><div- aria-describedby=":r26:-form-item-description"- aria-invalid="false"class="relative"- id=":r26:-form-item">- <div- aria-controls="radix-:r27:"- aria-expanded="false"- aria-haspopup="dialog"- class="flex h-6 w-fit mb-1 shadow-xsSolid items-center justify-between rounded-sm border border-input bg-transparent px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground hover:shadow-smSolid focus:outline-none focus:ring-1 focus:ring-ring focus:border-primary focus:shadow-mdSolid disabled:cursor-not-allowed disabled:opacity-50 min-w-[180px]"- data-state="closed"- type="button"- >- Select columns- <svg- class="lucide lucide-chevron-down ml-3 w-4 h-4 opacity-50"- fill="none"- height="24"- stroke="currentColor"- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- viewBox="0 0 24 24"- width="24"- xmlns="http://www.w3.org/2000/svg"- >- <path- d="m6 9 6 6 6-6"- />- </svg>- </div>- <div- class="flex flex-col gap-1 items-start"+ <input+ aria-describedby=":r7:-form-item-description"+ aria-invalid="false"+ class="shadow-xsSolid hover:shadow-smSolid disabled:shadow-xsSolid focus-visible:shadow-mdSolid flex h-6 w-full rounded-sm border border-input bg-background px-1.5 py-1 text-sm font-code ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:border-primary disabled:cursor-not-allowed disabled:opacity-50 my-0"+ id=":r7:-form-item"+ name="new_column_id"+ value=""/></div></div></div>+ </div>+</DocumentFragment>+`;++exports[`renderZodSchema > should render a form sample_rows 1`] = `+<DocumentFragment>+ <div+ class="flex flex-col gap-6"+ >+ <input+ name="type"+ type="hidden"+ value="sample_rows"+ /><divclass="flex flex-row align-start">@@ -818,78 +784,14 @@ exports[`renderZodSchema > should render a form 7`] = `class="flex flex-col gap-1"><label- class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 whitespace-pre"- for=":r28:-form-item"+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ for=":r2a:-form-item">- Aggregations+ Number of rows</label><div- aria-describedby=":r28:-form-item-description"- aria-invalid="false"- class="relative"- id=":r28:-form-item"- >- <div- aria-controls="radix-:r29:"- aria-expanded="false"- aria-haspopup="dialog"- class="flex h-6 w-fit mb-1 shadow-xsSolid items-center justify-between rounded-sm border border-input bg-transparent px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground hover:shadow-smSolid focus:outline-none focus:ring-1 focus:ring-ring focus:border-primary focus:shadow-mdSolid disabled:cursor-not-allowed disabled:opacity-50 min-w-[180px]"- data-state="closed"- type="button"- >- Select aggregations- <svg- class="lucide lucide-chevron-down ml-3 w-4 h-4 opacity-50"- fill="none"- height="24"- stroke="currentColor"- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- viewBox="0 0 24 24"- width="24"- xmlns="http://www.w3.org/2000/svg"- >- <path- d="m6 9 6 6 6-6"- />- </svg>- </div>- <div- class="flex flex-col gap-1 items-start"- />- </div>- </div>- </div>- </div>-</DocumentFragment>-`;--exports[`renderZodSchema > should render a form 8`] = `-<DocumentFragment>- <div- class="flex flex-col gap-6"- >- <input- name="type"- type="hidden"- value="sample_rows"- />- <div- class="flex flex-row align-start"- >- <div- class="flex flex-col gap-1"- >- <label- class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r2a:-form-item"- >- Number of rows- </label>- <div- class="my-0"- data-rac=""+ class="my-0"+ data-rac=""><divclass="shadow-xsSolid hover:shadow-smSolid hover:focus-within:shadow-mdSolid flex h-6 w-full overflow-hidden rounded-sm border border-input bg-background text-sm font-code ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 disabled:shadow-xsSolid focus-within:shadow-mdSolid focus-within:outline-none focus-within:ring-1 focus-within:ring-ring focus-within:border-primary my-0"@@ -1049,56 +951,7 @@ exports[`renderZodSchema > should render a form 8`] = `</DocumentFragment>`;-exports[`renderZodSchema > should render a form 9`] = `-<DocumentFragment>- <div- class="flex flex-col gap-6"- >- <input- name="type"- type="hidden"- value="shuffle_rows"- />- <div- class="flex flex-row align-start"- >- <button- class="disabled:opacity-50 disabled:pointer-events-none inline-flex items-center justify-center font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 ring-offset-background bg-secondary text-secondary-foreground hover:bg-secondary/80 border border-input shadow-smSolid active:shadow-xsSolid h-7 px-2 rounded-md text-xs"- data-testid="marimo-plugin-data-frames-random-number-button"- >- <svg- class="lucide lucide-refresh-ccw w-3.5 h-3.5 mr-1"- fill="none"- height="24"- stroke="currentColor"- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- viewBox="0 0 24 24"- width="24"- xmlns="http://www.w3.org/2000/svg"- >- <path- d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"- />- <path- d="M3 3v5h5"- />- <path- d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"- />- <path- d="M16 16h5v5"- />- </svg>- Re-shuffle- </button>- </div>- </div>-</DocumentFragment>-`;--exports[`renderZodSchema > should render a form 10`] = `+exports[`renderZodSchema > should render a form select_columns 1`] = `<DocumentFragment><divclass="flex flex-col gap-6"@@ -1106,7 +959,7 @@ exports[`renderZodSchema > should render a form 10`] = `<inputname="type"type="hidden"- value="explode_columns"+ value="select_columns"/><divclass="flex flex-row align-start"@@ -1116,18 +969,18 @@ exports[`renderZodSchema > should render a form 10`] = `><labelclass="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r2o:-form-item"+ for=":r3:-form-item">Columns</label><div- aria-describedby=":r2o:-form-item-description"+ aria-describedby=":r3:-form-item-description"aria-invalid="false"class="relative"- id=":r2o:-form-item"+ id=":r3:-form-item"><div- aria-controls="radix-:r2p:"+ aria-controls="radix-:r4:"aria-expanded="false"aria-haspopup="dialog"class="flex h-6 w-fit mb-1 shadow-xsSolid items-center justify-between rounded-sm border border-input bg-transparent px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground hover:shadow-smSolid focus:outline-none focus:ring-1 focus:ring-ring focus:border-primary focus:shadow-mdSolid disabled:cursor-not-allowed disabled:opacity-50 min-w-[180px]"@@ -1162,7 +1015,7 @@ exports[`renderZodSchema > should render a form 10`] = `</DocumentFragment>`;-exports[`renderZodSchema > should render a form 11`] = `+exports[`renderZodSchema > should render a form shuffle_rows 1`] = `<DocumentFragment><divclass="flex flex-col gap-6"@@ -1170,7 +1023,56 @@ exports[`renderZodSchema > should render a form 11`] = `<inputname="type"type="hidden"- value="expand_dict"+ value="shuffle_rows"+ />+ <div+ class="flex flex-row align-start"+ >+ <button+ class="disabled:opacity-50 disabled:pointer-events-none inline-flex items-center justify-center font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 ring-offset-background bg-secondary text-secondary-foreground hover:bg-secondary/80 border border-input shadow-smSolid active:shadow-xsSolid h-7 px-2 rounded-md text-xs"+ data-testid="marimo-plugin-data-frames-random-number-button"+ >+ <svg+ class="lucide lucide-refresh-ccw w-3.5 h-3.5 mr-1"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"+ />+ <path+ d="M3 3v5h5"+ />+ <path+ d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"+ />+ <path+ d="M16 16h5v5"+ />+ </svg>+ Re-shuffle+ </button>+ </div>+ </div>+</DocumentFragment>+`;++exports[`renderZodSchema > should render a form sort_column 1`] = `+<DocumentFragment>+ <div+ class="flex flex-col gap-6"+ >+ <input+ name="type"+ type="hidden"+ value="sort_column"/><divclass="flex flex-row align-start"@@ -1180,13 +1082,13 @@ exports[`renderZodSchema > should render a form 11`] = `><labelclass="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- for=":r2q:-form-item"+ for=":r1f:-form-item">Column</label><buttonaria-autocomplete="none"- aria-controls="radix-:r2r:"+ aria-controls="radix-:r1g:"aria-expanded="false"class="flex h-6 w-fit items-center justify-between rounded-sm bg-background px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer shadow-xsSolid border border-input hover:shadow-smSolid focus:border-primary focus:shadow-mdSolid disabled:hover:shadow-xsSolid mb-0 min-w-[180px]"data-placeholder=""@@ -1220,6 +1122,298 @@ exports[`renderZodSchema > should render a form 11`] = `</button></div></div>+ <div+ class="flex flex-row align-start"+ >+ <div+ class="flex flex-col gap-1"+ >+ <div+ class="flex flex-row items-start space-x-2"+ >+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ for=":r1h:-form-item"+ >+ Ascending+ </label>+ <button+ aria-checked="false"+ aria-describedby=":r1h:-form-item-description"+ aria-invalid="false"+ class="flex items-center justify-center peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground"+ data-state="unchecked"+ data-testid="marimo-plugin-data-frames-boolean-checkbox"+ id=":r1h:-form-item"+ role="checkbox"+ type="button"+ value="on"+ />+ </div>+ </div>+ </div>+ <div+ class="flex flex-row align-start"+ >+ <div+ class="flex flex-col gap-1"+ >+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ for=":r1i:-form-item"+ >+ N/A position+ </label>+ <div+ aria-describedby=":r1i:-form-item-description"+ aria-invalid="false"+ aria-required="false"+ class="flex flex-row gap-2 pt-1 items-center"+ dir="ltr"+ id=":r1i:-form-item"+ role="radiogroup"+ style="outline: none;"+ tabindex="0"+ >+ <div+ class="flex items-center gap-1"+ >+ <button+ aria-checked="false"+ class="h-[16px] w-[16px] transition-shadow data-[state=unchecked]:shadow-xsSolid rounded-full border border-input text-primary ring-offset-background focus:outline-none focus:shadow-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:shadow-none"+ data-radix-collection-item=""+ data-state="unchecked"+ id="na_position-first"+ role="radio"+ tabindex="-1"+ type="button"+ value="first"+ />+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 whitespace-pre"+ for="na_position-first"+ >+ First+ </label>+ </div>+ <div+ class="flex items-center gap-1"+ >+ <button+ aria-checked="false"+ class="h-[16px] w-[16px] transition-shadow data-[state=unchecked]:shadow-xsSolid rounded-full border border-input text-primary ring-offset-background focus:outline-none focus:shadow-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:shadow-none"+ data-radix-collection-item=""+ data-state="unchecked"+ id="na_position-last"+ role="radio"+ tabindex="-1"+ type="button"+ value="last"+ />+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 whitespace-pre"+ for="na_position-last"+ >+ Last+ </label>+ </div>+ </div>+ </div>+ </div>+ </div>+</DocumentFragment>+`;++exports[`renders custom forms column_id 1`] = `+<DocumentFragment>+ <div+ class="flex flex-col gap-1"+ >+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ for=":r31:-form-item"+ >+ Column+ </label>+ <button+ aria-autocomplete="none"+ aria-controls="radix-:r32:"+ aria-expanded="false"+ class="flex h-6 w-fit items-center justify-between rounded-sm bg-background px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer shadow-xsSolid border border-input hover:shadow-smSolid focus:border-primary focus:shadow-mdSolid disabled:hover:shadow-xsSolid mb-0 min-w-[180px]"+ data-placeholder=""+ data-state="closed"+ dir="ltr"+ role="combobox"+ type="button"+ >+ <span+ style="pointer-events: none;"+ >+ --+ </span>+ <svg+ aria-hidden="true"+ class="lucide lucide-chevron-down h-4 w-4 opacity-50"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="m6 9 6 6 6-6"+ />+ </svg>+ </button>+ </div>+</DocumentFragment>+`;++exports[`renders custom forms column_id_array 1`] = `+<DocumentFragment>+ <div+ class="flex flex-col gap-1"+ >+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ for=":r38:-form-item"+ >+ Columns+ </label>+ <div+ aria-describedby=":r38:-form-item-description"+ aria-invalid="false"+ class="relative"+ id=":r38:-form-item"+ >+ <div+ aria-controls="radix-:r39:"+ aria-expanded="false"+ aria-haspopup="dialog"+ class="flex h-6 w-fit mb-1 shadow-xsSolid items-center justify-between rounded-sm border border-input bg-transparent px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground hover:shadow-smSolid focus:outline-none focus:ring-1 focus:ring-ring focus:border-primary focus:shadow-mdSolid disabled:cursor-not-allowed disabled:opacity-50 min-w-[180px]"+ data-state="closed"+ type="button"+ >+ Select columns+ <svg+ class="lucide lucide-chevron-down ml-3 w-4 h-4 opacity-50"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="m6 9 6 6 6-6"+ />+ </svg>+ </div>+ <div+ class="flex flex-col gap-1 items-start"+ />+ </div>+ </div>+</DocumentFragment>+`;++exports[`renders custom forms column_id_dot_array 1`] = `+<DocumentFragment>+ <div+ class="flex flex-col gap-1"+ >+ <div+ aria-describedby=":r3a:-form-item-description"+ aria-invalid="false"+ class="relative"+ id=":r3a:-form-item"+ >+ <div+ aria-controls="radix-:r3b:"+ aria-expanded="false"+ aria-haspopup="dialog"+ class="flex h-6 w-fit mb-1 shadow-xsSolid items-center justify-between rounded-sm border border-input bg-transparent px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground hover:shadow-smSolid focus:outline-none focus:ring-1 focus:ring-ring focus:border-primary focus:shadow-mdSolid disabled:cursor-not-allowed disabled:opacity-50 min-w-[180px]"+ data-state="closed"+ type="button"+ >+ --+ <svg+ class="lucide lucide-chevron-down ml-3 w-4 h-4 opacity-50"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="m6 9 6 6 6-6"+ />+ </svg>+ </div>+ <div+ class="flex flex-col gap-1 items-start"+ />+ </div>+ </div>+</DocumentFragment>+`;++exports[`renders custom forms column_id_optional 1`] = `+<DocumentFragment>+ <div+ class="flex flex-col gap-1"+ >+ <label+ class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ for=":r3c:-form-item"+ >+ Column+ </label>+ <button+ aria-autocomplete="none"+ aria-controls="radix-:r3d:"+ aria-expanded="false"+ class="flex h-6 w-fit items-center justify-between rounded-sm bg-background px-2 text-sm font-prose ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer shadow-xsSolid border border-input hover:shadow-smSolid focus:border-primary focus:shadow-mdSolid disabled:hover:shadow-xsSolid mb-0 min-w-[180px]"+ data-placeholder=""+ data-state="closed"+ dir="ltr"+ role="combobox"+ type="button"+ >+ <span+ style="pointer-events: none;"+ >+ --+ </span>+ <svg+ aria-hidden="true"+ class="lucide lucide-chevron-down h-4 w-4 opacity-50"+ fill="none"+ height="24"+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="m6 9 6 6 6-6"+ />+ </svg>+ </button></div></DocumentFragment>`;diff --git a/frontend/src/plugins/impl/data-frames/forms/__tests__/form.test.tsx b/frontend/src/plugins/impl/data-frames/forms/__tests__/form.test.tsxindex d18fd847f7..3699807d8d 100644--- a/frontend/src/plugins/impl/data-frames/forms/__tests__/form.test.tsx+++ b/frontend/src/plugins/impl/data-frames/forms/__tests__/form.test.tsx@@ -1,7 +1,7 @@/* Copyright 2024 Marimo. All rights reserved. */import { describe, expect, it } from "vitest";import { ZodForm } from "../../../../../components/forms/form";-import { TransformTypeSchema } from "../../schema";+import { column_id, column_id_array, TransformTypeSchema } from "../../schema";import { render } from "@testing-library/react";import { zodResolver } from "@hookform/resolvers/zod";import { useForm } from "react-hook-form";@@ -9,6 +9,8 @@ import type { z } from "zod";import type { ColumnId } from "../../types";import { ColumnInfoContext } from "../context";import { DATAFRAME_FORM_RENDERERS } from "../renderers";+import { Objects } from "@/utils/objects";+import { getUnionLiteral } from "@/components/forms/form-utils";const ColumnTypes = new Map([[0 as ColumnId, "str"],@@ -36,11 +38,29 @@ const Subject = (props: { schema: z.ZodType }) => {};describe("renderZodSchema", () => {- const options = TransformTypeSchema._def.options;// Snapshot each form to make sure they don't change unexpectedly- it.each(options)("should render a form", (schema) => {- const expected = render(<Subject schema={schema} />);+ const options = Objects.keyBy(+ TransformTypeSchema._def.options,+ (z) => getUnionLiteral(z).value,+ );+ it.each(Object.entries(options))(+ "should render a form %s",+ (name, schema) => {+ const expected = render(<Subject schema={schema} />);- expect(expected.asFragment()).toMatchSnapshot();- });+ expect(expected.asFragment()).toMatchSnapshot();+ },+ );+});++const options = [+ ["column_id", column_id],+ ["column_id_array", column_id_array],+ ["column_id_dot_array", column_id.array()],+ ["column_id_optional", column_id.optional()],+] as const;++it.each(options)("renders custom forms %s", (key, schema) => {+ const expected = render(<Subject schema={schema} />);+ expect(expected.asFragment()).toMatchSnapshot();});diff --git a/frontend/src/plugins/impl/data-frames/forms/renderers.tsx b/frontend/src/plugins/impl/data-frames/forms/renderers.tsxindex 6ccb1ef07b..5cbf21c4ac 100644--- a/frontend/src/plugins/impl/data-frames/forms/renderers.tsx+++ b/frontend/src/plugins/impl/data-frames/forms/renderers.tsx@@ -2,9 +2,9 @@/* eslint-disable @typescript-eslint/no-explicit-any */import {type Path,- useController,type UseFormReturn,type FieldValues,+ useWatch,} from "react-hook-form";import { z } from "zod";import { renderZodSchema, type FormRenderer } from "@/components/forms/form";@@ -394,14 +394,15 @@ const ColumnFilterForm = <T extends FieldValues>({}) => {const { description } = FieldOptions.parse(schema._def.description);const columns = useContext(ColumnInfoContext);- const { field } = useController({ name: path });const columnIdSchema = Objects.entries(schema._def.shape()).find(([key]) => key === "column_id",)?.[1] as unknown as z.ZodString;// existing values- const { column_id: columnId, operator } = (field.value ?? {}) as {+ const { column_id: columnId, operator } = useWatch({+ name: path,+ }) as {column_id: ColumnId;operator: string;};diff --git a/frontend/src/plugins/impl/data-frames/schema.ts b/frontend/src/plugins/impl/data-frames/schema.tsindex eec1891c73..c38c319f7c 100644--- a/frontend/src/plugins/impl/data-frames/schema.ts+++ b/frontend/src/plugins/impl/data-frames/schema.ts@@ -12,14 +12,14 @@ import {isConditionValueValid,} from "./utils/operators";-const column_id = z+export const column_id = z.string().min(1, "Required").or(z.number()).transform((v) => v as ColumnId).describe(FieldOptions.of({ label: "Column", special: "column_id" }));-const column_id_array = z+export const column_id_array = z.array(column_id.describe(FieldOptions.of({ special: "column_id" }))).min(1, "At least one column is required").default([])