From 9e4741ae809b64d2006826879b61cb68b98f5e8a Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 5 Nov 2026 20:18:58 +0300 Subject: [PATCH 1/2] fix(timeline): restore point config sync with number of posts Re-applies the BlockEdit changes that were reverted by 4deb32f4: building the config for the new count so existing points keep their settings and only new points get defaults, and repairing short saved configs when the block loads. --- .../blocks/new-time-line/BlockEdit.js | 70 ++++++++++++------- .../blocks/time-line/BlockEdit.js | 70 ++++++++++++------- 2 files changed, 92 insertions(+), 48 deletions(-) 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 f52b42279fd1e7d584986efd9d76aadeddf90fd1 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Gachengo <55899373+timothy-mugo@users.noreply.github.com> Date: Fri, 6 Nov 2026 13:04:14 +0300 Subject: [PATCH 2/2] Add tooltipFontColor to BlockEdit.js Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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..622c45ebb 100644 --- a/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js +++ b/plugins/wp-react-blocks-plugin/blocks/time-line/BlockEdit.js @@ -57,7 +57,8 @@ const buildConfig = (config, count) => { titleOffset: (i % 2 > 0) ? 120 : -120, connectorLineHeight: 100, position: (i % 2 > 0) ? "bottom" : "top", - readMoreLabel: "read more" + readMoreLabel: "read more", + tooltipFontColor: "#fff" }) } else { result.push(Object.assign({}, current[i]))