Skip to content

Commit

Permalink
Show the Json schema property description field in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Nov 4, 2024
1 parent cb568a2 commit 14e7615
Show file tree
Hide file tree
Showing 3 changed files with 2,004 additions and 1,953 deletions.
50 changes: 45 additions & 5 deletions frontend/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface FormRadioInputProps {
readOnly?: boolean;
setValue: (value: string) => void;
items: ItemsProps;
description?: string;
}

export function FormRadioInput(props: FormRadioInputProps): JSX.Element {
Expand All @@ -38,6 +39,9 @@ export function FormRadioInput(props: FormRadioInputProps): JSX.Element {
</label>
</div>
))}
{props.description && (
<div className="form-text">{props.description}</div>
)}
</fieldset>
);
}
Expand All @@ -48,6 +52,7 @@ interface FormSelectInputProps {
readOnly?: boolean;
items: ItemsProps;
setValue: (value: string) => void;
description?: string;
}

export function FormSelectInput(props: FormSelectInputProps): JSX.Element {
Expand All @@ -71,6 +76,9 @@ export function FormSelectInput(props: FormSelectInputProps): JSX.Element {
<label className="form-label" htmlFor={id}>
{props.label}
</label>
{props.description && (
<div className="form-text">{props.description}</div>
)}
</div>
);
}
Expand All @@ -81,6 +89,7 @@ interface FormCheckboxInputProps {
checked: boolean;
readOnly?: boolean;
setValue: (value: JsonValue) => void;
description?: string;
}

export function FormCheckboxInput(props: FormCheckboxInputProps): JSX.Element {
Expand All @@ -100,6 +109,9 @@ export function FormCheckboxInput(props: FormCheckboxInputProps): JSX.Element {
<label className="form-check-label" htmlFor={id}>
{props.label}
</label>
{props.description && (
<div className="form-text">{props.description}</div>
)}
</div>
);
}
Expand All @@ -110,6 +122,7 @@ export interface FormTextAreaInputProps {
value: string | null;
setValue: (value: string | null) => void;
readOnly?: boolean;
description?: string;
}

export function FormTextAreaInput(props: FormTextAreaInputProps): JSX.Element {
Expand Down Expand Up @@ -152,6 +165,9 @@ export function FormTextAreaInput(props: FormTextAreaInputProps): JSX.Element {
<label className="form-label" htmlFor={id}>
{props.label}
</label>
{props.description && (
<div className="form-text">{props.description}</div>
)}
</div>
);
}
Expand All @@ -161,6 +177,7 @@ interface FormTextInputProps {
readOnly?: boolean;
type?: string;
value: JsonValue;
description?: string;
disabled?: boolean;
setValue: (value: JsonValue) => void;
}
Expand All @@ -183,6 +200,9 @@ export function FormTextInput(props: FormTextInputProps): JSX.Element {
<label className="form-label" htmlFor={id}>
{props.label}
</label>
{props.description && (
<div className="form-text">{props.description}</div>
)}
</div>
);
}
Expand All @@ -194,6 +214,7 @@ interface FormNumberInputProps {
disabled?: boolean;
step?: number;
setValue: (value: JsonValue) => void;
description?: string;
}

export function FormNumberInput(props: FormNumberInputProps): JSX.Element {
Expand All @@ -217,13 +238,17 @@ export function FormNumberInput(props: FormNumberInputProps): JSX.Element {
<label className="form-label" htmlFor={id}>
{props.label}
</label>
{props.description && (
<div className="form-text">{props.description}</div>
)}
</div>
);
}

interface FormSelectProps {
label: string;
children: React.ReactNode;
description?: string;
}

export function FormSelect(props: FormSelectProps): JSX.Element {
Expand All @@ -233,8 +258,12 @@ export function FormSelect(props: FormSelectProps): JSX.Element {
<label className="form-label" htmlFor={id}>
{props.label}
</label>
<select className="form-select" {...props} />
{props.children}
<select className="form-select" {...props}>
{props.children}
</select>
{props.description && (
<div className="form-text">{props.description}</div>
)}
</div>
);
}
Expand All @@ -246,6 +275,7 @@ interface FormCheckProps {
checked: boolean;
label: string;
handleValueChange: (value: string) => void;
description?: string;
}

export function FormCheck(props: FormCheckProps): JSX.Element {
Expand All @@ -255,19 +285,29 @@ export function FormCheck(props: FormCheckProps): JSX.Element {
<label className="form-check-label" htmlFor={props.id}>
{props.label}
</label>
{props.description && (
<div className="form-text">{props.description}</div>
)}
</div>
);
}

export function FormSwitch(
props: JSX.IntrinsicAttributes & JSX.HTMLAttributes<HTMLInputElement>,
): JSX.Element {
interface FormSwitchProps {
id: string;
label: string;
description?: string;
}

export function FormSwitch(props: FormSwitchProps): JSX.Element {
return (
<div className="form-check form-switch mb-3">
<input className="form-check-input" role="switch" {...props} />
<label className="form-check-label" htmlFor={props.id}>
{props.label}
</label>
{props.description && (
<div className="form-text">{props.description}</div>
)}
</div>
);
}
9 changes: 9 additions & 0 deletions frontend/src/pages/Configuration/ConfigCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface EditControlProps {
uniqueItems?: boolean;
format?: string;
items?: ItemsProps;
description?: string;
displayMultiplier?: number;
displayOffset?: number;
};
Expand Down Expand Up @@ -60,6 +61,7 @@ export function EditControl({
setValue={(value: string) => {
setValue(value);
}}
description={schema.description}
/>
);
case "number":
Expand All @@ -78,6 +80,7 @@ export function EditControl({
(schema.displayMultiplier ?? 1),
);
}}
description={schema.description}
/>
);
case "integer":
Expand All @@ -97,6 +100,7 @@ export function EditControl({
(schema.displayMultiplier ?? 1),
);
}}
description={schema.description}
/>
);
break;
Expand All @@ -112,6 +116,7 @@ export function EditControl({
setValue={(checked: boolean) => {
setValue(checked);
}}
description={schema.description}
/>
);
case "array":
Expand All @@ -127,6 +132,7 @@ export function EditControl({
setValue={(value: string) => {
setValue(value);
}}
description={schema.description}
/>
);
} else if (schema.format === "select") {
Expand All @@ -140,6 +146,7 @@ export function EditControl({
setValue={(value: string) => {
setValue(value);
}}
description={schema.description}
/>
);
} else {
Expand Down Expand Up @@ -180,6 +187,7 @@ export function EditControl({
}
}}
readOnly={schema.readOnly ?? false}
description={schema.description}
/>
);
}
Expand All @@ -198,6 +206,7 @@ export function EditControl({
setValue={(value: string) => {
setValue(value);
}}
description={schema.description}
/>
);
}
Expand Down
Loading

0 comments on commit 14e7615

Please sign in to comment.