From 8611266b1a3b7c53e9b9c88e3c14379363984b86 Mon Sep 17 00:00:00 2001 From: Maria Date: Fri, 6 Sep 2024 12:27:31 +0100 Subject: [PATCH 1/4] details component except for archive file --- .../Contentful/EntityResolverTests.cs | 1 + .../Contentful/PartialsFactoryTests.cs | 1 + .../Contentful/Models/Details.cs | 9 ++ .../Contentful/PartialsFactory.cs | 1 + .../Views/Shared/_Details.cshtml | 16 +++ .../migrations/0008-details-component.cjs | 99 +++++++++++++++++++ Contentful-Schema/migrations/manifest.txt | 3 +- 7 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 Childrens-Social-Care-CPD/Contentful/Models/Details.cs create mode 100644 Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml create mode 100644 Contentful-Schema/migrations/0008-details-component.cjs diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs index a7486e1e..39372e58 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs @@ -25,6 +25,7 @@ public class EntityResolverTests [TestCase("contentSeparator", typeof(ContentSeparator))] [TestCase("detailedPathway", typeof(DetailedPathway))] [TestCase("detailedRole", typeof(DetailedRole))] + [TestCase("details", typeof(Details))] [TestCase("feedback", typeof(Feedback))] [TestCase("heroBanner", typeof(HeroBanner))] [TestCase("imageCard", typeof(ImageCard))] diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs index 4387a32d..22f2274d 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs @@ -24,6 +24,7 @@ public partial class PartialsFactoryTests new object[] { new ContentsAnchor(), "_ContentsAnchor" }, new object[] { new DetailedPathway(), "_DetailedPathway" }, new object[] { new DetailedRole(), "_DetailedRole" }, + new object[] { new Details(), "_Details" }, new object[] { new Feedback(), "_Feedback" }, new object[] { new HeroBanner(), string.Empty }, new object[] { new LinkCard(), "_LinkCard" }, diff --git a/Childrens-Social-Care-CPD/Contentful/Models/Details.cs b/Childrens-Social-Care-CPD/Contentful/Models/Details.cs new file mode 100644 index 00000000..9fc8ae51 --- /dev/null +++ b/Childrens-Social-Care-CPD/Contentful/Models/Details.cs @@ -0,0 +1,9 @@ +using Contentful.Core.Models; + +namespace Childrens_Social_Care_CPD.Contentful.Models; + +public class Details : IContent +{ + public string SummaryText { get; set; } + public Document DetailsText { get; set; } +} \ No newline at end of file diff --git a/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs b/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs index 73669f0d..906bf0bd 100644 --- a/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs +++ b/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs @@ -27,6 +27,7 @@ public static string GetPartialFor(IContent item) ContentsAnchor => "_ContentsAnchor", DetailedRole => "_DetailedRole", DetailedPathway => "_DetailedPathway", + Details => "_Details", Feedback => "_Feedback", HeroBanner => string.Empty,// skip - handled in specific layout section ImageCard => "_ImageCard", diff --git a/Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml b/Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml new file mode 100644 index 00000000..4de3522a --- /dev/null +++ b/Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml @@ -0,0 +1,16 @@ +@using Childrens_Social_Care_CPD.Contentful; +@using Childrens_Social_Care_CPD.Contentful.Models; +@using Childrens_Social_Care_CPD.Contentful.Renderers; + +@model Details + +
+ + + @Model.SummaryText + + +
+ +
+
\ No newline at end of file diff --git a/Contentful-Schema/migrations/0008-details-component.cjs b/Contentful-Schema/migrations/0008-details-component.cjs new file mode 100644 index 00000000..ffe49ce7 --- /dev/null +++ b/Contentful-Schema/migrations/0008-details-component.cjs @@ -0,0 +1,99 @@ +module.exports = async function (migration, { makeRequest }) { + const details = migration + .createContentType("details") + .name("Details") + .description( + "Allows users to view more detailed information if they need it, as per the GDS component of the same name." + ) + .displayField("summaryText"); + + details + .createField("summaryText") + .name("Summary text") + .type("Symbol") + .localized(false) + .required(true) + .validations([]) + .disabled(false) + .omitted(false); + + details + .createField("detailsText") + .name("Details text") + .type("RichText") + .localized(false) + .required(true) + .validations([ + { + enabledMarks: [ + "bold", + "italic", + "underline", + "code", + "superscript", + "subscript", + ], + message: + "Only bold, italic, underline, code, superscript, and subscript marks are allowed", + }, + { + enabledNodeTypes: [ + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "table", + "asset-hyperlink", + "embedded-entry-inline", + "entry-hyperlink", + "hyperlink", + ], + + message: + "Only heading 1, heading 2, heading 3, heading 4, heading 5, heading 6, ordered list, unordered list, horizontal rule, quote, block entry, asset, table, link to asset, inline entry, link to entry, and link to Url nodes are allowed", + }, + { + nodes: {}, + }, + ]) + .disabled(false) + .omitted(false); + + details.changeFieldControl("summaryText", "builtin", "singleLine", {}); + details.changeFieldControl("detailsText", "builtin", "richTextEditor", {}); + + const contentTypeId = "content", + linkingFieldId = "items", + detailsTypeId = "details"; + + const response = await makeRequest({ + method: "GET", + url: `/content_types?sys.id[in]=${contentTypeId}`, + }); + + const validations = response.items[0].fields + .filter((field) => field.id == linkingFieldId)[0] + .items.validations.map((rule) => { + if ( + rule.linkContentType && + !rule.linkContentType.includes(detailsTypeId) + ) { + rule.linkContentType.push(detailsTypeId); + } + return rule; + }); + + migration.editContentType(contentTypeId).editField(linkingFieldId).items({ + type: "Link", + linkType: "Entry", + validations: validations, + }); +}; diff --git a/Contentful-Schema/migrations/manifest.txt b/Contentful-Schema/migrations/manifest.txt index a975447b..430a1228 100644 --- a/Contentful-Schema/migrations/manifest.txt +++ b/Contentful-Schema/migrations/manifest.txt @@ -4,4 +4,5 @@ 0004-back-to-top-component.cjs 0005-create-employer-standards-page-category.cjs 0006-accordion-component.cjs -0007-add-header-field-to-navigation-menu.cjs \ No newline at end of file +0007-add-header-field-to-navigation-menu.cjs +0008-details-component.cjs \ No newline at end of file From 4fd11280c025e840aad0ab36107cf4bfb115765e Mon Sep 17 00:00:00 2001 From: Maria Date: Fri, 6 Sep 2024 12:38:48 +0100 Subject: [PATCH 2/4] missing test addition --- Childrens-Social-Care-CPD/Contentful/EntityResolver.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs b/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs index 2f5fab1c..084d1019 100644 --- a/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs +++ b/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs @@ -28,6 +28,7 @@ public Type Resolve(string contentTypeId) "contentSeparator" => typeof(ContentSeparator), "detailedPathway" => typeof(DetailedPathway), "detailedRole" => typeof(DetailedRole), + "details" => typeof(Details), "feedback" => typeof(Feedback), "heroBanner" => typeof(HeroBanner), "imageCard" => typeof(ImageCard), From 6490974eab23ae306b74dbb0640d4b2110052298 Mon Sep 17 00:00:00 2001 From: Maria Date: Fri, 6 Sep 2024 12:48:36 +0100 Subject: [PATCH 3/4] Revert "missing test addition" This reverts commit 4fd11280c025e840aad0ab36107cf4bfb115765e. --- Childrens-Social-Care-CPD/Contentful/EntityResolver.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs b/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs index 084d1019..2f5fab1c 100644 --- a/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs +++ b/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs @@ -28,7 +28,6 @@ public Type Resolve(string contentTypeId) "contentSeparator" => typeof(ContentSeparator), "detailedPathway" => typeof(DetailedPathway), "detailedRole" => typeof(DetailedRole), - "details" => typeof(Details), "feedback" => typeof(Feedback), "heroBanner" => typeof(HeroBanner), "imageCard" => typeof(ImageCard), From 28c4228bb1333e85bae6c67066ec5ddc29dcf0cc Mon Sep 17 00:00:00 2001 From: Maria Date: Fri, 6 Sep 2024 12:50:15 +0100 Subject: [PATCH 4/4] Revert "details component except for archive file" This reverts commit 8611266b1a3b7c53e9b9c88e3c14379363984b86. --- .../Contentful/EntityResolverTests.cs | 1 - .../Contentful/PartialsFactoryTests.cs | 1 - .../Contentful/Models/Details.cs | 9 -- .../Contentful/PartialsFactory.cs | 1 - .../Views/Shared/_Details.cshtml | 16 --- .../migrations/0008-details-component.cjs | 99 ------------------- Contentful-Schema/migrations/manifest.txt | 3 +- 7 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 Childrens-Social-Care-CPD/Contentful/Models/Details.cs delete mode 100644 Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml delete mode 100644 Contentful-Schema/migrations/0008-details-component.cjs diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs index 39372e58..a7486e1e 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs @@ -25,7 +25,6 @@ public class EntityResolverTests [TestCase("contentSeparator", typeof(ContentSeparator))] [TestCase("detailedPathway", typeof(DetailedPathway))] [TestCase("detailedRole", typeof(DetailedRole))] - [TestCase("details", typeof(Details))] [TestCase("feedback", typeof(Feedback))] [TestCase("heroBanner", typeof(HeroBanner))] [TestCase("imageCard", typeof(ImageCard))] diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs index 22f2274d..4387a32d 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs @@ -24,7 +24,6 @@ public partial class PartialsFactoryTests new object[] { new ContentsAnchor(), "_ContentsAnchor" }, new object[] { new DetailedPathway(), "_DetailedPathway" }, new object[] { new DetailedRole(), "_DetailedRole" }, - new object[] { new Details(), "_Details" }, new object[] { new Feedback(), "_Feedback" }, new object[] { new HeroBanner(), string.Empty }, new object[] { new LinkCard(), "_LinkCard" }, diff --git a/Childrens-Social-Care-CPD/Contentful/Models/Details.cs b/Childrens-Social-Care-CPD/Contentful/Models/Details.cs deleted file mode 100644 index 9fc8ae51..00000000 --- a/Childrens-Social-Care-CPD/Contentful/Models/Details.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Contentful.Core.Models; - -namespace Childrens_Social_Care_CPD.Contentful.Models; - -public class Details : IContent -{ - public string SummaryText { get; set; } - public Document DetailsText { get; set; } -} \ No newline at end of file diff --git a/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs b/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs index 906bf0bd..73669f0d 100644 --- a/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs +++ b/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs @@ -27,7 +27,6 @@ public static string GetPartialFor(IContent item) ContentsAnchor => "_ContentsAnchor", DetailedRole => "_DetailedRole", DetailedPathway => "_DetailedPathway", - Details => "_Details", Feedback => "_Feedback", HeroBanner => string.Empty,// skip - handled in specific layout section ImageCard => "_ImageCard", diff --git a/Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml b/Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml deleted file mode 100644 index 4de3522a..00000000 --- a/Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml +++ /dev/null @@ -1,16 +0,0 @@ -@using Childrens_Social_Care_CPD.Contentful; -@using Childrens_Social_Care_CPD.Contentful.Models; -@using Childrens_Social_Care_CPD.Contentful.Renderers; - -@model Details - -
- - - @Model.SummaryText - - -
- -
-
\ No newline at end of file diff --git a/Contentful-Schema/migrations/0008-details-component.cjs b/Contentful-Schema/migrations/0008-details-component.cjs deleted file mode 100644 index ffe49ce7..00000000 --- a/Contentful-Schema/migrations/0008-details-component.cjs +++ /dev/null @@ -1,99 +0,0 @@ -module.exports = async function (migration, { makeRequest }) { - const details = migration - .createContentType("details") - .name("Details") - .description( - "Allows users to view more detailed information if they need it, as per the GDS component of the same name." - ) - .displayField("summaryText"); - - details - .createField("summaryText") - .name("Summary text") - .type("Symbol") - .localized(false) - .required(true) - .validations([]) - .disabled(false) - .omitted(false); - - details - .createField("detailsText") - .name("Details text") - .type("RichText") - .localized(false) - .required(true) - .validations([ - { - enabledMarks: [ - "bold", - "italic", - "underline", - "code", - "superscript", - "subscript", - ], - message: - "Only bold, italic, underline, code, superscript, and subscript marks are allowed", - }, - { - enabledNodeTypes: [ - "heading-1", - "heading-2", - "heading-3", - "heading-4", - "heading-5", - "heading-6", - "ordered-list", - "unordered-list", - "hr", - "blockquote", - "embedded-entry-block", - "embedded-asset-block", - "table", - "asset-hyperlink", - "embedded-entry-inline", - "entry-hyperlink", - "hyperlink", - ], - - message: - "Only heading 1, heading 2, heading 3, heading 4, heading 5, heading 6, ordered list, unordered list, horizontal rule, quote, block entry, asset, table, link to asset, inline entry, link to entry, and link to Url nodes are allowed", - }, - { - nodes: {}, - }, - ]) - .disabled(false) - .omitted(false); - - details.changeFieldControl("summaryText", "builtin", "singleLine", {}); - details.changeFieldControl("detailsText", "builtin", "richTextEditor", {}); - - const contentTypeId = "content", - linkingFieldId = "items", - detailsTypeId = "details"; - - const response = await makeRequest({ - method: "GET", - url: `/content_types?sys.id[in]=${contentTypeId}`, - }); - - const validations = response.items[0].fields - .filter((field) => field.id == linkingFieldId)[0] - .items.validations.map((rule) => { - if ( - rule.linkContentType && - !rule.linkContentType.includes(detailsTypeId) - ) { - rule.linkContentType.push(detailsTypeId); - } - return rule; - }); - - migration.editContentType(contentTypeId).editField(linkingFieldId).items({ - type: "Link", - linkType: "Entry", - validations: validations, - }); -}; diff --git a/Contentful-Schema/migrations/manifest.txt b/Contentful-Schema/migrations/manifest.txt index 430a1228..a975447b 100644 --- a/Contentful-Schema/migrations/manifest.txt +++ b/Contentful-Schema/migrations/manifest.txt @@ -4,5 +4,4 @@ 0004-back-to-top-component.cjs 0005-create-employer-standards-page-category.cjs 0006-accordion-component.cjs -0007-add-header-field-to-navigation-menu.cjs -0008-details-component.cjs \ No newline at end of file +0007-add-header-field-to-navigation-menu.cjs \ No newline at end of file