diff --git a/.changeset/tabbed-posts-category-fix-scoped.md b/.changeset/tabbed-posts-category-fix-scoped.md new file mode 100644 index 000000000..1ed005ce6 --- /dev/null +++ b/.changeset/tabbed-posts-category-fix-scoped.md @@ -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. diff --git a/packages/dvz-ui/src/embeddable/tabbedposts/index.jsx b/packages/dvz-ui/src/embeddable/tabbedposts/index.jsx index ca84c7f70..35a688385 100644 --- a/packages/dvz-ui/src/embeddable/tabbedposts/index.jsx +++ b/packages/dvz-ui/src/embeddable/tabbedposts/index.jsx @@ -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; diff --git a/packages/dvz-ui/src/layout/PreviewComponent.tsx b/packages/dvz-ui/src/layout/PreviewComponent.tsx index 51be2cc5c..a0088b656 100644 --- a/packages/dvz-ui/src/layout/PreviewComponent.tsx +++ b/packages/dvz-ui/src/layout/PreviewComponent.tsx @@ -28,9 +28,7 @@ const PreviewComponentParameterParser = () => { const newParams: Record = { ...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); }