@eeacms/volto-widget-toggle 2.2.2 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,15 +4,40 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [2.2.6](https://github.com/eea/volto-widget-toggle/compare/2.2.5...2.2.6)
8
+
9
+
10
+ #### [2.2.5](https://github.com/eea/volto-widget-toggle/compare/2.2.4...2.2.5)
11
+
12
+ > 16 December 2021
13
+
14
+ - Add SonarQube badges [`#7`](https://github.com/eea/volto-widget-toggle/pull/7)
15
+
16
+ #### [2.2.4](https://github.com/eea/volto-widget-toggle/compare/2.2.3...2.2.4)
17
+
18
+ > 10 December 2021
19
+
20
+ - Develop [`#6`](https://github.com/eea/volto-widget-toggle/pull/6)
21
+ - Correct Cypress tests [`#5`](https://github.com/eea/volto-widget-toggle/pull/5)
22
+ - Refs #142010 - Optimize Volto-addons gitflow pipelines [`2bd2039`](https://github.com/eea/volto-widget-toggle/commit/2bd203979963ee5cb15592470e1d341d1bd65291)
23
+
24
+ #### [2.2.3](https://github.com/eea/volto-widget-toggle/compare/2.2.2...2.2.3)
25
+
26
+ > 28 June 2021
27
+
28
+ - refactor code, introduce defaultValue prop to handle default state when value is null or undefined [`#4`](https://github.com/eea/volto-widget-toggle/pull/4)
29
+ - refactor code, introduce defaultValue prop to handle default state when value is null [`560d23f`](https://github.com/eea/volto-widget-toggle/commit/560d23f785e7780cdb30197c2ebc999b85961f46)
30
+
7
31
  #### [2.2.2](https://github.com/eea/volto-widget-toggle/compare/2.2.1...2.2.2)
8
32
 
9
- - Cypress coverage [`0b37475`](https://github.com/eea/volto-widget-toggle/commit/0b37475868061a61be13cf53747fa9ffdd694365)
33
+ > 4 June 2021
34
+
35
+ - Cypress coverage [`#3`](https://github.com/eea/volto-widget-toggle/pull/3)
10
36
 
11
37
  #### [2.2.1](https://github.com/eea/volto-widget-toggle/compare/2.2.0...2.2.1)
12
38
 
13
39
  > 14 May 2021
14
40
 
15
- - [JENKINS] - Auto-release pipeline [`#2`](https://github.com/eea/volto-widget-toggle/pull/2)
16
41
 
17
42
  #### [2.2.0](https://github.com/eea/volto-widget-toggle/compare/2.1.0...2.2.0)
18
43
 
@@ -26,7 +51,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
26
51
  > 8 March 2021
27
52
 
28
53
  - Release 2.1.0 [`8a77751`](https://github.com/eea/volto-widget-toggle/commit/8a77751a8eaa3817f4831a21365768387321dc50)
29
- - Cleanup DEPENDENCIES from Jenkinsfile [`41eb8ba`](https://github.com/eea/volto-widget-toggle/commit/41eb8ba076da6feed4bfc8f05ed1c18678b4a434)
30
54
 
31
55
  ### [2.0.0](https://github.com/eea/volto-widget-toggle/compare/1.0.1...2.0.0)
32
56
 
@@ -41,8 +65,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
41
65
 
42
66
  - Release 1.0.1 [`454220f`](https://github.com/eea/volto-widget-toggle/commit/454220fa61495427f874fb9b56401fe69689f4fe)
43
67
  - Auto-release npm [`10b31b3`](https://github.com/eea/volto-widget-toggle/commit/10b31b3b64330d41f69a033a45030e49d20c16b5)
44
- - [JENKINS] - Add pipeline, update docs [`fb5c3ac`](https://github.com/eea/volto-widget-toggle/commit/fb5c3ac401b10e07dd67949d01eae116d7458a79)
45
- - yarn prettier [`5136059`](https://github.com/eea/volto-widget-toggle/commit/51360595bf452c815e526ce10f15aa8a84ad186f)
46
68
 
47
69
  ### [1.0.0](https://github.com/eea/volto-widget-toggle/compare/0.1.0...1.0.0)
48
70
 
package/Jenkinsfile CHANGED
@@ -4,13 +4,37 @@ pipeline {
4
4
  environment {
5
5
  GIT_NAME = "volto-widget-toggle"
6
6
  NAMESPACE = "@eeacms"
7
- SONARQUBE_TAGS = "volto.eea.europa.eu"
7
+ SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater"
8
8
  DEPENDENCIES = ""
9
9
  }
10
10
 
11
11
  stages {
12
12
 
13
+ stage('Release') {
14
+ when {
15
+ allOf {
16
+ environment name: 'CHANGE_ID', value: ''
17
+ branch 'master'
18
+ }
19
+ }
20
+ steps {
21
+ node(label: 'docker') {
22
+ withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
23
+ sh '''docker pull eeacms/gitflow'''
24
+ sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-master" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e GIT_TOKEN="$GITHUB_TOKEN" -e NPM_TOKEN="$NPM_TOKEN" -e LANGUAGE=javascript eeacms/gitflow'''
25
+ }
26
+ }
27
+ }
28
+ }
29
+
13
30
  stage('Code') {
31
+ when {
32
+ allOf {
33
+ environment name: 'CHANGE_ID', value: ''
34
+ not { changelog '.*^Automated release [0-9\\.]+$' }
35
+ not { branch 'master' }
36
+ }
37
+ }
14
38
  steps {
15
39
  parallel(
16
40
 
@@ -36,6 +60,15 @@ pipeline {
36
60
  }
37
61
 
38
62
  stage('Tests') {
63
+ when {
64
+ allOf {
65
+ environment name: 'CHANGE_ID', value: ''
66
+ anyOf {
67
+ not { changelog '.*^Automated release [0-9\\.]+$' }
68
+ branch 'master'
69
+ }
70
+ }
71
+ }
39
72
  steps {
40
73
  parallel(
41
74
 
@@ -75,6 +108,15 @@ pipeline {
75
108
  }
76
109
 
77
110
  stage('Integration tests') {
111
+ when {
112
+ allOf {
113
+ environment name: 'CHANGE_ID', value: ''
114
+ anyOf {
115
+ not { changelog '.*^Automated release [0-9\\.]+$' }
116
+ branch 'master'
117
+ }
118
+ }
119
+ }
78
120
  steps {
79
121
  parallel(
80
122
 
@@ -82,7 +124,7 @@ pipeline {
82
124
  node(label: 'docker') {
83
125
  script {
84
126
  try {
85
- sh '''docker pull plone; docker run -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
127
+ sh '''docker pull plone; docker run -d --rm --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
86
128
  sh '''docker pull plone/volto-addon-ci; docker run -i --name="$BUILD_TAG-cypress" --link $BUILD_TAG-plone:plone -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e DEPENDENCIES="$DEPENDENCIES" plone/volto-addon-ci cypress'''
87
129
  } finally {
88
130
  try {
@@ -100,7 +142,8 @@ pipeline {
100
142
  reportName: 'CypressCoverage',
101
143
  reportTitles: 'Integration Tests Code Coverage'])
102
144
  }
103
- archiveArtifacts artifacts: 'cypress-reports/videos/*.mp4', fingerprint: true
145
+ sh '''touch empty_file; for ok_test in $(grep -E 'file=.*failures="0"' $(grep 'testsuites .*failures="0"' $(find cypress-results -name *.xml) empty_file | awk -F: '{print $1}') empty_file | sed 's/.* file="\\(.*\\)" time.*/\\1/' | sed 's#^cypress/integration/##g' | sed 's#^../../../node_modules/@eeacms/##g'); do rm -f cypress-reports/videos/$ok_test.mp4; rm -f cypress-reports/$ok_test.mp4; done'''
146
+ archiveArtifacts artifacts: 'cypress-reports/**/*.mp4', fingerprint: true, allowEmptyArchive: true
104
147
  stash name: "cypress-coverage", includes: "cypress-coverage/**", allowEmpty: true
105
148
  }
106
149
  finally {
@@ -122,10 +165,16 @@ pipeline {
122
165
  }
123
166
 
124
167
  stage('Report to SonarQube') {
125
- // Exclude Pull-Requests
126
168
  when {
127
169
  allOf {
128
170
  environment name: 'CHANGE_ID', value: ''
171
+ anyOf {
172
+ branch 'master'
173
+ allOf {
174
+ branch 'develop'
175
+ not { changelog '.*^Automated release [0-9\\.]+$' }
176
+ }
177
+ }
129
178
  }
130
179
  }
131
180
  steps {
@@ -156,8 +205,8 @@ pipeline {
156
205
  steps {
157
206
  node(label: 'docker') {
158
207
  script {
159
- if ( env.CHANGE_BRANCH != "develop" && !( env.CHANGE_BRANCH.startsWith("hotfix")) ) {
160
- error "Pipeline aborted due to PR not made from develop or hotfix branch"
208
+ if ( env.CHANGE_BRANCH != "develop" ) {
209
+ error "Pipeline aborted due to PR not made from develop branch"
161
210
  }
162
211
  withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) {
163
212
  sh '''docker pull eeacms/gitflow'''
@@ -168,23 +217,6 @@ pipeline {
168
217
  }
169
218
  }
170
219
 
171
- stage('Release') {
172
- when {
173
- allOf {
174
- environment name: 'CHANGE_ID', value: ''
175
- branch 'master'
176
- }
177
- }
178
- steps {
179
- node(label: 'docker') {
180
- withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
181
- sh '''docker pull eeacms/gitflow'''
182
- sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-master" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e GIT_TOKEN="$GITHUB_TOKEN" -e NPM_TOKEN="$NPM_TOKEN" -e LANGUAGE=javascript eeacms/gitflow'''
183
- }
184
- }
185
- }
186
- }
187
-
188
220
  }
189
221
 
190
222
  post {
package/README.md CHANGED
@@ -1,7 +1,19 @@
1
1
  # volto-widget-toggle
2
+
2
3
  [![Releases](https://img.shields.io/github/v/release/eea/volto-widget-toggle)](https://github.com/eea/volto-widget-toggle/releases)
4
+
3
5
  [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-widget-toggle%2Fmaster&subject=master)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-widget-toggle/job/master/display/redirect)
6
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-widget-toggle-master&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-master)
7
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-widget-toggle-master&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-master)
8
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-widget-toggle-master&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-master)
9
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-widget-toggle-master&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-master)
10
+
4
11
  [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-widget-toggle%2Fdevelop&subject=develop)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-widget-toggle/job/develop/display/redirect)
12
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-widget-toggle-develop&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-develop)
13
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-widget-toggle-develop&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-develop)
14
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-widget-toggle-develop&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-develop)
15
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-widget-toggle-develop&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-develop)
16
+
5
17
 
6
18
  [Volto](https://github.com/plone/volto) add-on: Replace any checkbox with a nice toggle button within edit forms
7
19
 
@@ -44,6 +56,81 @@
44
56
 
45
57
  1. Happy editing!
46
58
 
59
+ ## Release
60
+
61
+ ### Automatic release using Jenkins
62
+
63
+ * The automatic release is started by creating a [Pull Request](../../compare/master...develop) from `develop` to `master`. The pull request status checks correlated to the branch and PR Jenkins jobs need to be processed successfully. 1 review from a github user with rights is mandatory.
64
+ * It runs on every commit on `master` branch, which is protected from direct commits, only allowing pull request merge commits.
65
+ * The automatic release is done by [Jenkins](https://ci.eionet.europa.eu). The status of the release job can be seen both in the Readme.md badges and the green check/red cross/yellow circle near the last commit information. If you click on the icon, you will have the list of checks that were run. The `continuous-integration/jenkins/branch` link goes to the Jenkins job execution webpage.
66
+ * Automated release scripts are located in the `eeacms/gitflow` docker image, specifically [js-release.sh](https://github.com/eea/eea.docker.gitflow/blob/master/src/js-release.sh) script. It uses the `release-it` tool.
67
+ * As long as a PR request is open from develop to master, the PR Jenkins job will automatically re-create the CHANGELOG.md and package.json files to be production-ready.
68
+ * The version format must be MAJOR.MINOR.PATCH. By default, next release is set to next minor version (with patch 0).
69
+ * You can manually change the version in `package.json`. The new version must not be already present in the tags/releases of the repository, otherwise it will be automatically increased by the script. Any changes to the version will trigger a `CHANGELOG.md` re-generation.
70
+ * Automated commits and commits with [JENKINS] or [YARN] in the commit log are excluded from `CHANGELOG.md` file.
71
+
72
+ ### Manual release from the develop branch ( beta release )
73
+
74
+ #### Installation and configuration of release-it
75
+
76
+ You need to first install the [release-it](https://github.com/release-it/release-it) client.
77
+
78
+ ```
79
+ npm install -g release-it
80
+ ```
81
+
82
+ Release-it uses the configuration written in the [`.release-it.json`](./.release-it.json) file located in the root of the repository.
83
+
84
+ Release-it is a tool that automates 4 important steps in the release process:
85
+
86
+ 1. Version increase in `package.json` ( increased from the current version in `package.json`)
87
+ 2. `CHANGELOG.md` automatic generation from commit messages ( grouped by releases )
88
+ 3. GitHub release on the commit with the changelog and package.json modification on the develop branch
89
+ 4. NPM release ( by default it's disabled, but can be enabled in the configuration file )
90
+
91
+ To configure the authentification, you need to export GITHUB_TOKEN for [GitHub](https://github.com/settings/tokens)
92
+
93
+ ```
94
+ export GITHUB_TOKEN=XXX-XXXXXXXXXXXXXXXXXXXXXX
95
+ ```
96
+
97
+ To configure npm, you can use the `npm login` command or use a configuration file with a TOKEN :
98
+
99
+ ```
100
+ echo "//registry.npmjs.org/:_authToken=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" > .npmrc
101
+ ```
102
+
103
+ #### Using release-it tool
104
+
105
+ There are 3 yarn scripts that can be run to do the release
106
+
107
+ ##### yarn release-beta
108
+
109
+ Automatically calculates and presents 3 beta versions - patch, minor and major for you to choose ( or Other for manual input).
110
+
111
+ ```
112
+ ? Select increment (next version):
113
+ ❯ prepatch (0.1.1-beta.0)
114
+ preminor (0.2.0-beta.0)
115
+ premajor (1.0.0-beta.0)
116
+ Other, please specify...
117
+ ```
118
+
119
+ ##### yarn release-major-beta
120
+
121
+ Same as `yarn release-beta`, but with premajor version pre-selected.
122
+
123
+ ##### yarn release
124
+
125
+ Generic command, does not automatically add the `beta` to version, but you can still manually write it if you choose Other.
126
+
127
+ #### Important notes
128
+
129
+ > Do not use release-it tool on master branch, the commit on CHANGELOG.md file and the version increase in the package.json file can't be done without a PULL REQUEST.
130
+
131
+ > Do not keep Pull Requests from develop to master branches open when you are doing beta releases from the develop branch. As long as a PR to master is open, an automatic script will run on every commit and will update both the version and the changelog to a production-ready state - ( MAJOR.MINOR.PATCH mandatory format for version).
132
+
133
+
47
134
  ## How to contribute
48
135
 
49
136
  See [DEVELOP.md](https://github.com/eea/volto-widget-toggle/blob/master/DEVELOP.md).
@@ -5,16 +5,17 @@ describe('Blocks Tests', () => {
5
5
  afterEach(tearDownAfterEach);
6
6
 
7
7
  it('Add Block: Empty', () => {
8
+ // without this the clear command below does nothing sometimes
9
+ cy.wait(500);
10
+
8
11
  // Change page title
9
- cy.get('.documentFirstHeading > .public-DraftStyleDefault-block')
10
- .clear()
11
- .type('My Add-on Page')
12
- .get('.documentFirstHeading span[data-text]')
13
- .contains('My Add-on Page');
14
-
15
- cy.get('.documentFirstHeading > .public-DraftStyleDefault-block').type(
16
- '{enter}',
17
- );
12
+ cy.get('[contenteditable=true]').first().clear();
13
+
14
+ cy.get('[contenteditable=true]').first().type('My Add-on Page');
15
+
16
+ cy.get('.documentFirstHeading').contains('My Add-on Page');
17
+
18
+ cy.get('[contenteditable=true]').first().type('{enter}');
18
19
 
19
20
  // Add block
20
21
  cy.get('.ui.basic.icon.button.block-add-button').first().click();
@@ -44,7 +44,7 @@ export const setupBeforeEach = () => {
44
44
  cy.waitForResourceToLoad('@types');
45
45
  cy.waitForResourceToLoad('my-page');
46
46
  cy.navigate('/cypress/my-page/edit');
47
- cy.get(`.block.title [data-contents]`);
47
+ cy.get(`.block.title h1`);
48
48
  };
49
49
 
50
50
  export const tearDownAfterEach = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-widget-toggle",
3
- "version": "2.2.2",
3
+ "version": "2.2.6",
4
4
  "description": "volto-widget-toggle: Volto add-on to replace checkboxes with toggle buttons",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -25,6 +25,8 @@
25
25
  },
26
26
  "scripts": {
27
27
  "release": "release-it",
28
+ "release-major-beta": "release-it major --preRelease=beta",
29
+ "release-beta": "release-it --preRelease=beta",
28
30
  "bootstrap": "npm install -g ejs; npm link ejs; node bootstrap",
29
31
  "stylelint": "../../../node_modules/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}'",
30
32
  "stylelint:overrides": "../../../node_modules/.bin/stylelint --syntax less --allow-empty-input 'theme/**/*.overrides' 'src/**/*.overrides'",
@@ -16,19 +16,30 @@ import { FormFieldWrapper } from '@plone/volto/components';
16
16
  * @returns {string} Markup of the component.
17
17
  */
18
18
  const CheckboxWidget = (props) => {
19
- const { id, title, value, onChange, isDisabled } = props;
20
- const [checked, setChecked] = React.useState(value || false);
19
+ const {
20
+ id,
21
+ title,
22
+ value,
23
+ onChange,
24
+ isDisabled,
25
+ defaultValue = false,
26
+ } = props;
27
+
28
+ React.useEffect(() => {
29
+ if (value === null && defaultValue) onChange(id, defaultValue); //value===null prevents assigning default value on every render
30
+ // eslint-disable-next-line react-hooks/exhaustive-deps
31
+ }, []);
32
+
21
33
  return (
22
34
  <FormFieldWrapper {...props} columns={1}>
23
35
  <div className="wrapper">
24
36
  <Checkbox
25
37
  toggle
26
38
  name={`field-${id}`}
27
- checked={checked}
39
+ checked={value ?? defaultValue}
28
40
  disabled={isDisabled}
29
41
  onChange={(event, { checked }) => {
30
42
  onChange(id, checked);
31
- setChecked(checked);
32
43
  }}
33
44
  label={<label htmlFor={`field-${id}`}>{title}</label>}
34
45
  />