Skip to content

Commit 27f4978

Browse files
💄 [#353] style: view labels instead of values for multiple deelzaaktype values
1 parent ec2e9a0 commit 27f4978

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

frontend/src/pages/zaaktype/components/zaaktypetabs/ZaaktypeAttributeGridTab.tsx

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ export const ZaaktypeAttributeGridTab = ({
103103
* Fetches and sets selected deelzaaktypen options when not editing.
104104
*/
105105
useEffect(() => {
106-
if (isEditing) return;
107-
108106
const deelzaaktypenField = fields.find(
109107
(f) => f.name.split(".").pop() === "deelzaaktypen",
110108
);
@@ -152,7 +150,7 @@ export const ZaaktypeAttributeGridTab = ({
152150
* Non-primitive values are displayed as RelatedObjectBadge or editable text.
153151
*/
154152
const complexOverrides = useMemo(() => {
155-
const overrides: Partial<Record<keyof TargetType, ReactNode>> = {};
153+
const overrides: Partial<Record<keyof TargetType, unknown>> = {};
156154

157155
for (const field of fields) {
158156
const _fieldName = field.name.split(".").pop();
@@ -165,31 +163,41 @@ export const ZaaktypeAttributeGridTab = ({
165163

166164
// When deelzaaktypen we want to render badges for selected options
167165
if (fieldName === "deelzaaktypen") {
168-
overrides[fieldName] = isEditing
169-
? (originalValue as string[])
170-
: selectedDeelzaaktypenOptions.length > 0
171-
? selectedDeelzaaktypenOptions.map((option) => {
172-
const uuid =
173-
option.value &&
174-
getZaaktypeUUID({ url: String(option.value) });
175-
const to =
176-
uuid && `/${serviceSlug}/${catalogusId}/zaaktypen/${uuid}`;
177-
178-
return to ? (
179-
<Badge
180-
href={to}
181-
onClick={(e: React.MouseEvent) => {
182-
e.preventDefault();
183-
navigate(to);
184-
}}
185-
>
186-
{option.label}
187-
</Badge>
188-
) : (
189-
<Badge key={option.value}>{option.label}</Badge>
190-
);
191-
})
192-
: "-";
166+
if (isEditing) {
167+
// eslint-disable-next-line max-depth
168+
if (!Array.isArray(originalValue)) continue;
169+
overrides[fieldName] = originalValue.map((v) => {
170+
const label = selectedDeelzaaktypenOptions.find(
171+
(s) => s.value === v,
172+
)?.label;
173+
return label ? { label, value: v } : v;
174+
});
175+
} else {
176+
overrides[fieldName] =
177+
selectedDeelzaaktypenOptions.length > 0
178+
? selectedDeelzaaktypenOptions.map((option) => {
179+
const uuid =
180+
option.value &&
181+
getZaaktypeUUID({ url: String(option.value) });
182+
const to =
183+
uuid && `/${serviceSlug}/${catalogusId}/zaaktypen/${uuid}`;
184+
185+
return to ? (
186+
<Badge
187+
href={to}
188+
onClick={(e: React.MouseEvent) => {
189+
e.preventDefault();
190+
navigate(to);
191+
}}
192+
>
193+
{option.label}
194+
</Badge>
195+
) : (
196+
<Badge key={option.value}>{option.label}</Badge>
197+
);
198+
})
199+
: "-";
200+
}
193201
continue;
194202
}
195203

0 commit comments

Comments
 (0)