@eeacms/volto-slate-metadata-mentions 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,16 @@ 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
+
7
12
  #### [4.0.3](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.2...4.0.3)
8
13
 
9
- - Disable faulty cypress test [`60f9d12`](https://github.com/eea/volto-slate-metadata-mentions/commit/60f9d12bf52282624b386b1d0490400bd9826f78)
14
+ > 16 March 2022
15
+
16
+ - Disable faulty cypress test [`#23`](https://github.com/eea/volto-slate-metadata-mentions/pull/23)
10
17
 
11
18
  #### [4.0.2](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.1...4.0.2)
12
19
 
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,demo-www.eea.europa.eu"
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"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-slate-metadata-mentions",
3
- "version": "4.0.3",
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
  };