@eeacms/volto-slate-footnote 4.0.3 → 5.0.0

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,9 +4,26 @@ 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
+ #### [5.0.0](https://github.com/eea/volto-slate-footnote/compare/4.0.5...5.0.0)
8
+
9
+ - feat(footnotes): Add blocksWithFootnotesSupport config settings [`ed3de55`](https://github.com/eea/volto-slate-footnote/commit/ed3de5546b409c7c9f149a28407110959d198f68)
10
+
11
+ #### [4.0.5](https://github.com/eea/volto-slate-footnote/compare/4.0.4...4.0.5)
12
+
13
+ > 17 May 2022
14
+
15
+ - Allow other block types to define footnotes - refs #148688 [`#31`](https://github.com/eea/volto-slate-footnote/pull/31)
16
+
17
+ #### [4.0.4](https://github.com/eea/volto-slate-footnote/compare/4.0.3...4.0.4)
18
+
19
+ > 3 January 2022
20
+
21
+
7
22
  #### [4.0.3](https://github.com/eea/volto-slate-footnote/compare/4.0.2...4.0.3)
8
23
 
9
- - Add SonarQube badges [`5d05ecf`](https://github.com/eea/volto-slate-footnote/commit/5d05ecfd933ec64693998d88f6b6c69e3866cb0b)
24
+ > 18 December 2021
25
+
26
+ - Add SonarQube badges [`#29`](https://github.com/eea/volto-slate-footnote/pull/29)
10
27
  - Refs #142010 - Optimize Volto-addons gitflow pipelines [`1081079`](https://github.com/eea/volto-slate-footnote/commit/1081079444f5ac806e9d56765c4ccf0b9e415a73)
11
28
 
12
29
  #### [4.0.2](https://github.com/eea/volto-slate-footnote/compare/4.0.1...4.0.2)
package/Jenkinsfile CHANGED
@@ -4,7 +4,7 @@ pipeline {
4
4
  environment {
5
5
  GIT_NAME = "volto-slate-footnote"
6
6
  NAMESPACE = "@eeacms"
7
- SONARQUBE_TAGS = "volto.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,forest.eea.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater"
7
+ SONARQUBE_TAGS = "volto.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,forest.eea.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu"
8
8
  DEPENDENCIES = "volto-slate:asDefault"
9
9
  }
10
10
 
@@ -124,7 +124,7 @@ pipeline {
124
124
  node(label: 'docker') {
125
125
  script {
126
126
  try {
127
- 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'''
128
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'''
129
129
  } finally {
130
130
  try {
@@ -142,7 +142,8 @@ pipeline {
142
142
  reportName: 'CypressCoverage',
143
143
  reportTitles: 'Integration Tests Code Coverage'])
144
144
  }
145
- 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
146
147
  stash name: "cypress-coverage", includes: "cypress-coverage/**", allowEmpty: true
147
148
  }
148
149
  finally {
@@ -183,10 +184,10 @@ pipeline {
183
184
  unstash "xunit-reports"
184
185
  unstash "cypress-coverage"
185
186
  def scannerHome = tool 'SonarQubeScanner';
186
- def nodeJS = tool 'NodeJS11';
187
+ def nodeJS = tool 'NodeJS';
187
188
  withSonarQubeEnv('Sonarqube') {
188
189
  sh '''sed -i "s#/opt/frontend/my-volto-project/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info'''
189
- sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
190
+ sh "export PATH=${scannerHome}/bin:${nodeJS}/bin:$PATH; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
190
191
  sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
191
192
  }
192
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-slate-footnote",
3
- "version": "4.0.3",
3
+ "version": "5.0.0",
4
4
  "description": "volto-slate-footnote: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
package/src/constants.js CHANGED
@@ -1 +1,2 @@
1
1
  export const FOOTNOTE = 'footnote';
2
+ export const SLATE = 'slate';
@@ -11,6 +11,7 @@ import { Node } from 'slate';
11
11
  import { useSelector } from 'react-redux';
12
12
  import { isEmpty } from 'lodash';
13
13
  import { getAllBlocksAndSlateFields } from '@eeacms/volto-slate-footnote/editor/utils';
14
+ import config from '@plone/volto/registry';
14
15
 
15
16
  const FootnoteEditor = (props) => {
16
17
  const {
@@ -66,18 +67,27 @@ const FootnoteEditor = (props) => {
66
67
  // add label and value for the multi search widget
67
68
  // flatten blocks to add all extra in the list
68
69
  flatAllBlocks
69
- .filter((b) => b['@type'] === 'slate')
70
- .forEach(({ value }) => {
71
- if (!value) return;
70
+ .filter((b) => b['@type'] in config.settings.blocksWithFootnotesSupport)
71
+ .forEach((element) => {
72
+ const mapping = config.settings.blocksWithFootnotesSupport[
73
+ element['@type']
74
+ ] || ['value'];
72
75
 
73
- Array.from(Node.elements(value[0])).forEach(([block]) => {
74
- block.children.forEach((node) => {
75
- if (node.data && node.type === 'footnote') {
76
- manageAddBlockToUniqueBlocks(uniqueFootnoteBlocks, node.data);
77
- (node.data.extra || []).forEach((ftitem) => {
78
- manageAddBlockToUniqueBlocks(uniqueFootnoteBlocks, ftitem);
76
+ mapping.forEach((key) => {
77
+ const value = element[key];
78
+ if (!value) return;
79
+
80
+ value.forEach((item) => {
81
+ Array.from(Node.elements(item)).forEach(([block]) => {
82
+ block.children.forEach((node) => {
83
+ if (node.data && node.type === 'footnote') {
84
+ manageAddBlockToUniqueBlocks(uniqueFootnoteBlocks, node.data);
85
+ (node.data.extra || []).forEach((ftitem) => {
86
+ manageAddBlockToUniqueBlocks(uniqueFootnoteBlocks, ftitem);
87
+ });
88
+ }
79
89
  });
80
- }
90
+ });
81
91
  });
82
92
  });
83
93
  });
@@ -118,38 +118,52 @@ export const makeFootnoteListOfUniqueItems = (blocks) => {
118
118
  let notesObjResult = {};
119
119
 
120
120
  blocks
121
- .filter((b) => b['@type'] === 'slate')
122
- .forEach(({ value }) => {
123
- if (!value) return;
124
- // Node.elements(value[0]) returns an iterable generator of nodes
125
- Array.from(Node.elements(value[0])).forEach(([node]) => {
126
- if (footnotes.includes(node.type) && node.data) {
127
- // for citations (Zotero items) create refs for same zoteroId
128
- if (node.data.zoteroId) {
129
- iterateZoteroObj(notesObjResult, node.data);
130
- // itereate the extra obj for multiple citations
131
- if (node.data.extra) {
132
- node.data.extra.forEach((zoteroObjItem) =>
133
- // send the uid of the parent
134
- // of the word the will have the reference indice
135
- iterateZoteroObj(notesObjResult, zoteroObjItem, node.data.uid),
136
- );
121
+ .filter((b) => b['@type'] in config.settings.blocksWithFootnotesSupport)
122
+ .forEach((element) => {
123
+ const mapping = config.settings.blocksWithFootnotesSupport[
124
+ element['@type']
125
+ ] || ['value'];
126
+
127
+ mapping.forEach((key) => {
128
+ const value = element[key];
129
+ if (!value) return;
130
+
131
+ value.forEach((item) => {
132
+ // Node.elements(item) returns an iterable generator of nodes
133
+ Array.from(Node.elements(item)).forEach(([node]) => {
134
+ if (footnotes.includes(node.type) && node.data) {
135
+ // for citations (Zotero items) create refs for same zoteroId
136
+ if (node.data.zoteroId) {
137
+ iterateZoteroObj(notesObjResult, node.data);
138
+ // itereate the extra obj for multiple citations
139
+ if (node.data.extra) {
140
+ node.data.extra.forEach((zoteroObjItem) =>
141
+ // send the uid of the parent
142
+ // of the word the will have the reference indice
143
+ iterateZoteroObj(
144
+ notesObjResult,
145
+ zoteroObjItem,
146
+ node.data.uid,
147
+ ),
148
+ );
149
+ }
150
+ // for footnotes - create refs, on identical text
151
+ } else {
152
+ iterateFootnoteObj(notesObjResult, node.data);
153
+ if (node.data.extra) {
154
+ node.data.extra.forEach((footnoteObjItem) =>
155
+ // since is called in case of extra, the parent is needed
156
+ iterateFootnoteObj(
157
+ notesObjResult,
158
+ footnoteObjItem,
159
+ node.data.uid,
160
+ ),
161
+ );
162
+ }
163
+ }
137
164
  }
138
- // for footnotes - create refs, on identical text
139
- } else {
140
- iterateFootnoteObj(notesObjResult, node.data);
141
- if (node.data.extra) {
142
- node.data.extra.forEach((footnoteObjItem) =>
143
- // since is called in case of extra, the parent is needed
144
- iterateFootnoteObj(
145
- notesObjResult,
146
- footnoteObjItem,
147
- node.data.uid,
148
- ),
149
- );
150
- }
151
- }
152
- }
165
+ });
166
+ });
153
167
  });
154
168
  });
155
169
 
package/src/index.js CHANGED
@@ -36,5 +36,15 @@ export default function install(config) {
36
36
  config.widgets.widget.searchInput = SearchWidget;
37
37
  config = installFootnoteEditor(config);
38
38
 
39
+ // Some blocks may have multiple slate fields,
40
+ // thus provide these fields per block type in order to lookup for footnotes:
41
+ //
42
+ // 'my-custom-block-type': ['value', 'field1', 'field2']
43
+ //
44
+ config.settings.blocksWithFootnotesSupport = {
45
+ ...(config.settings.blocksWithFootnotesSupport || {}),
46
+ slate: ['value'],
47
+ };
48
+
39
49
  return config;
40
50
  }