Skip to content
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
20 changes: 20 additions & 0 deletions .changeset/tabbed-posts-category-fix-scoped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@devgateway/dvz-ui-react": patch
---

Revert the PR #296 fix for TCDICORE-601, which comma-joined all array/object
attributes in `PreviewComponent.tsx` before postMessage'ing them to the
block-editor preview iframe. That change was a shared choke point used by
every embeddable block, and it broke any block whose attribute is an array of
objects (e.g. `filters`, map `legendBreaks`) by turning it into an
unparseable `"[object Object],[object Object]"` string.

`PreviewComponent.tsx` now always JSON-stringifies object/array attributes
again, restoring pre-PR-296 behavior for every block except Tabbed Posts.

The original TCDICORE-601 problem — the Tabbed Posts editor preview sending
`categories` as `"[5,7]"` instead of the front-end's comma-separated `"5,7"`
— is now fixed locally inside the Tabbed Posts embeddable component
(`tabbedposts/index.jsx`), which detects a JSON-array-shaped `categories`
string and normalizes it to the comma-separated format the REST API expects,
without changing how any other block's attributes are serialized.
18 changes: 14 additions & 4 deletions packages/dvz-ui/src/embeddable/tabbedposts/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,20 @@ const Wrapper = (props) => {
previewMode = pageModuleProps.previewMode;
editing = pageModuleProps.editing;
}
const locale = props.intl.locale;
const normalizedCategories = Array.isArray(categories)
? categories.join(',').toString()
: categories;
const locale = props.intl.locale;
let normalizedCategories = categories;
if (Array.isArray(categories)) {
normalizedCategories = categories.join(',');
} else if (typeof categories === 'string') {
try {
const parsedCategories = JSON.parse(categories);
if (Array.isArray(parsedCategories)) {
normalizedCategories = parsedCategories.join(',');
}
} catch (e) {
// Not JSON — already a plain string (e.g. "5,7"), use as-is.
}
}

const scrollable = useScrolls === 'true';
const conditionalHeight = scrollable ? height : undefined;
Expand Down
4 changes: 1 addition & 3 deletions packages/dvz-ui/src/layout/PreviewComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const PreviewComponentParameterParser = () => {
const newParams: Record<string, string> = { ...paramPropsRef.current };
Object.keys(data).forEach(k => {
newParams["data-" + k.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()] =
typeof data[k] === 'object'
? (Array.isArray(data[k]) ? data[k].join(',') : JSON.stringify(data[k]))
: data[k];
typeof data[k] === 'object' ? JSON.stringify(data[k]) : data[k];
});
setParamProps(newParams);
}
Expand Down
Loading