Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Schema Form - RSJF Integration (for action parameters) #524

Merged
merged 37 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6423206
- Added rsjf library
jashanbhullar Sep 22, 2024
eeb1186
- minor changes
jashanbhullar Sep 22, 2024
921cf83
- titlefield template implementation
jashanbhullar Sep 22, 2024
5c6acab
- Description Field Template implementation
jashanbhullar Sep 22, 2024
c913038
- Checkbox Widget
jashanbhullar Sep 23, 2024
e915069
- Minor change
jashanbhullar Sep 23, 2024
d7c226b
- BaseInputTemplate
jashanbhullar Sep 23, 2024
2ec3c0e
- Update schemaForm
jashanbhullar Sep 23, 2024
f9e827b
Merge branch 'main' of github.com:reearth/reearth-flow into feat(ui)/…
jashanbhullar Sep 23, 2024
8acbd53
- moved the schema storybook
jashanbhullar Sep 24, 2024
77c0aff
- form control label for spaces in between fields
jashanbhullar Sep 24, 2024
e7a1ab2
Merge branch 'main' of github.com:reearth/reearth-flow into feat(ui)/…
jashanbhullar Sep 24, 2024
1196259
- yarn.lock update
jashanbhullar Sep 24, 2024
4cac637
- updated storybook for better DX
jashanbhullar Sep 24, 2024
3b7c1d8
- minor changes
jashanbhullar Sep 25, 2024
b1c4626
- Added all the buttons
jashanbhullar Sep 25, 2024
766cdb5
- Another field added
jashanbhullar Sep 25, 2024
815f753
- ArrayFieldTemplate
jashanbhullar Sep 25, 2024
8e7ba4b
- checkboxes widget and error list template
jashanbhullar Sep 25, 2024
89cc36c
- Field help and error template
jashanbhullar Sep 25, 2024
1eba04c
- added radio group
jashanbhullar Sep 25, 2024
54dce3d
- Added objectfield template
jashanbhullar Sep 25, 2024
4edf056
- radio widget
jashanbhullar Sep 25, 2024
5fabd0f
- range widget
jashanbhullar Sep 25, 2024
c164fec
- Added selectWidget
jashanbhullar Sep 25, 2024
914df24
- textarea widget done
jashanbhullar Sep 25, 2024
ce99087
- stories update
jashanbhullar Sep 30, 2024
5872ab6
- radio button storybook
jashanbhullar Sep 30, 2024
1952519
- fixed type by commenting some code
jashanbhullar Sep 30, 2024
ffba14c
- yarn i18n
jashanbhullar Sep 30, 2024
57d8c83
Merge branch 'main' of github.com:reearth/reearth-flow into feat(ui)/…
jashanbhullar Sep 30, 2024
4a38d6e
- Minor fix
jashanbhullar Sep 30, 2024
2651e38
- minor change
jashanbhullar Sep 30, 2024
881620f
- Updated as coderaabit suggestion
jashanbhullar Sep 30, 2024
88b570a
- fixes as per coderabbit
jashanbhullar Sep 30, 2024
c84031e
Merge branch 'main' of github.com:reearth/reearth-flow into feat(ui)/…
jashanbhullar Sep 30, 2024
0daacf4
- minor changes
jashanbhullar Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@
"@radix-ui/react-label": "2.1.0",
"@radix-ui/react-navigation-menu": "1.2.0",
"@radix-ui/react-progress": "1.1.0",
"@radix-ui/react-radio-group": "1.2.0",
"@radix-ui/react-scroll-area": "1.1.0",
"@radix-ui/react-select": "2.1.1",
"@radix-ui/react-slot": "1.1.0",
"@radix-ui/react-tabs": "1.1.0",
"@radix-ui/react-toast": "1.2.1",
"@radix-ui/react-tooltip": "1.1.2",
"@reearth/core": "0.0.7-beta.2",
"@rjsf/core": "5.21.1",
"@rjsf/utils": "5.21.1",
"@rjsf/validator-ajv8": "5.21.1",
"@tanstack/react-query": "5.56.2",
"@tanstack/react-router": "1.58.7",
"@tanstack/react-table": "8.20.5",
Expand Down
35 changes: 35 additions & 0 deletions ui/src/components/RadioGroup/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Meta } from "@storybook/react";

import { Label } from "../Label";

import { RadioGroup, RadioGroupItem } from ".";

const meta = {
component: RadioGroupItem,
parameters: {
layout: "centered",
},
tags: ["autodocs"],
argTypes: {},
} satisfies Meta<typeof RadioGroupItem>;

export default meta;

export const Default = () => {
return (
<RadioGroup defaultValue="comfortable">
<div className="flex items-center space-x-2">
<RadioGroupItem value="default" id="r1" />
<Label htmlFor="r1">Default</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="comfortable" id="r2" />
<Label htmlFor="r2">Comfortable</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="compact" id="r3" />
<Label htmlFor="r3">Compact</Label>
</div>
</RadioGroup>
);
};
41 changes: 41 additions & 0 deletions ui/src/components/RadioGroup/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { CheckIcon } from "@radix-ui/react-icons";
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
import * as React from "react";

import { cn } from "@flow/lib/utils";

const RadioGroup = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
>(({ className, ...props }, ref) => {
return (
<RadioGroupPrimitive.Root
className={cn("grid gap-2", className)}
{...props}
ref={ref}
/>
);
});
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;

const RadioGroupItem = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
>(({ className, ...props }, ref) => {
return (
<RadioGroupPrimitive.Item
ref={ref}
className={cn(
"aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
className,
)}
{...props}>
<RadioGroupPrimitive.Indicator className="flex items-center justify-center">
<CheckIcon className="size-3.5 fill-primary" />
</RadioGroupPrimitive.Indicator>
</RadioGroupPrimitive.Item>
);
});
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;

