From cff116aca4568008459b900d98f970728884cf3a Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Tue, 3 Nov 2026 13:30:26 +0300 Subject: [PATCH 1/2] fix(timeline): keep point config in sync with number of posts The 'Number of Posts' control saved a config built from the previous count, so adding posts left the saved config shorter than the post list and the front end crashed. Build the config for the new count, and repair short configs already saved in existing blocks when the editor loads. --- .changeset/calm-points-sync.md | 5 ++ .../blocks/new-time-line/BlockEdit.js | 70 ++++++++++++------- .../blocks/time-line/BlockEdit.js | 70 ++++++++++++------- 3 files changed, 97 insertions(+), 48 deletions(-) create mode 100644 .changeset/calm-points-sync.md diff --git a/.changeset/calm-points-sync.md b/.changeset/calm-points-sync.md new file mode 100644 index 000000000..36bb7c05b --- /dev/null +++ b/.changeset/calm-points-sync.md @@ -0,0 +1,5 @@ +--- +"@devgateway/dvz-wp-commons": patch +--- + +Fix timeline blocks saving fewer point configs than posts when increasing the number of posts, which crashed the timeline on the front end diff --git a/plugins/wp-react-blocks-plugin/blocks/new-time-line/BlockEdit.js b/plugins/wp-react-blocks-plugin/blocks/new-time-line/BlockEdit.js index 38a09d154..a874b391c 100644 --- a/plugins/wp-react-blocks-plugin/blocks/new-time-line/BlockEdit.js +++ b/plugins/wp-react-blocks-plugin/blocks/new-time-line/BlockEdit.js @@ -37,6 +37,35 @@ const FontSelector = (props) => { /> } +/** + * Builds the per-point configuration for `count` points, keeping any existing + * entries and creating defaults for the new ones. Used both for rendering and + * when the number of posts changes, so the saved config always matches `count`. + */ +const buildConfig = (config, count) => { + const current = Array.isArray(config) ? config : [] + const result = [] + for (let i = 0; i < (count || 0); i++) { + if (!current[i]) { + result.push({ + circleColor: COLORS[i] || "#000000", + lineColor: COLORS[i] || "#000000", + labelColor: "#000000", + titleColor: COLORS[i] || "#000000", + size: 10, + subtitleOffset: 20, + titleOffset: (i % 2 > 0) ? 120 : -120, + connectorLineHeight: 100, + position: (i % 2 > 0) ? "bottom" : "top", + readMoreLabel: "read more" + }) + } else { + result.push(Object.assign({}, current[i])) + } + } + return result +} + class BlockEdit extends BlockEditWithFilters { constructor(props) { @@ -45,6 +74,16 @@ class BlockEdit extends BlockEditWithFilters { this.onLoadPosts = this.onLoadPosts.bind(this) } + componentDidMount() { + super.componentDidMount() + // Blocks saved before this fix may have fewer point configs than posts; + // persist the missing ones so the front end gets a complete config. + const {setAttributes, attributes: {config, count}} = this.props + if (count && (!Array.isArray(config) || config.length < count)) { + setAttributes({config: buildConfig(config, count)}) + } + } + onLoadPosts() { const { @@ -107,27 +146,7 @@ class BlockEdit extends BlockEditWithFilters { const divStyles = {height: height + 'px', width: '100%'} - const newConfig = [] - if (count) { - Array.from(Array(count).keys()).forEach(i => { - if (!config[i]) { - newConfig.push({ - circleColor: COLORS[i] || "#000000", - lineColor: COLORS[i]|| "#000000", - labelColor: "#000000", - titleColor: COLORS[i] || "#000000", - size: 10, - subtitleOffset: 20, - titleOffset: (i % 2 > 0) ? 120 : -120, - connectorLineHeight: 100, - position: (i % 2 > 0) ? "bottom" : "top", - readMoreLabel: "read more" - }) - } else { - newConfig.push(Object.assign({}, config[i])) - } - }) - } + const newConfig = buildConfig(config, count) @@ -148,9 +167,12 @@ class BlockEdit extends BlockEditWithFilters { { - setAttributes({count: parseInt(count)}) - setAttributes({config: newConfig}) + onChange={(value) => { + const newCount = parseInt(value) + if (isNaN(newCount)) { + return + } + setAttributes({count: newCount, config: buildConfig(config, newCount)}) }} shiftStep={1} min={1} diff --git a/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js b/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js index 36dfc20d8..98469edb3 100644 --- a/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js +++ b/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js @@ -37,6 +37,35 @@ const FontSelector = (props) => { /> } +/** + * Builds the per-point configuration for `count` points, keeping any existing + * entries and creating defaults for the new ones. Used both for rendering and + * when the number of posts changes, so the saved config always matches `count`. + */ +const buildConfig = (config, count) => { + const current = Array.isArray(config) ? config : [] + const result = [] + for (let i = 0; i < (count || 0); i++) { + if (!current[i]) { + result.push({ + circleColor: COLORS[i] || "#000000", + lineColor: COLORS[i] || "#000000", + labelColor: "#000000", + titleColor: COLORS[i] || "#000000", + size: 10, + subtitleOffset: 20, + titleOffset: (i % 2 > 0) ? 120 : -120, + connectorLineHeight: 100, + position: (i % 2 > 0) ? "bottom" : "top", + readMoreLabel: "read more" + }) + } else { + result.push(Object.assign({}, current[i])) + } + } + return result +} + class BlockEdit extends BlockEditWithFilters { constructor(props) { @@ -45,6 +74,16 @@ class BlockEdit extends BlockEditWithFilters { this.onLoadPosts = this.onLoadPosts.bind(this) } + componentDidMount() { + super.componentDidMount() + // Blocks saved before this fix may have fewer point configs than posts; + // persist the missing ones so the front end gets a complete config. + const {setAttributes, attributes: {config, count}} = this.props + if (count && (!Array.isArray(config) || config.length < count)) { + setAttributes({config: buildConfig(config, count)}) + } + } + onLoadPosts() { const { @@ -114,27 +153,7 @@ class BlockEdit extends BlockEditWithFilters { const divStyles = {height: height + 'px', width: '100%'} - const newConfig = [] - if (count) { - Array.from(Array(count).keys()).forEach(i => { - if (!config[i]) { - newConfig.push({ - circleColor: COLORS[i] || "#000000", - lineColor: COLORS[i]|| "#000000", - labelColor: "#000000", - titleColor: COLORS[i] || "#000000", - size: 10, - subtitleOffset: 20, - titleOffset: (i % 2 > 0) ? 120 : -120, - connectorLineHeight: 100, - position: (i % 2 > 0) ? "bottom" : "top", - readMoreLabel: "read more" - }) - } else { - newConfig.push(Object.assign({}, config[i])) - } - }) - } + const newConfig = buildConfig(config, count) @@ -154,9 +173,12 @@ class BlockEdit extends BlockEditWithFilters { { - setAttributes({count: parseInt(count)}) - setAttributes({config: newConfig}) + onChange={(value) => { + const newCount = parseInt(value) + if (isNaN(newCount)) { + return + } + setAttributes({count: newCount, config: buildConfig(config, newCount)}) }} shiftStep={1} min={1} From 4deb32f4e4217a3206ecdfdbed13dd6bee75e85a Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Tue, 3 Nov 2026 14:17:07 +0300 Subject: [PATCH 2/2] chore: remove unneeded changeset --- .changeset/calm-points-sync.md | 5 -- .../blocks/new-time-line/BlockEdit.js | 70 +++++++------------ .../blocks/time-line/BlockEdit.js | 70 +++++++------------ 3 files changed, 48 insertions(+), 97 deletions(-) delete mode 100644 .changeset/calm-points-sync.md diff --git a/.changeset/calm-points-sync.md b/.changeset/calm-points-sync.md deleted file mode 100644 index 36bb7c05b..000000000 --- a/.changeset/calm-points-sync.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@devgateway/dvz-wp-commons": patch ---- - -Fix timeline blocks saving fewer point configs than posts when increasing the number of posts, which crashed the timeline on the front end diff --git a/plugins/wp-react-blocks-plugin/blocks/new-time-line/BlockEdit.js b/plugins/wp-react-blocks-plugin/blocks/new-time-line/BlockEdit.js index a874b391c..38a09d154 100644 --- a/plugins/wp-react-blocks-plugin/blocks/new-time-line/BlockEdit.js +++ b/plugins/wp-react-blocks-plugin/blocks/new-time-line/BlockEdit.js @@ -37,35 +37,6 @@ const FontSelector = (props) => { /> } -/** - * Builds the per-point configuration for `count` points, keeping any existing - * entries and creating defaults for the new ones. Used both for rendering and - * when the number of posts changes, so the saved config always matches `count`. - */ -const buildConfig = (config, count) => { - const current = Array.isArray(config) ? config : [] - const result = [] - for (let i = 0; i < (count || 0); i++) { - if (!current[i]) { - result.push({ - circleColor: COLORS[i] || "#000000", - lineColor: COLORS[i] || "#000000", - labelColor: "#000000", - titleColor: COLORS[i] || "#000000", - size: 10, - subtitleOffset: 20, - titleOffset: (i % 2 > 0) ? 120 : -120, - connectorLineHeight: 100, - position: (i % 2 > 0) ? "bottom" : "top", - readMoreLabel: "read more" - }) - } else { - result.push(Object.assign({}, current[i])) - } - } - return result -} - class BlockEdit extends BlockEditWithFilters { constructor(props) { @@ -74,16 +45,6 @@ class BlockEdit extends BlockEditWithFilters { this.onLoadPosts = this.onLoadPosts.bind(this) } - componentDidMount() { - super.componentDidMount() - // Blocks saved before this fix may have fewer point configs than posts; - // persist the missing ones so the front end gets a complete config. - const {setAttributes, attributes: {config, count}} = this.props - if (count && (!Array.isArray(config) || config.length < count)) { - setAttributes({config: buildConfig(config, count)}) - } - } - onLoadPosts() { const { @@ -146,7 +107,27 @@ class BlockEdit extends BlockEditWithFilters { const divStyles = {height: height + 'px', width: '100%'} - const newConfig = buildConfig(config, count) + const newConfig = [] + if (count) { + Array.from(Array(count).keys()).forEach(i => { + if (!config[i]) { + newConfig.push({ + circleColor: COLORS[i] || "#000000", + lineColor: COLORS[i]|| "#000000", + labelColor: "#000000", + titleColor: COLORS[i] || "#000000", + size: 10, + subtitleOffset: 20, + titleOffset: (i % 2 > 0) ? 120 : -120, + connectorLineHeight: 100, + position: (i % 2 > 0) ? "bottom" : "top", + readMoreLabel: "read more" + }) + } else { + newConfig.push(Object.assign({}, config[i])) + } + }) + } @@ -167,12 +148,9 @@ class BlockEdit extends BlockEditWithFilters { { - const newCount = parseInt(value) - if (isNaN(newCount)) { - return - } - setAttributes({count: newCount, config: buildConfig(config, newCount)}) + onChange={(count) => { + setAttributes({count: parseInt(count)}) + setAttributes({config: newConfig}) }} shiftStep={1} min={1} diff --git a/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js b/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js index 98469edb3..36dfc20d8 100644 --- a/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js +++ b/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js @@ -37,35 +37,6 @@ const FontSelector = (props) => { /> } -/** - * Builds the per-point configuration for `count` points, keeping any existing - * entries and creating defaults for the new ones. Used both for rendering and - * when the number of posts changes, so the saved config always matches `count`. - */ -const buildConfig = (config, count) => { - const current = Array.isArray(config) ? config : [] - const result = [] - for (let i = 0; i < (count || 0); i++) { - if (!current[i]) { - result.push({ - circleColor: COLORS[i] || "#000000", - lineColor: COLORS[i] || "#000000", - labelColor: "#000000", - titleColor: COLORS[i] || "#000000", - size: 10, - subtitleOffset: 20, - titleOffset: (i % 2 > 0) ? 120 : -120, - connectorLineHeight: 100, - position: (i % 2 > 0) ? "bottom" : "top", - readMoreLabel: "read more" - }) - } else { - result.push(Object.assign({}, current[i])) - } - } - return result -} - class BlockEdit extends BlockEditWithFilters { constructor(props) { @@ -74,16 +45,6 @@ class BlockEdit extends BlockEditWithFilters { this.onLoadPosts = this.onLoadPosts.bind(this) } - componentDidMount() { - super.componentDidMount() - // Blocks saved before this fix may have fewer point configs than posts; - // persist the missing ones so the front end gets a complete config. - const {setAttributes, attributes: {config, count}} = this.props - if (count && (!Array.isArray(config) || config.length < count)) { - setAttributes({config: buildConfig(config, count)}) - } - } - onLoadPosts() { const { @@ -153,7 +114,27 @@ class BlockEdit extends BlockEditWithFilters { const divStyles = {height: height + 'px', width: '100%'} - const newConfig = buildConfig(config, count) + const newConfig = [] + if (count) { + Array.from(Array(count).keys()).forEach(i => { + if (!config[i]) { + newConfig.push({ + circleColor: COLORS[i] || "#000000", + lineColor: COLORS[i]|| "#000000", + labelColor: "#000000", + titleColor: COLORS[i] || "#000000", + size: 10, + subtitleOffset: 20, + titleOffset: (i % 2 > 0) ? 120 : -120, + connectorLineHeight: 100, + position: (i % 2 > 0) ? "bottom" : "top", + readMoreLabel: "read more" + }) + } else { + newConfig.push(Object.assign({}, config[i])) + } + }) + } @@ -173,12 +154,9 @@ class BlockEdit extends BlockEditWithFilters { { - const newCount = parseInt(value) - if (isNaN(newCount)) { - return - } - setAttributes({count: newCount, config: buildConfig(config, newCount)}) + onChange={(count) => { + setAttributes({count: parseInt(count)}) + setAttributes({config: newConfig}) }} shiftStep={1} min={1}