@eeacms/volto-slate-footnote 6.1.3 → 6.1.5

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.
@@ -0,0 +1,2 @@
1
+ [ -n "$CI" ] && exit 0
2
+ yarn lint-staged
package/CHANGELOG.md CHANGED
@@ -4,6 +4,28 @@ 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
+ ### [6.1.5](https://github.com/eea/volto-slate-footnote/compare/6.1.4...6.1.5) - 19 September 2023
8
+
9
+ #### :bug: Bug Fixes
10
+
11
+ - fix: index not showing on diff - refs #257191 [dobri1408 - [`bd6eb19`](https://github.com/eea/volto-slate-footnote/commit/bd6eb197213e23420fdd2f185447cb92a8156fc9)]
12
+
13
+ #### :house: Internal changes
14
+
15
+ - style: lint-staged reorder in package.json [Alin Voinea - [`c618c3c`](https://github.com/eea/volto-slate-footnote/commit/c618c3c12a878cc87fb9c3fd658eeb5d1241e871)]
16
+
17
+ #### :hammer_and_wrench: Others
18
+
19
+ - test: EN locales, pre-commit fix, feature PRs checks Refs #257193 [valentinab25 - [`6886cf7`](https://github.com/eea/volto-slate-footnote/commit/6886cf796c58d38fcce7c515bda1d3586420a58a)]
20
+ ### [6.1.4](https://github.com/eea/volto-slate-footnote/compare/6.1.3...6.1.4) - 1 September 2023
21
+
22
+ #### :bug: Bug Fixes
23
+
24
+ - fix: force footnotes to open in the same tab - refs #257251 [dobri1408 - [`20bb988`](https://github.com/eea/volto-slate-footnote/commit/20bb988534413a837786ab10cc09244498dbcb7e)]
25
+
26
+ #### :hammer_and_wrench: Others
27
+
28
+ - increase code coverage [Dobricean Ioan Dorian - [`3ba3ef3`](https://github.com/eea/volto-slate-footnote/commit/3ba3ef3187b1119d7be96ac2f952a36368163b97)]
7
29
  ### [6.1.3](https://github.com/eea/volto-slate-footnote/compare/6.1.2...6.1.3) - 30 August 2023
8
30
 
9
31
  #### :bug: Bug Fixes
package/Jenkinsfile CHANGED
@@ -62,11 +62,17 @@ pipeline {
62
62
 
63
63
  stage('Tests') {
64
64
  when {
65
- allOf {
66
- environment name: 'CHANGE_ID', value: ''
67
- anyOf {
68
- not { changelog '.*^Automated release [0-9\\.]+$' }
69
- branch 'master'
65
+ anyOf {
66
+ allOf {
67
+ not { environment name: 'CHANGE_ID', value: '' }
68
+ environment name: 'CHANGE_TARGET', value: 'develop'
69
+ }
70
+ allOf {
71
+ environment name: 'CHANGE_ID', value: ''
72
+ anyOf {
73
+ not { changelog '.*^Automated release [0-9\\.]+$' }
74
+ branch 'master'
75
+ }
70
76
  }
71
77
  }
72
78
  }
@@ -110,11 +116,17 @@ pipeline {
110
116
 
111
117
  stage('Integration tests') {
112
118
  when {
113
- allOf {
114
- environment name: 'CHANGE_ID', value: ''
115
- anyOf {
116
- not { changelog '.*^Automated release [0-9\\.]+$' }
117
- branch 'master'
119
+ anyOf {
120
+ allOf {
121
+ not { environment name: 'CHANGE_ID', value: '' }
122
+ environment name: 'CHANGE_TARGET', value: 'develop'
123
+ }
124
+ allOf {
125
+ environment name: 'CHANGE_ID', value: ''
126
+ anyOf {
127
+ not { changelog '.*^Automated release [0-9\\.]+$' }
128
+ branch 'master'
129
+ }
118
130
  }
119
131
  }
120
132
  }
@@ -167,13 +179,19 @@ pipeline {
167
179
 
168
180
  stage('Report to SonarQube') {
169
181
  when {
170
- allOf {
171
- environment name: 'CHANGE_ID', value: ''
172
- anyOf {
173
- branch 'master'
174
- allOf {
175
- branch 'develop'
176
- not { changelog '.*^Automated release [0-9\\.]+$' }
182
+ anyOf {
183
+ allOf {
184
+ not { environment name: 'CHANGE_ID', value: '' }
185
+ environment name: 'CHANGE_TARGET', value: 'develop'
186
+ }
187
+ allOf {
188
+ environment name: 'CHANGE_ID', value: ''
189
+ anyOf {
190
+ allOf {
191
+ branch 'develop'
192
+ not { changelog '.*^Automated release [0-9\\.]+$' }
193
+ }
194
+ branch 'master'
177
195
  }
178
196
  }
179
197
  }
@@ -199,10 +217,16 @@ pipeline {
199
217
 
200
218
  stage('SonarQube compare to master') {
201
219
  when {
202
- allOf {
203
- environment name: 'CHANGE_ID', value: ''
204
- branch 'develop'
205
- not { changelog '.*^Automated release [0-9\\.]+$' }
220
+ anyOf {
221
+ allOf {
222
+ not { environment name: 'CHANGE_ID', value: '' }
223
+ environment name: 'CHANGE_TARGET', value: 'develop'
224
+ }
225
+ allOf {
226
+ environment name: 'CHANGE_ID', value: ''
227
+ branch 'develop'
228
+ not { changelog '.*^Automated release [0-9\\.]+$' }
229
+ }
206
230
  }
207
231
  }
208
232
  steps {
@@ -44,6 +44,28 @@ describe('Slate citations', () => {
44
44
  cy.get('[aria-label="Back to content"]').first().click();
45
45
  });
46
46
 
47
+ it('Test cancel Button', () => {
48
+ cy.getSlateEditorAndType('Colorless green ideas sleep furiously.')
49
+ .type('{selectAll}')
50
+ .dblclick();
51
+
52
+ // Footnote
53
+ cy.setSlateCursor('Colorless').dblclick();
54
+ cy.setSlateSelection('Colorless', 'green');
55
+ cy.clickSlateButton('Footnote');
56
+
57
+ cy.get('.sidebar-container .field-wrapper-footnote .react-select-container')
58
+ .click()
59
+ .type('Citation{enter}');
60
+
61
+ //click on the cancel button
62
+ cy.get('.sidebar-container .form .header button').first().next().click();
63
+
64
+ // Save
65
+ cy.get('#toolbar-save').click();
66
+ cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');
67
+ });
68
+
47
69
  it('Add Footnotes block and create multiple citations', () => {
48
70
  // Complete chained commands
49
71
  cy.getSlateEditorAndType('Colorless green ideas sleep furiously.')
package/cypress.config.js CHANGED
@@ -2,12 +2,12 @@ const { defineConfig } = require('cypress');
2
2
 
3
3
  module.exports = defineConfig({
4
4
  viewportWidth: 1280,
5
- defaultCommandTimeout: 8888,
5
+ defaultCommandTimeout: 5000,
6
6
  chromeWebSecurity: false,
7
7
  reporter: 'junit',
8
8
  video: true,
9
9
  retries: {
10
- runMode: 8,
10
+ runMode: 1,
11
11
  openMode: 0,
12
12
  },
13
13
  reporterOptions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-slate-footnote",
3
- "version": "6.1.3",
3
+ "version": "6.1.5",
4
4
  "description": "volto-slate-footnote: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -23,8 +23,31 @@
23
23
  "@cypress/code-coverage": "^3.10.0",
24
24
  "@plone/scripts": "*",
25
25
  "babel-plugin-transform-class-properties": "^6.24.1",
26
+ "husky": "*",
27
+ "lint-staged": "*",
26
28
  "md5": "^2.3.0"
27
29
  },
30
+ "lint-staged": {
31
+ "src/**/*.{js,jsx,ts,tsx,json}": [
32
+ "make lint-fix",
33
+ "make prettier-fix"
34
+ ],
35
+ "src/**/*.{jsx}": [
36
+ "make i18n"
37
+ ],
38
+ "theme/**/*.{css,less}": [
39
+ "make stylelint-fix"
40
+ ],
41
+ "src/**/*.{css,less}": [
42
+ "make stylelint-fix"
43
+ ],
44
+ "theme/**/*.overrides": [
45
+ "make stylelint-fix"
46
+ ],
47
+ "src/**/*.overrides": [
48
+ "make stylelint-fix"
49
+ ]
50
+ },
28
51
  "scripts": {
29
52
  "release": "release-it",
30
53
  "release-major-beta": "release-it major --preRelease=beta",
@@ -42,6 +65,7 @@
42
65
  "lint:fix": "make lint-fix",
43
66
  "i18n": "make i18n",
44
67
  "cypress:run": "make cypress-run",
45
- "cypress:open": "make cypress-open"
68
+ "cypress:open": "make cypress-open",
69
+ "prepare": "husky install"
46
70
  }
47
71
  }
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React from 'react';
2
2
  import {
3
3
  openAccordionIfContainsFootnoteReference,
4
4
  getAllBlocksAndSlateFields,
@@ -7,6 +7,8 @@ import {
7
7
  } from '@eeacms/volto-slate-footnote/editor/utils';
8
8
  import './less/public.less';
9
9
 
10
+ import { UniversalLink } from '@plone/volto/components';
11
+
10
12
  const alphabet = 'abcdefghijklmnopqrstuvwxyz';
11
13
 
12
14
  /**
@@ -20,18 +22,10 @@ const alphabet = 'abcdefghijklmnopqrstuvwxyz';
20
22
  const FootnotesBlockView = (props) => {
21
23
  const { data, properties } = props;
22
24
  const { title, global, placeholder = 'Footnotes' } = data;
23
- const [notesObj, setNodesObjs] = useState(null);
24
25
  const metadata = props.metadata ? props.metadata : properties;
25
-
26
- useEffect(() => {
27
- if (properties) {
28
- const globalMetadata = global ? metadata : properties;
29
- const blocks = getAllBlocksAndSlateFields(globalMetadata);
30
- const notesObjResult = makeFootnoteListOfUniqueItems(blocks);
31
-
32
- setNodesObjs(notesObjResult);
33
- }
34
- }, [properties]); // eslint-disable-line
26
+ const globalMetadata = global ? metadata : properties;
27
+ const blocks = getAllBlocksAndSlateFields(globalMetadata);
28
+ const notesObj = makeFootnoteListOfUniqueItems(blocks);
35
29
 
36
30
  return (
37
31
  <div className="footnotes-listing-block">
@@ -62,7 +56,7 @@ const FootnotesBlockView = (props) => {
62
56
  id={`cite_ref-${refsList[0]}`}
63
57
  key={`indice-${refsList[0]}`}
64
58
  >
65
- <a
59
+ <UniversalLink
66
60
  href={`#ref-${parentUid || uid}`}
67
61
  aria-label="Back to content"
68
62
  onClick={() =>
@@ -72,12 +66,12 @@ const FootnotesBlockView = (props) => {
72
66
  }
73
67
  >
74
68
  {alphabet[0]}
75
- </a>{' '}
69
+ </UniversalLink>{' '}
76
70
  </sup>
77
71
  {/** following refs will have the uid of the one that references it*/}
78
72
  {refsList.slice(1).map((ref, index) => (
79
73
  <sup id={`cite_ref-${ref}`} key={`indice-${ref}`}>
80
- <a
74
+ <UniversalLink
81
75
  href={`#ref-${ref}`}
82
76
  aria-label="Back to content"
83
77
  onClick={() =>
@@ -87,14 +81,14 @@ const FootnotesBlockView = (props) => {
87
81
  }
88
82
  >
89
83
  {alphabet[index + 1]}
90
- </a>{' '}
84
+ </UniversalLink>{' '}
91
85
  </sup>
92
86
  ))}
93
87
  </>
94
88
  ) : (
95
89
  <sup id={`cite_ref-${uid}`}>
96
90
  {/** some footnotes are never parent so we need the parent to reference */}
97
- <a
91
+ <UniversalLink
98
92
  href={`#ref-${parentUid || uid}`}
99
93
  aria-label="Back to content"
100
94
  onClick={() =>
@@ -104,7 +98,7 @@ const FootnotesBlockView = (props) => {
104
98
  }
105
99
  >
106
100
 
107
- </a>{' '}
101
+ </UniversalLink>{' '}
108
102
  </sup>
109
103
  )}
110
104
  </li>
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import SearchWidget from './SearchWidget';
4
+ describe('Test SearchWidget', () => {
5
+ it('check html content', () => {
6
+ const component = renderer.create(<SearchWidget />);
7
+ const json = component.toJSON();
8
+ expect(json).toMatchSnapshot();
9
+ });
10
+ });
@@ -0,0 +1,72 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Test SearchWidget check html content 1`] = `
4
+ <div
5
+ id="blockform-fieldset-default"
6
+ >
7
+ <div
8
+ className="ui segment attached"
9
+ fluid={true}
10
+ >
11
+ <div
12
+ className="ui fluid card"
13
+ onClick={[Function]}
14
+ >
15
+ <div
16
+ className="content"
17
+ fluid={true}
18
+ >
19
+ <div
20
+ className="header"
21
+ >
22
+ Citation
23
+ </div>
24
+ <div
25
+ className="description"
26
+ fluid={true}
27
+ >
28
+ <div
29
+ className="ui fluid search"
30
+ onBlur={[Function]}
31
+ onFocus={[Function]}
32
+ onMouseDown={[Function]}
33
+ >
34
+ <div
35
+ className="ui fluid right icon input"
36
+ >
37
+ <input
38
+ autoComplete="off"
39
+ className="prompt"
40
+ id="field-footnote"
41
+ onChange={[Function]}
42
+ onClick={[Function]}
43
+ tabIndex="0"
44
+ type="text"
45
+ value=""
46
+ />
47
+ <i
48
+ aria-hidden="true"
49
+ className="search icon"
50
+ onClick={[Function]}
51
+ />
52
+ </div>
53
+ <div
54
+ className="results transition"
55
+ >
56
+ <div
57
+ className="message empty"
58
+ >
59
+ <div
60
+ className="header"
61
+ >
62
+ No results found.
63
+ </div>
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ </div>
69
+ </div>
70
+ </div>
71
+ </div>
72
+ `;
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React from 'react';
2
2
  import { Popup, List } from 'semantic-ui-react';
3
3
  import { useEditorContext } from '@plone/volto-slate/hooks';
4
4
  import { getAllBlocksAndSlateFields } from '@eeacms/volto-slate-footnote/editor/utils';
@@ -8,6 +8,7 @@ import {
8
8
  } from './utils';
9
9
  import { isEmpty } from 'lodash';
10
10
  import { useSelector } from 'react-redux';
11
+ import { UniversalLink } from '@plone/volto/components';
11
12
 
12
13
  /**
13
14
  * Removes '<?xml version="1.0"?>' from footnote
@@ -23,71 +24,61 @@ export const FootnoteElement = (props) => {
23
24
  const { data = {} } = element;
24
25
  const { uid, zoteroId } = data;
25
26
  const editor = useEditorContext();
26
- const [citationIndice, setCitationIndice] = useState(null); // list of indices to reference
27
- const [citationRefId, setCitationRefId] = useState(null); // indice of element to be referenced
28
- const initialFormData = useSelector((state) => state?.content?.data || {});
29
-
30
- useEffect(() => {
31
- const blockProps = editor?.getBlockProps ? editor.getBlockProps() : null;
32
- const metadata = blockProps
33
- ? blockProps.metadata || blockProps.properties
34
- : extras?.metadata || {};
35
- const blocks = getAllBlocksAndSlateFields(metadata);
36
- const storeBlocks = getAllBlocksAndSlateFields(initialFormData);
37
27
 
38
- const notesObjResult = isEmpty(metadata)
39
- ? makeFootnoteListOfUniqueItems(storeBlocks)
40
- : makeFootnoteListOfUniqueItems(blocks);
28
+ const initialFormData = useSelector((state) => state?.content?.data || {});
29
+ const blockProps = editor?.getBlockProps ? editor.getBlockProps() : null;
30
+ const metadata = blockProps
31
+ ? blockProps.metadata || blockProps.properties
32
+ : extras?.metadata || {};
33
+ const blocks = getAllBlocksAndSlateFields(metadata);
34
+ const storeBlocks = getAllBlocksAndSlateFields(initialFormData);
41
35
 
42
- // will cosider zotero citations and footnote
43
- // notesObjResult contains all zotero/footnote as unique, and contain refs for other zotero/footnote
44
- const indiceIfZoteroId = data.extra
45
- ? [
46
- `[${Object.keys(notesObjResult).indexOf(zoteroId) + 1}]`, // parent footnote
47
- ...data.extra.map(
48
- // citations from extra
49
- (zoteroObj, _index) =>
50
- // all zotero citation are indexed by zoteroId in notesObjResult
51
- `[${
52
- Object.keys(notesObjResult).indexOf(zoteroObj.zoteroId) + 1
53
- }]`,
54
- ),
55
- ].join('')
56
- : // no extra citations (no multiples)
57
- `[${Object.keys(notesObjResult).indexOf(zoteroId) + 1}]`;
36
+ const notesObjResult = isEmpty(metadata)
37
+ ? makeFootnoteListOfUniqueItems(storeBlocks)
38
+ : makeFootnoteListOfUniqueItems(blocks);
58
39
 
59
- const indice = zoteroId // ZOTERO
60
- ? indiceIfZoteroId
61
- : // FOOTNOTES
62
- // parent footnote
63
- [data, ...(data.extra || [])]
64
- .map((footnoteObj, _index) => {
65
- return `[${
66
- Object.keys(notesObjResult).indexOf(
67
- Object.keys(notesObjResult).find(
68
- (key) =>
69
- notesObjResult[key].footnote === footnoteObj.footnote,
70
- ),
71
- ) + 1
72
- }]`;
73
- })
74
- .join('');
40
+ // will cosider zotero citations and footnote
41
+ // notesObjResult contains all zotero/footnote as unique, and contain refs for other zotero/footnote
42
+ const indiceIfZoteroId = data.extra
43
+ ? [
44
+ `[${Object.keys(notesObjResult).indexOf(zoteroId) + 1}]`, // parent footnote
45
+ ...data.extra.map(
46
+ // citations from extra
47
+ (zoteroObj, _index) =>
48
+ // all zotero citation are indexed by zoteroId in notesObjResult
49
+ `[${Object.keys(notesObjResult).indexOf(zoteroObj.zoteroId) + 1}]`,
50
+ ),
51
+ ].join('')
52
+ : // no extra citations (no multiples)
53
+ `[${Object.keys(notesObjResult).indexOf(zoteroId) + 1}]`;
75
54
 
76
- const findReferenceId =
77
- // search within parent citations first, otherwise the uid might be inside a refs obj that comes before
78
- Object.keys(notesObjResult).find(
79
- (noteKey) => notesObjResult[noteKey].uid === uid,
80
- ) ||
81
- // if not found in parent, search in refs, it might be a footnote references multiple times
82
- Object.keys(notesObjResult).find(
83
- (noteKey) =>
84
- notesObjResult[noteKey].uid === uid ||
85
- (notesObjResult[noteKey].refs && notesObjResult[noteKey].refs[uid]),
86
- );
55
+ const citationIndice = zoteroId // ZOTERO
56
+ ? indiceIfZoteroId
57
+ : // FOOTNOTES
58
+ // parent footnote
59
+ [data, ...(data.extra || [])]
60
+ .map((footnoteObj, _index) => {
61
+ return `[${
62
+ Object.keys(notesObjResult).indexOf(
63
+ Object.keys(notesObjResult).find(
64
+ (key) => notesObjResult[key].footnote === footnoteObj.footnote,
65
+ ),
66
+ ) + 1
67
+ }]`;
68
+ })
69
+ .join('');
87
70
 
88
- setCitationIndice(indice);
89
- setCitationRefId(findReferenceId);
90
- }, [editor, element, children]); // eslint-disable-line
71
+ const citationRefId =
72
+ // search within parent citations first, otherwise the uid might be inside a refs obj that comes before
73
+ Object.keys(notesObjResult).find(
74
+ (noteKey) => notesObjResult[noteKey].uid === uid,
75
+ ) ||
76
+ // if not found in parent, search in refs, it might be a footnote references multiple times
77
+ Object.keys(notesObjResult).find(
78
+ (noteKey) =>
79
+ notesObjResult[noteKey].uid === uid ||
80
+ (notesObjResult[noteKey].refs && notesObjResult[noteKey].refs[uid]),
81
+ );
91
82
 
92
83
  return (
93
84
  <>
@@ -110,7 +101,7 @@ export const FootnoteElement = (props) => {
110
101
  <Popup.Content>
111
102
  <List divided relaxed selection>
112
103
  <List.Item
113
- as="a"
104
+ as={UniversalLink}
114
105
  href={`#footnote-${citationRefId}`}
115
106
  onClick={() =>
116
107
  openAccordionIfContainsFootnoteReference(
@@ -132,7 +123,7 @@ export const FootnoteElement = (props) => {
132
123
  {data.extra &&
133
124
  data.extra.map((item) => (
134
125
  <List.Item
135
- as="a"
126
+ as={UniversalLink}
136
127
  href={`#footnote-${item.zoteroId || item.uid}`}
137
128
  onClick={() =>
138
129
  openAccordionIfContainsFootnoteReference(
@@ -174,7 +165,7 @@ export const FootnoteElement = (props) => {
174
165
  <Popup.Content>
175
166
  <List divided relaxed selection>
176
167
  <List.Item
177
- as="a"
168
+ as={UniversalLink}
178
169
  href={`#footnote-${citationRefId}`}
179
170
  onClick={() =>
180
171
  openAccordionIfContainsFootnoteReference(
@@ -196,7 +187,7 @@ export const FootnoteElement = (props) => {
196
187
  {data.extra &&
197
188
  data.extra.map((item) => (
198
189
  <List.Item
199
- as="a"
190
+ as={UniversalLink}
200
191
  href={`#footnote-${item.zoteroId || item.uid}`}
201
192
  onClick={() =>
202
193
  openAccordionIfContainsFootnoteReference(