Extract condition check to function

Signed-off-by: Stephen Glass <stephen@stephen.glass>
This commit is contained in:
Stephen Glass
2024-06-27 23:20:51 -04:00
parent 8839381d6a
commit 19d495939d
@@ -47,11 +47,8 @@ function flattenObject(
// Recurse into nested objects
if (
backstageReviewOptions &&
backstageReviewOptions.explode &&
typeof value === 'object' &&
value !== null &&
!Array.isArray(value)
backstageReviewOptions?.explode &&
isJsonObject(value)
) {
return flattenObject(value, prefixedKey, schema, formState);
}
@@ -61,6 +58,14 @@ function flattenObject(
});
}
function isJsonObject(value?: JsonValue): value is JsonObject {
return (
typeof value === 'object' &&
value !== null &&
!Array.isArray(value)
);
}
/**
* The component used by the {@link Stepper} to render the review step.
* @alpha
@@ -89,9 +94,7 @@ export const ReviewState = (props: ReviewStateProps) => {
}
if (
backstageReviewOptions.explode &&
typeof value === 'object' &&
value !== null &&
!Array.isArray(value)
isJsonObject(value)
) {
return flattenObject(value, key, parsedSchema, props.formState);
}
@@ -106,7 +109,7 @@ export const ReviewState = (props: ReviewStateProps) => {
[
key,
definitionInSchema.enumNames[
definitionInSchema.enum.indexOf(value)
definitionInSchema.enum.indexOf(value)
] || value,
],
];