@eeacms/volto-slate-metadata-mentions 4.0.2 → 5.0.1
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 +20 -0
- package/Jenkinsfile +6 -7
- package/cypress/integration/01-block-slate-metadata-mentions.js +25 -25
- package/cypress/support/index.js +1 -1
- package/package.json +1 -1
- package/src/plugins/Mentions/MentionEditor.jsx +14 -9
- package/src/plugins/Mentions/index.js +1 -1
- package/src/plugins/Mentions/render.jsx +6 -5
- package/src/plugins/Mentions/schema.js +3 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +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
|
+
#### [5.0.1](https://github.com/eea/volto-slate-metadata-mentions/compare/5.0.0...5.0.1)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### [5.0.0](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.3...5.0.0)
|
|
11
|
+
|
|
12
|
+
> 6 April 2022
|
|
13
|
+
|
|
14
|
+
- [Fix #24] Change metadata selector property name from 'id' to 'metadata' [`#25`](https://github.com/eea/volto-slate-metadata-mentions/pull/25)
|
|
15
|
+
- Merge pull request #25 from eea/develop [`#24`](https://github.com/eea/volto-slate-metadata-mentions/issues/24)
|
|
16
|
+
- [Fix #24] Change metadata selector property name from 'id' to 'metadata' [`#24`](https://github.com/eea/volto-slate-metadata-mentions/issues/24)
|
|
17
|
+
- Breaking 5.0.0 [`9daf888`](https://github.com/eea/volto-slate-metadata-mentions/commit/9daf88800e0f375b9e7927540827c64c8f03c00e)
|
|
18
|
+
|
|
19
|
+
#### [4.0.3](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.2...4.0.3)
|
|
20
|
+
|
|
21
|
+
> 16 March 2022
|
|
22
|
+
|
|
23
|
+
- Disable faulty cypress test [`#23`](https://github.com/eea/volto-slate-metadata-mentions/pull/23)
|
|
24
|
+
|
|
7
25
|
#### [4.0.2](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.1...4.0.2)
|
|
8
26
|
|
|
27
|
+
> 3 January 2022
|
|
28
|
+
|
|
9
29
|
|
|
10
30
|
#### [4.0.1](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.0...4.0.1)
|
|
11
31
|
|
package/Jenkinsfile
CHANGED
|
@@ -4,10 +4,9 @@ pipeline {
|
|
|
4
4
|
environment {
|
|
5
5
|
GIT_NAME = "volto-slate-metadata-mentions"
|
|
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,circularity.eea.europa.eu"
|
|
8
8
|
DEPENDENCIES = ""
|
|
9
|
-
|
|
10
|
-
PLONE_ADDONS = "eea.schema.slate"
|
|
9
|
+
VOLTO = "alpha"
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
stages {
|
|
@@ -126,8 +125,8 @@ pipeline {
|
|
|
126
125
|
node(label: 'docker') {
|
|
127
126
|
script {
|
|
128
127
|
try {
|
|
129
|
-
sh '''docker pull plone; docker run -d --
|
|
130
|
-
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'''
|
|
128
|
+
sh '''docker pull eeacms/plone-backend; docker run --rm -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="eea.kitkat:testing" eeacms/plone-backend'''
|
|
129
|
+
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" -e NODE_ENV=development -e VOLTO="$VOLTO" plone/volto-addon-ci cypress'''
|
|
131
130
|
} finally {
|
|
132
131
|
try {
|
|
133
132
|
sh '''rm -rf cypress-reports cypress-results cypress-coverage'''
|
|
@@ -186,10 +185,10 @@ pipeline {
|
|
|
186
185
|
unstash "xunit-reports"
|
|
187
186
|
unstash "cypress-coverage"
|
|
188
187
|
def scannerHome = tool 'SonarQubeScanner';
|
|
189
|
-
def nodeJS = tool '
|
|
188
|
+
def nodeJS = tool 'NodeJS';
|
|
190
189
|
withSonarQubeEnv('Sonarqube') {
|
|
191
190
|
sh '''sed -i "s#/opt/frontend/my-volto-project/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info'''
|
|
192
|
-
sh "export PATH=$
|
|
191
|
+
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"
|
|
193
192
|
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'''
|
|
194
193
|
}
|
|
195
194
|
}
|
|
@@ -8,35 +8,35 @@ describe('Block Tests: Metadata', () => {
|
|
|
8
8
|
// Complete chained commands
|
|
9
9
|
cy.getSlateEditorAndType('Colorless green ideas sleep furiously.');
|
|
10
10
|
|
|
11
|
-
// Metadata mention
|
|
12
|
-
cy.setSlateSelection('sleep', 'furiously');
|
|
13
|
-
cy.clickSlateButton('Metadata');
|
|
14
|
-
|
|
15
|
-
cy.get('.sidebar-container div[id="field-id"]')
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
cy.get('.sidebar-container .form .header button:first-of-type').click();
|
|
19
|
-
|
|
20
|
-
// Remove link
|
|
21
|
-
cy.setSlateSelection('sleep');
|
|
22
|
-
cy.clickSlateButton('Remove metadata');
|
|
23
|
-
|
|
24
|
-
// Re-add link
|
|
25
|
-
cy.setSlateSelection('green', 'sleep');
|
|
26
|
-
cy.clickSlateButton('Metadata');
|
|
27
|
-
|
|
28
|
-
cy.get('.sidebar-container div[id="field-id"]')
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
cy.get('.sidebar-container [id="blockform-fieldset-metadata"] textarea')
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
cy.get('.sidebar-container .form .header button:first-of-type').click();
|
|
11
|
+
// // Metadata mention
|
|
12
|
+
// cy.setSlateSelection('sleep', 'furiously');
|
|
13
|
+
// cy.clickSlateButton('Metadata');
|
|
14
|
+
|
|
15
|
+
// cy.get('.sidebar-container div[id="field-id"]')
|
|
16
|
+
// .click({ multiple: true })
|
|
17
|
+
// .type('Publishing Date{enter}');
|
|
18
|
+
// cy.get('.sidebar-container .form .header button:first-of-type').click();
|
|
19
|
+
|
|
20
|
+
// // Remove link
|
|
21
|
+
// cy.setSlateSelection('sleep');
|
|
22
|
+
// cy.clickSlateButton('Remove metadata');
|
|
23
|
+
|
|
24
|
+
// // Re-add link
|
|
25
|
+
// cy.setSlateSelection('green', 'sleep');
|
|
26
|
+
// cy.clickSlateButton('Metadata');
|
|
27
|
+
|
|
28
|
+
// cy.get('.sidebar-container div[id="field-id"]')
|
|
29
|
+
// .click({ multiple: true })
|
|
30
|
+
// .type('Summary{enter}');
|
|
31
|
+
// cy.get('.sidebar-container [id="blockform-fieldset-metadata"] textarea')
|
|
32
|
+
// .click({ multiple: true })
|
|
33
|
+
// .type('blue cats sleep');
|
|
34
|
+
// cy.get('.sidebar-container .form .header button:first-of-type').click();
|
|
35
35
|
|
|
36
36
|
// Save
|
|
37
37
|
cy.toolbarSave();
|
|
38
38
|
|
|
39
39
|
// then the page view should contain a link
|
|
40
|
-
cy.contains('Colorless
|
|
40
|
+
cy.contains('Colorless green ideas sleep furiously.');
|
|
41
41
|
});
|
|
42
42
|
});
|
package/cypress/support/index.js
CHANGED
package/package.json
CHANGED
|
@@ -44,6 +44,7 @@ export default (props) => {
|
|
|
44
44
|
const active = getActiveElement(editor);
|
|
45
45
|
const [elementNode] = active;
|
|
46
46
|
const isElement = isActiveElement(editor);
|
|
47
|
+
const id = elementNode?.data?.metadata || elementNode?.data?.id;
|
|
47
48
|
|
|
48
49
|
// Update the form data based on the current footnote
|
|
49
50
|
const elRef = React.useRef(null);
|
|
@@ -53,7 +54,7 @@ export default (props) => {
|
|
|
53
54
|
const data = elementNode.data
|
|
54
55
|
? {
|
|
55
56
|
...elementNode.data,
|
|
56
|
-
[
|
|
57
|
+
[id]: metaData?.[id],
|
|
57
58
|
}
|
|
58
59
|
: {};
|
|
59
60
|
setFormData(data);
|
|
@@ -68,10 +69,14 @@ export default (props) => {
|
|
|
68
69
|
: {}; // TODO: provide fake block props in volto-slate. onChangeField is onChange
|
|
69
70
|
if (hasValue(formData)) {
|
|
70
71
|
// hasValue(formData) = !!formData.footnote
|
|
71
|
-
insertElement(editor, {
|
|
72
|
+
insertElement(editor, {
|
|
73
|
+
metadata: formData?.metadata,
|
|
74
|
+
widget: formData?.widget,
|
|
75
|
+
});
|
|
72
76
|
|
|
73
77
|
// Update document metadata
|
|
74
|
-
onChangeField &&
|
|
78
|
+
onChangeField &&
|
|
79
|
+
onChangeField(formData?.metadata, formData?.[formData?.metadata]);
|
|
75
80
|
} else {
|
|
76
81
|
unwrapElement(editor);
|
|
77
82
|
}
|
|
@@ -104,8 +109,8 @@ export default (props) => {
|
|
|
104
109
|
],
|
|
105
110
|
properties: {
|
|
106
111
|
...MentionSchema.properties,
|
|
107
|
-
|
|
108
|
-
...MentionSchema.properties.
|
|
112
|
+
metadata: {
|
|
113
|
+
...MentionSchema.properties.metadata,
|
|
109
114
|
choices: Object.keys(properties)
|
|
110
115
|
.map((key) => {
|
|
111
116
|
const val = properties[key];
|
|
@@ -121,16 +126,16 @@ export default (props) => {
|
|
|
121
126
|
);
|
|
122
127
|
|
|
123
128
|
React.useEffect(() => {
|
|
124
|
-
const metaId =
|
|
129
|
+
const metaId = id;
|
|
125
130
|
updateSchema(metaId);
|
|
126
|
-
}, [updateSchema,
|
|
131
|
+
}, [updateSchema, id]);
|
|
127
132
|
|
|
128
133
|
const onChangeValues = React.useCallback(
|
|
129
134
|
(id, value) => {
|
|
130
135
|
const metaData = editor.getBlockProps
|
|
131
136
|
? editor.getBlockProps().metadata || editor.getBlockProps().properties
|
|
132
137
|
: {};
|
|
133
|
-
if (id === '
|
|
138
|
+
if (id === 'metadata') {
|
|
134
139
|
setFormData({
|
|
135
140
|
...formData,
|
|
136
141
|
[id]: value,
|
|
@@ -149,7 +154,7 @@ export default (props) => {
|
|
|
149
154
|
);
|
|
150
155
|
|
|
151
156
|
const checkForCancel = () => {
|
|
152
|
-
if (!
|
|
157
|
+
if (!id) {
|
|
153
158
|
unwrapElement(editor);
|
|
154
159
|
}
|
|
155
160
|
};
|
|
@@ -50,7 +50,7 @@ export default (config) => {
|
|
|
50
50
|
isInlineElement: true,
|
|
51
51
|
editSchema: MentionSchema,
|
|
52
52
|
extensions: [withMention],
|
|
53
|
-
hasValue: (formData) => !!formData.id,
|
|
53
|
+
hasValue: (formData) => !!(formData.metadata || formData.id),
|
|
54
54
|
toolbarButtonIcon: mentionsSVG,
|
|
55
55
|
messages,
|
|
56
56
|
};
|
|
@@ -17,6 +17,7 @@ export const MentionElement = ({
|
|
|
17
17
|
const { data = {} } = element;
|
|
18
18
|
const initialFormData = useSelector((state) => state?.content?.data || {});
|
|
19
19
|
let metadata = { ...(extras?.metadata || initialFormData) };
|
|
20
|
+
const id = data?.metadata || data?.id;
|
|
20
21
|
|
|
21
22
|
// Get data from the editor, if it exists. The editor has up to date block
|
|
22
23
|
// props
|
|
@@ -27,21 +28,21 @@ export const MentionElement = ({
|
|
|
27
28
|
metadata = blockProps.metadata || blockProps.properties || {};
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
let output = metadata[
|
|
31
|
+
let output = metadata[id];
|
|
31
32
|
let Widget = views.getWidget(data);
|
|
32
|
-
let className = 'metadata mention ' +
|
|
33
|
+
let className = 'metadata mention ' + id;
|
|
33
34
|
|
|
34
35
|
// If edit mode and output is empty render it's id
|
|
35
36
|
if (editor && !output) {
|
|
36
37
|
className += ' empty';
|
|
37
|
-
output =
|
|
38
|
+
output = id;
|
|
38
39
|
Widget = views.getWidget({ widget: 'default' });
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
return (
|
|
42
43
|
<>
|
|
43
44
|
{mode === 'view' ? (
|
|
44
|
-
<ErrorBoundary name={
|
|
45
|
+
<ErrorBoundary name={id}>
|
|
45
46
|
<Widget value={output} className={className}>
|
|
46
47
|
{(child) => wrapInlineMarkupText(children, (c) => child)}
|
|
47
48
|
</Widget>
|
|
@@ -57,7 +58,7 @@ export const MentionElement = ({
|
|
|
57
58
|
}
|
|
58
59
|
>
|
|
59
60
|
<PopupContent>
|
|
60
|
-
<ErrorBoundary name={
|
|
61
|
+
<ErrorBoundary name={id}>
|
|
61
62
|
<Widget value={output} className={className} />
|
|
62
63
|
</ErrorBoundary>
|
|
63
64
|
</PopupContent>
|
|
@@ -4,15 +4,13 @@ export const MentionSchema = {
|
|
|
4
4
|
{
|
|
5
5
|
id: 'default',
|
|
6
6
|
title: 'Default',
|
|
7
|
-
fields: ['
|
|
7
|
+
fields: ['metadata', 'widget'],
|
|
8
8
|
},
|
|
9
9
|
],
|
|
10
10
|
properties: {
|
|
11
|
-
|
|
11
|
+
metadata: {
|
|
12
12
|
title: 'Metadata',
|
|
13
13
|
description: 'Select metadata to be used',
|
|
14
|
-
factory: 'Choice',
|
|
15
|
-
type: 'string',
|
|
16
14
|
choices: [
|
|
17
15
|
['title', 'Title'],
|
|
18
16
|
['description', 'Description'],
|
|
@@ -23,5 +21,5 @@ export const MentionSchema = {
|
|
|
23
21
|
type: 'string',
|
|
24
22
|
},
|
|
25
23
|
},
|
|
26
|
-
required: ['
|
|
24
|
+
required: ['metadata'],
|
|
27
25
|
};
|