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

Use more json schema annotations in the basic form #5532

Merged
merged 4 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ export interface IArrayParamProps {
label: string;
type: string;
param: IBasicFormParam;
step: number;
handleBasicFormParamChange: (
param: IBasicFormParam,
) => (e: React.FormEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
}

export default function ArrayParam(props: IArrayParamProps) {
const { id, label, type, param, handleBasicFormParamChange } = props;
const { id, label, type, param, step, handleBasicFormParamChange } = props;

const [currentArrayItems, setCurrentArrayItems] = useState<(string | number | boolean)[]>(
param.currentValue ? JSON.parse(param.currentValue) : [],
Expand Down Expand Up @@ -138,6 +139,7 @@ export default function ArrayParam(props: IArrayParamProps) {
action="flat"
status="primary"
size="sm"
disabled={currentArrayItems.length >= param?.maxItems}
>
<CdsIcon shape="plus" size="sm" solid={true} />
<span>Add</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function BooleanParam(props: IBooleanParamProps) {
<CdsToggle>
<input
required={param.required}
disabled={param.readOnly}
aria-label={label}
id={id}
type="checkbox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function SliderParam(props: ISliderParamProps) {
<CdsRange>
<input
required={param.required}
disabled={param.readOnly}
aria-label={label}
id={id + "_range"}
type="range"
Expand All @@ -77,6 +78,7 @@ export default function SliderParam(props: ISliderParamProps) {
<CdsInput className={isModified ? "bolder" : ""}>
<input
required={param.required}
disabled={param.readOnly}
aria-label={label}
id={id + "_text"}
type="number"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ function renderCellWithTooltip(
const stringValue = ["string", "number"].includes(typeof value?.[property])
? value?.[property] || ""
: JSON.stringify(value?.[property]);

return renderCellWithTooltipBase(stringValue, className, trimFromBeginning, maxLength);
}
function renderCellWithTooltipBase(
stringValue: string,
className = "",
trimFromBeginning = false,
maxLength = MAX_LENGTH,
) {
if (stringValue?.length > maxLength) {
const trimmedString = trimFromBeginning
? "..." + stringValue.substring(stringValue.length - maxLength, stringValue.length)
Expand Down Expand Up @@ -73,6 +80,7 @@ export function renderConfigKeyHeader(table: any, _saveAllChanges: any) {
}

export function renderConfigKey(value: IBasicFormParam, row: any, _saveAllChanges: any) {
const stringKey = value?.deprecated ? `${value?.key} (deprecated)` : value?.key;
return (
<div
className="left-align self-center"
Expand Down Expand Up @@ -102,15 +110,17 @@ export function renderConfigKey(value: IBasicFormParam, row: any, _saveAllChange
<></>
)}
</CdsButton>
{renderCellWithTooltip(value, "key", "breakable self-center", true, MAX_LENGTH / 1.5)}
{renderCellWithTooltipBase(stringKey, "breakable self-center", true, MAX_LENGTH / 1.5)}
</div>
</>
</div>
);
}

export function renderConfigType(value: IBasicFormParam) {
return renderCellWithTooltip(value, "type", "italics");
const stringType =
value?.type === "array" ? `${value?.type}<${value?.items?.type}>` : value?.type;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value?.type === "array" ? `${value?.type}<${value?.items?.type}>` : value?.type;
value?.type === "array" ? `array of ${value?.items?.type}` : value?.type;

Minor suggestion, as it is for human reading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done (in a follow-up PR)

After:
image

Before:
image

return renderCellWithTooltipBase(stringType, "italics");
}

export function renderConfigDescription(value: IBasicFormParam) {
Expand Down Expand Up @@ -181,7 +191,7 @@ export function renderConfigCurrentValuePro(
label={param.title || param.path}
param={param}
handleBasicFormParamChange={handleBasicFormParamChange}
step={param.type === "integer" ? 1 : 0.1}
step={param?.multipleOf || (param.schema?.type === "number" ? 0.5 : 1)}
unit={""}
/>
);
Expand Down
11 changes: 11 additions & 0 deletions dashboard/src/shared/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export function retrieveBasicFormParams(
const isUpgrading = deploymentEvent === "upgrade" && deployedValues;
const isLeaf = !schemaProperty?.properties;

// get the values for the current property in the examples array
// for objects, we need to get the value of the property in the example array,
// for the rest, we can just get the value of the example array
let examples = schemaProperty.examples;
if (schemaExamples?.length > 0) {
examples = schemaExamples?.map((item: any) =>
typeof item === "object" ? item?.[propertyKey]?.toString() ?? "" : item?.toString() ?? "",
);
}

const param: IBasicFormParam = {
...schemaProperty,
title: schemaProperty.title || propertyKey,
Expand All @@ -50,6 +60,7 @@ export function retrieveBasicFormParams(
`${itemPath}/`,
)
: undefined,
// get the string values of the enum array
enum: schemaProperty?.enum?.map((item: { toString: () => any }) => item?.toString() ?? ""),
// check if the "required" array contains the current property
required: requiredProperties?.includes(propertyKey),
Expand Down
10 changes: 9 additions & 1 deletion dashboard/src/shared/yamlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ export function getPathValueInYamlNode(
path: string,
) {
const splittedPath = parsePath(path);
const value = values?.getIn(splittedPath);
let value = values?.getIn(splittedPath);

// if the value from getIn is an object, it means
// it is a YamlSeq or YamlMap, so we need to convert it
// back to a plain JS object
if (typeof value === "object") {
value = (value as any)?.toJSON();
}

return value;
}

Expand Down