@eeacms/volto-slate-metadata-mentions 4.0.1 → 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,10 +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.0](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.3...5.0.0)
8
+
9
+ - [Fix #24] Change metadata selector property name from 'id' to 'metadata' [`#24`](https://github.com/eea/volto-slate-metadata-mentions/issues/24)
10
+ - Breaking 5.0.0 [`9daf888`](https://github.com/eea/volto-slate-metadata-mentions/commit/9daf88800e0f375b9e7927540827c64c8f03c00e)
11
+
12
+ #### [4.0.3](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.2...4.0.3)
13
+
14
+ > 16 March 2022
15
+
16
+ - Disable faulty cypress test [`#23`](https://github.com/eea/volto-slate-metadata-mentions/pull/23)
17
+
18
+ #### [4.0.2](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.1...4.0.2)
19
+
20
+ > 3 January 2022
21
+
22
+
7
23
  #### [4.0.1](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.0...4.0.1)
8
24
 
25
+ > 18 December 2021
26
+
27
+ - Add SonarQube badges [`#21`](https://github.com/eea/volto-slate-metadata-mentions/pull/21)
9
28
  - Use a button factory [`#19`](https://github.com/eea/volto-slate-metadata-mentions/pull/19)
10
- - Add SonarQube badges [`5d68285`](https://github.com/eea/volto-slate-metadata-mentions/commit/5d68285dd04f86628ba7f9174c1945412b5fb9a1)
11
29
  - Refs #142010 - Optimize Volto-addons gitflow pipelines [`3a6a696`](https://github.com/eea/volto-slate-metadata-mentions/commit/3a6a69612652cd947d54f77c430bdca21b82a0df)
12
30
 
13
31
  ### [4.0.0](https://github.com/eea/volto-slate-metadata-mentions/compare/3.0.2...4.0.0)
package/Jenkinsfile CHANGED
@@ -4,7 +4,7 @@ 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"
8
8
  DEPENDENCIES = ""
9
9
  PLONE_VERSIONS = "plone.schema=1.3.0 plone.restapi=8.9.1"
10
10
  PLONE_ADDONS = "eea.schema.slate"
@@ -126,7 +126,7 @@ pipeline {
126
126
  node(label: 'docker') {
127
127
  script {
128
128
  try {
129
- sh '''docker pull plone; docker run -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e ADDONS="$PLONE_ADDONS" -e VERSIONS="$PLONE_VERSIONS" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
129
+ sh '''docker pull plone; docker run -d --rm --name="$BUILD_TAG-plone" -e SITE="Plone" -e ADDONS="$PLONE_ADDONS" -e VERSIONS="$PLONE_VERSIONS" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
130
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'''
131
131
  } finally {
132
132
  try {
@@ -144,7 +144,8 @@ pipeline {
144
144
  reportName: 'CypressCoverage',
145
145
  reportTitles: 'Integration Tests Code Coverage'])
146
146
  }
147
- archiveArtifacts artifacts: 'cypress-reports/videos/*.mp4', fingerprint: true
147
+ 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'''
148
+ archiveArtifacts artifacts: 'cypress-reports/**/*.mp4', fingerprint: true, allowEmptyArchive: true
148
149
  stash name: "cypress-coverage", includes: "cypress-coverage/**", allowEmpty: true
149
150
  }
150
151
  finally {
@@ -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
- .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();
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 blue cats sleep furiously.');
40
+ cy.contains('Colorless green ideas sleep furiously.');
41
41
  });
42
42
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-slate-metadata-mentions",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "Volto Slate Metadata Mentions Plugin",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -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
- [elementNode.data.id]: metaData?.[elementNode.data.id],
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, { id: formData?.id, widget: formData?.widget });
72
+ insertElement(editor, {
73
+ metadata: formData?.metadata,
74
+ widget: formData?.widget,
75
+ });
72
76
 
73
77
  // Update document metadata
74
- onChangeField && onChangeField(formData?.id, formData[formData?.id]);
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
- id: {
108
- ...MentionSchema.properties.id,
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 = elementNode?.data?.id;
129
+ const metaId = id;
125
130
  updateSchema(metaId);
126
- }, [updateSchema, elementNode?.data?.id]);
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 === '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 (!elementNode.data.id) {
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[data.id];
31
+ let output = metadata[id];
31
32
  let Widget = views.getWidget(data);
32
- let className = 'metadata mention ' + data?.id;
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 = data?.id;
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={data.id}>
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={data.id}>
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: ['id', 'widget'],
7
+ fields: ['metadata', 'widget'],
8
8
  },
9
9
  ],
10
10
  properties: {
11
- id: {
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: ['id'],
24
+ required: ['metadata'],
27
25
  };