Skip to content

Commit

Permalink
fix incorrectly flattening array (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfshao authored Mar 7, 2024
1 parent f749b9c commit 09729a0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Discovery/DiscoveryDetails/DiscoveryDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ type TabFieldConfig = TabFieldGroup['fields'][0];
type TabFieldGroup = DiscoveryConfig['detailView']['tabs'][0]['groups'][0];

const formatResourceValuesWhenNestedArray = (
isTargetAListField: boolean = false,
resourceFieldValue: string | any[],
) => {
if (Array.isArray(resourceFieldValue)) {
Expand All @@ -232,6 +233,9 @@ const formatResourceValuesWhenNestedArray = (
) {
return resourceFieldValue[0].join(', ');
}
if (isTargetAListField) {
return resourceFieldValue;
}
return resourceFieldValue[0];
}
return resourceFieldValue;
Expand Down Expand Up @@ -281,7 +285,11 @@ const tabField = (
// Here begins some normal fields (texts, links, etc...)
if (resourceFieldValueIsValid) {
// Format resourceFieldValue for all other field types
resourceFieldValue = formatResourceValuesWhenNestedArray(resourceFieldValue);
let isTargetAListField = false;
if (fieldConfig.type === 'textList' || fieldConfig.type === 'linkList') {
isTargetAListField = true;
}
resourceFieldValue = formatResourceValuesWhenNestedArray(isTargetAListField, resourceFieldValue);

if (fieldConfig.type === 'text') {
return labeledSingleTextField(fieldConfig.label, resourceFieldValue);
Expand Down

0 comments on commit 09729a0

Please sign in to comment.