From f8b93aff0871ede741e5f784126ae8e531f71f7a Mon Sep 17 00:00:00 2001 From: Andy E Phipps Date: Tue, 12 Mar 2024 18:51:20 +0000 Subject: [PATCH] fix: Rename WYMD Carousel fields (#632) * fix: attemtp to fix carousel syntax issue * Remove need for underscore --- .../Organisms/WYMDCarousel/WYMDCarousel.js | 72 ++++---- .../Organisms/WYMDCarousel/_utils.js | 4 +- src/styleguide/data/data.js | 168 +++++++++--------- 3 files changed, 122 insertions(+), 122 deletions(-) diff --git a/src/components/Organisms/WYMDCarousel/WYMDCarousel.js b/src/components/Organisms/WYMDCarousel/WYMDCarousel.js index b351d364..b5907042 100644 --- a/src/components/Organisms/WYMDCarousel/WYMDCarousel.js +++ b/src/components/Organisms/WYMDCarousel/WYMDCarousel.js @@ -145,87 +145,87 @@ const WYMDCarousel = ({ data, data: { autoPlay, contentful_id: thisID } }) => { WYMDCarousel.propTypes = { data: PropTypes.shape({ // Required 'node' fields: - node1_Amount: PropTypes.string.isRequired, - node1_Copy: PropTypes.string.isRequired, - node1_Image: PropTypes.shape({ + node1Amount: PropTypes.string.isRequired, + node1Copy: PropTypes.string.isRequired, + node1Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string.isRequired }).isRequired }).isRequired, - node2_Amount: PropTypes.string.isRequired, - node2_Copy: PropTypes.string.isRequired, - node2_Image: PropTypes.shape({ + node2Amount: PropTypes.string.isRequired, + node2Copy: PropTypes.string.isRequired, + node2Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string.isRequired }).isRequired }).isRequired, - node3_Amount: PropTypes.string.isRequired, - node3_Copy: PropTypes.string.isRequired, - node3_Image: PropTypes.shape({ + node3Amount: PropTypes.string.isRequired, + node3Copy: PropTypes.string.isRequired, + node3Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string.isRequired }).isRequired }).isRequired, - node4_Amount: PropTypes.string.isRequired, - node4_Copy: PropTypes.string.isRequired, - node4_Image: PropTypes.shape({ + node4Amount: PropTypes.string.isRequired, + node4Copy: PropTypes.string.isRequired, + node4Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string.isRequired }).isRequired }).isRequired, // Non-required 'node' fields: - node5_Amount: PropTypes.string, - node5_Copy: PropTypes.string, - node5_Image: PropTypes.shape({ + node5Amount: PropTypes.string, + node5Copy: PropTypes.string, + node5Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string }) }), - node6_Amount: PropTypes.string, - node6_Copy: PropTypes.string, - node6_Image: PropTypes.shape({ + node6Amount: PropTypes.string, + node6Copy: PropTypes.string, + node6Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string }) }), - node7_Amount: PropTypes.string, - node7_Copy: PropTypes.string, - node7_Image: PropTypes.shape({ + node7Amount: PropTypes.string, + node7Copy: PropTypes.string, + node7Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string }) }), - node8_Amount: PropTypes.string, - node8_Copy: PropTypes.string, - node8_Image: PropTypes.shape({ + node8Amount: PropTypes.string, + node8Copy: PropTypes.string, + node8Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string }) }), - node9_Amount: PropTypes.string, - node9_Copy: PropTypes.string, - node9_Image: PropTypes.shape({ + node9Amount: PropTypes.string, + node9Copy: PropTypes.string, + node9Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string }) }), - node10_Amount: PropTypes.string, - node10_Copy: PropTypes.string, - node10_Image: PropTypes.shape({ + node10Amount: PropTypes.string, + node10Copy: PropTypes.string, + node10Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string }) }), - node11_Amount: PropTypes.string, - node11_Copy: PropTypes.string, - node11_Image: PropTypes.shape({ + node11Amount: PropTypes.string, + node11Copy: PropTypes.string, + node11Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string }) }), - node12_Amount: PropTypes.string, - node12_Copy: PropTypes.string, - node12_Image: PropTypes.shape({ + node12Amount: PropTypes.string, + node12Copy: PropTypes.string, + node12Image: PropTypes.shape({ file: PropTypes.shape({ url: PropTypes.string }) diff --git a/src/components/Organisms/WYMDCarousel/_utils.js b/src/components/Organisms/WYMDCarousel/_utils.js index d797517e..36c90597 100644 --- a/src/components/Organisms/WYMDCarousel/_utils.js +++ b/src/components/Organisms/WYMDCarousel/_utils.js @@ -13,7 +13,7 @@ const formatItems = thisData => { for (let i = 1; i <= possibleNumberOfNodes; i += 1) { // Create a dynamic key prefix based on the counter, obviously matching // the naming convention set at the Content Type level in the CMS - const thisKeyPrefix = `node${i}_`; + const thisKeyPrefix = `node${i}`; // Make an array of objects, each object representing a specific node and its fields: const thisNodeContent = theseKeys @@ -23,7 +23,7 @@ const formatItems = thisData => { // Only assign if we have actually have a value; only the fields for nodes 1-4 are required: if (thisData[thisKey]) { // Use a repeatable, generic key so rendering is a LOT easier: - const simplifedKey = thisKey.split('_').pop().toLowerCase(); + const simplifedKey = thisKey.split(/([0-9])/).pop().toLowerCase(); thisFilteredObj[simplifedKey] = thisData[thisKey]; } return thisFilteredObj; diff --git a/src/styleguide/data/data.js b/src/styleguide/data/data.js index d4af64f1..7d6f5c04 100644 --- a/src/styleguide/data/data.js +++ b/src/styleguide/data/data.js @@ -57,87 +57,87 @@ const carouselItemsComplete = { desktopHeight: 475, headerCopy: 'Over the past two years, we’ve supported', peopleHelpedText: '11.7 million people', - autoplay: false, - node1_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node1_Amount: '1,000', - node1_Image: { + autoPlay: false, + node1Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node1Amount: '1,000', + node1Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node2_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node2_Amount: '750,000', - node2_Image: { + node2Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node2Amount: '750,000', + node2Image: { file: { url: 'https://images.ctfassets.net/zsfivwzfgl3t/5uKnps3prnG6GpTM1EPZdC/8d7264465846de31e3bbb5b6b2c36c8f/014-helping_hand.png' } }, - node3_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node3_Amount: '3,000', - node3_Image: { + node3Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node3Amount: '3,000', + node3Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node4_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node4_Amount: '4,000', - node4_Image: { + node4Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node4Amount: '4,000', + node4Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node5_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node5_Amount: '5,000', - node5_Image: { + node5Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node5Amount: '5,000', + node5Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node6_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node6_Amount: '6,000', - node6_Image: { + node6Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node6Amount: '6,000', + node6Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node7_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node7_Amount: '7,000', - node7_Image: { + node7Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node7Amount: '7,000', + node7Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node8_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node8_Amount: '8,000', - node8_Image: { + node8Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node8Amount: '8,000', + node8Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node9_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node9_Amount: '9,000', - node9_Image: { + node9Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node9Amount: '9,000', + node9Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node10_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node10_Amount: '10,000', - node10_Image: { + node10Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node10Amount: '10,000', + node10Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node11_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node11_Amount: '11,000', - node11_Image: { + node11Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node11Amount: '11,000', + node11Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node12_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.750,000', - node12_Amount: '12,000', - node12_Image: { + node12Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.750,000', + node12Amount: '12,000', + node12Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } @@ -153,73 +153,73 @@ const carouselItemsIncomplete = { headerCopy: 'Over the past two years, we’ve supported', peopleHelpedText: '11.7 million people', autoPlay: false, - node1_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node1_Amount: '1,000', - node1_Image: { + node1Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node1Amount: '1,000', + node1Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node2_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node2_Amount: '750,000', - node2_Image: { + node2Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node2Amount: '750,000', + node2Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node3_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node3_Amount: '3,000', - node3_Image: { + node3Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node3Amount: '3,000', + node3Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node4_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node4_Amount: '4,000', - node4_Image: { + node4Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node4Amount: '4,000', + node4Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node5_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node5_Image: { + node5Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node5Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node6_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node6_Amount: '6,000', - node6_Image: null, - node7_Copy: null, - node7_Amount: null, - node7_Image: null, - node8_Copy: null, - node8_Amount: null, - node8_Image: { + node6Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node6Amount: '6,000', + node6Image: null, + node7Copy: null, + node7Amount: null, + node7Image: null, + node8Copy: null, + node8Amount: null, + node8Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node9_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node9_Amount: null, - node9_Image: null, - node10_Copy: null, - node10_Amount: '10,000', - node10_Image: { + node9Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node9Amount: null, + node9Image: null, + node10Copy: null, + node10Amount: '10,000', + node10Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node11_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node11_Amount: '11,000', - node11_Image: { + node11Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node11Amount: '11,000', + node11Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node12_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.750,000', - node12_Amount: null, - node12_Image: { + node12Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.750,000', + node12Amount: null, + node12Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } @@ -235,30 +235,30 @@ const carouselItemsMinimal = { headerCopy: 'Over the past two years, we’ve supported', peopleHelpedText: '11.7 million people', autoPlay: false, - node1_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node1_Amount: '1,000', - node1_Image: { + node1Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node1Amount: '1,000', + node1Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node2_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node2_Amount: '750,000', - node2_Image: { + node2Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node2Amount: '750,000', + node2Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node3_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node3_Amount: '3,000', - node3_Image: { + node3Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node3Amount: '3,000', + node3Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' } }, - node4_Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', - node4_Amount: '4,000', - node4_Image: { + node4Copy: 'children and young people in the UK and around the world, including with safe homes, good nutrition and access to quality healthcare and education.', + node4Amount: '4,000', + node4Image: { file: { url: '//images.ctfassets.net/zsfivwzfgl3t/45yv3H0XZsvsySHtutQ8vb/1fb6d1afe4037c7dccde743a747f6b4f/Test-Carousel-Icon.png' }