generated from DFE-Digital/govuk-dotnet-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WiP: Details component * WiP: details migration script * WiP: details component migration script * WiP: async added * migrations file updated * edits to details migration file * rectify error on details view * details component finalised * feat: completed Details component * sonar checkout version updated and fetch-depth set to 0 * exclude Contentful migrations on sonar checks * feat: details component --------- Co-authored-by: Maria <[email protected]>
- Loading branch information
Showing
13 changed files
with
218 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,68 @@ | ||
name: Static code analysis | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- next | ||
jobs: | ||
code-analysis: | ||
name: Static code analysis | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- next | ||
jobs: | ||
code-analysis: | ||
name: Static code analysis | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: 'zulu' # Alternative distribution options are available. | ||
|
||
- name: Cache SonarCloud packages | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~\sonar\cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
|
||
- name: Cache SonarCloud scanner | ||
id: cache-sonar-scanner | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~\sonar\cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
|
||
- name: Cache SonarCloud coverage | ||
id: cache-sonar-coverage | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~\sonar\cache | ||
key: ${{ runner.os }}-coverage | ||
restore-keys: ${{ runner.os }}-coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install SonarCloud scanners | ||
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' | ||
run: dotnet tool install --global dotnet-sonarscanner | ||
|
||
- name: Install SonarCloud coverage | ||
if: steps.cache-sonar-coverage.outputs.cache-hit != 'true' | ||
run: dotnet tool install --global dotnet-coverage | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: "zulu" # Alternative distribution options are available. | ||
|
||
- name: Build, Test and Analyze | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
run: | | ||
dotnet-sonarscanner begin \ | ||
/k:"DFE-Digital_childrens-social-care-cpd" \ | ||
/o:"dfe-digital" \ | ||
/d:sonar.qualitygate.wait=true \ | ||
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \ | ||
/d:sonar.exclusions="**/*.css,**/*.scss,**/Models/*,**/Program.cs,**/WebApplicationBuilderExtensions.cs,**/GraphQL/Queries/*" \ | ||
/d:sonar.test.exclusions="Childrens-Social-Care-CPD-Tests/**/*" \ | ||
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ | ||
/d:sonar.host.url="https://sonarcloud.io" | ||
dotnet build --no-incremental | ||
dotnet-coverage collect --settings dotnet-cover-config.xml -f xml -o coverage.xml "dotnet test" | ||
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" | ||
- name: Cache SonarCloud packages | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~\sonar\cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
|
||
- name: Cache SonarCloud scanner | ||
id: cache-sonar-scanner | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~\sonar\cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
|
||
- name: Cache SonarCloud coverage | ||
id: cache-sonar-coverage | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~\sonar\cache | ||
key: ${{ runner.os }}-coverage | ||
restore-keys: ${{ runner.os }}-coverage | ||
|
||
- name: Install SonarCloud scanners | ||
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' | ||
run: dotnet tool install --global dotnet-sonarscanner | ||
|
||
- name: Install SonarCloud coverage | ||
if: steps.cache-sonar-coverage.outputs.cache-hit != 'true' | ||
run: dotnet tool install --global dotnet-coverage | ||
|
||
- name: Build, Test and Analyze | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
run: | | ||
dotnet-sonarscanner begin \ | ||
/k:"DFE-Digital_childrens-social-care-cpd" \ | ||
/o:"dfe-digital" \ | ||
/d:sonar.qualitygate.wait=true \ | ||
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \ | ||
/d:sonar.exclusions="**/*.css,**/*.scss,**/Models/*,**/Program.cs,**/WebApplicationBuilderExtensions.cs,**/GraphQL/Queries/*,**/Contentful-Schema/migrations/*.cjs" \ | ||
/d:sonar.test.exclusions="Childrens-Social-Care-CPD-Tests/**/*" \ | ||
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ | ||
/d:sonar.host.url="https://sonarcloud.io" | ||
dotnet build --no-incremental | ||
dotnet-coverage collect --settings dotnet-cover-config.xml -f xml -o coverage.xml "dotnet test" | ||
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
<details class="govuk-details"> | ||
<summary class="govuk-details__summary"> | ||
<span class="govuk-details__summary-text"> | ||
@Model.SummaryText | ||
</span> | ||
</summary> | ||
<div class="govuk-details__text"> | ||
<partial name="_RichText" model="Model.DetailsText" /> | ||
</div> | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.