export { RadioGroup, RadioGroupItem };
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
ArrayFieldTemplateItemType,
FormContextType,
RJSFSchema,
StrictRJSFSchema,
} from "@rjsf/utils";

const ArrayFieldItemTemplate = <
T = any,

Check warning on line 9 in ui/src/components/SchemaForm/Templates/ArrayFieldItemTemplate.tsx

View workflow job for this annotation

GitHub Actions / ci-ui / ci

Unexpected any. Specify a different type
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any,

Check warning on line 11 in ui/src/components/SchemaForm/Templates/ArrayFieldItemTemplate.tsx

View workflow job for this annotation

GitHub Actions / ci-ui / ci

Unexpected any. Specify a different type
>(
props: ArrayFieldTemplateItemType<T, S, F>,
) => {
jashanbhullar marked this conversation as resolved.
Show resolved Hide resolved
const {
children,
disabled,
hasToolbar,
hasCopy,
hasMoveDown,
hasMoveUp,
hasRemove,
index,
onCopyIndexClick,
onDropIndexClick,
onReorderClick,
readonly,
registry,
uiSchema,
} = props;
const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } =
registry.templates.ButtonTemplates;
return (
<div>
<div className="mb-2 flex items-center">
<div>{children}</div>
<div className="py-4">
{hasToolbar && (
<div className="flex flex-row">
{(hasMoveUp || hasMoveDown) && (
<div>
<MoveUpButton
disabled={disabled || readonly || !hasMoveUp}
onClick={onReorderClick(index, index - 1)}
uiSchema={uiSchema}
registry={registry}
/>
</div>
)}
{(hasMoveUp || hasMoveDown) && (
<div>
<MoveDownButton
disabled={disabled || readonly || !hasMoveDown}
onClick={onReorderClick(index, index + 1)}
uiSchema={uiSchema}
registry={registry}
/>
</div>
)}
{hasCopy && (
<div>
<CopyButton
disabled={disabled || readonly}
onClick={onCopyIndexClick(index)}
uiSchema={uiSchema}
registry={registry}
/>
</div>
)}
{hasRemove && (
<div>
<RemoveButton
disabled={disabled || readonly}
onClick={onDropIndexClick(index)}
uiSchema={uiSchema}
registry={registry}
/>
</div>
)}
</div>
)}
</div>
</div>
</div>
);
};

export { ArrayFieldItemTemplate };
103 changes: 103 additions & 0 deletions ui/src/components/SchemaForm/Templates/ArrayFieldTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {
ArrayFieldTemplateItemType,
ArrayFieldTemplateProps,
FormContextType,
getTemplate,
getUiOptions,
RJSFSchema,
StrictRJSFSchema,
} from "@rjsf/utils";

const ArrayFieldTemplate = <
T = any,

Check warning on line 12 in ui/src/components/SchemaForm/Templates/ArrayFieldTemplate.tsx

View workflow job for this annotation

GitHub Actions / ci-ui / ci

Unexpected any. Specify a different type
jashanbhullar marked this conversation as resolved.
Show resolved Hide resolved
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any,

Check warning on line 14 in ui/src/components/SchemaForm/Templates/ArrayFieldTemplate.tsx

View workflow job for this annotation

GitHub Actions / ci-ui / ci

Unexpected any. Specify a different type
>(
props: ArrayFieldTemplateProps<T, S, F>,
) => {
const {
canAdd,
disabled,
idSchema,
uiSchema,
items,
onAddClick,
readonly,
registry,
required,
schema,
title,
} = props;
const uiOptions = getUiOptions<T, S, F>(uiSchema);
const ArrayFieldDescriptionTemplate = getTemplate<
"ArrayFieldDescriptionTemplate",
T,
S,
F
>("ArrayFieldDescriptionTemplate", registry, uiOptions);
const ArrayFieldItemTemplate = getTemplate<"ArrayFieldItemTemplate", T, S, F>(
"ArrayFieldItemTemplate",
registry,
uiOptions,
);
const ArrayFieldTitleTemplate = getTemplate<
"ArrayFieldTitleTemplate",
T,
S,
F
>("ArrayFieldTitleTemplate", registry, uiOptions);
// Button templates are not overridden in the uiSchema
const {
ButtonTemplates: { AddButton },
} = registry.templates;
return (
<div>
<div>
<div>
jashanbhullar marked this conversation as resolved.
Show resolved Hide resolved
<ArrayFieldTitleTemplate
idSchema={idSchema}
title={uiOptions.title || title}
schema={schema}
uiSchema={uiSchema}
required={required}
registry={registry}
/>
<ArrayFieldDescriptionTemplate
idSchema={idSchema}
description={uiOptions.description || schema.description}
schema={schema}
uiSchema={uiSchema}
registry={registry}
/>
<div key={`array-item-list-${idSchema.$id}`}>
{items &&
items.map(
({
key,
...itemProps
}: ArrayFieldTemplateItemType<T, S, F>) => (
<ArrayFieldItemTemplate key={key} {...itemProps} />
),
)}
jashanbhullar marked this conversation as resolved.
Show resolved Hide resolved
{canAdd && (
<div>
<div className="mt-2">
<div className="py-4">
<AddButton
onClick={onAddClick}
disabled={disabled || readonly}
uiSchema={uiSchema}
registry={registry}
/>
</div>
</div>
</div>
)}
jashanbhullar marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
</div>
</div>
);
};

export { ArrayFieldTemplate };
Loading
Loading