@eeacms/volto-clms-theme 1.0.184 → 1.0.185

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,6 +4,12 @@ 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
+ ### [1.0.185](https://github.com/eea/volto-clms-theme/compare/1.0.184...1.0.185) - 13 March 2023
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - comment MenuList [Unai - [`b8dfeff`](https://github.com/eea/volto-clms-theme/commit/b8dfeff240130c803fd6c33dd6460cd8252f90af)]
12
+ - volto 16 array widget [Unai - [`a29aab8`](https://github.com/eea/volto-clms-theme/commit/a29aab86c035f352e32ca1c20edd926591566094)]
7
13
  ### [1.0.184](https://github.com/eea/volto-clms-theme/compare/1.0.183...1.0.184) - 10 March 2023
8
14
 
9
15
  #### :rocket: New Features
@@ -940,6 +946,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
940
946
  #### :hammer_and_wrench: Others
941
947
 
942
948
  - related products and datasets added to news and meeting views and login-plone route created [Unai - [`5704a1a`](https://github.com/eea/volto-clms-theme/commit/5704a1a766148746162b60efaf232ea90dc20cf4)]
949
+ - Revert "[JENKINS] Use eeacms/plone-backend and Volto alpha version- Refs #151967" [Mikel Larreategi - [`46eb694`](https://github.com/eea/volto-clms-theme/commit/46eb69415280a3c982405299135027ae4221426a)]
943
950
  - sort items according to the lowercased label and put those with special meaning at the end [Mikel Larreategi - [`6410abe`](https://github.com/eea/volto-clms-theme/commit/6410abe096f60dcad54dced2026c9df9b7946d68)]
944
951
  - lint fix [Unai - [`1264a7a`](https://github.com/eea/volto-clms-theme/commit/1264a7adfe8d679fea1bd821ad087add20f4271d)]
945
952
  - footer newsletter subscription change, global search maxLength change from 8000 to 200 and /login design change [Unai - [`a09d24a`](https://github.com/eea/volto-clms-theme/commit/a09d24adbb6fa053fb2a2cc0071506b906593b42)]
@@ -1090,6 +1097,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
1090
1097
  - search block new features [ionlizarazu - [`8e814cb`](https://github.com/eea/volto-clms-theme/commit/8e814cbd359782540c21fe37b37ef146d331f0d6)]
1091
1098
  - language selector cookie management [ionlizarazu - [`1385ac9`](https://github.com/eea/volto-clms-theme/commit/1385ac95795702206d3623ba6e780faa43a89e0a)]
1092
1099
  - toolbar cookie management [ionlizarazu - [`5c23200`](https://github.com/eea/volto-clms-theme/commit/5c23200790b20e1d4f1bc966463c37bf4c808f47)]
1100
+ - Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`0316a0d`](https://github.com/eea/volto-clms-theme/commit/0316a0d8b6fb0fa14af13002415f3c95d9f8ede3)]
1093
1101
  ### [1.0.84](https://github.com/eea/volto-clms-theme/compare/1.0.83...1.0.84) - 18 March 2022
1094
1102
 
1095
1103
  #### :hammer_and_wrench: Others
@@ -1994,11 +2002,13 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
1994
2002
  #### :hammer_and_wrench: Others
1995
2003
 
1996
2004
  - replace @collective/volto-dropdownmenu with volto-dropdownmenu [ionlizarazu - [`07f004f`](https://github.com/eea/volto-clms-theme/commit/07f004fe0219e403fb51bc045c83d34f3b981f76)]
2005
+ - yarn.lock [ionlizarazu - [`fe1ca04`](https://github.com/eea/volto-clms-theme/commit/fe1ca04889d29fe7b653db4c69af2751b84b8a1a)]
1997
2006
  - add NODE_ENV parameter [ionlizarazu - [`101f27c`](https://github.com/eea/volto-clms-theme/commit/101f27c25b8fbd192e1b11865e95cf5ffee08c1b)]
1998
2007
  - upgrade volto-dropdownmenu version [ionlizarazu - [`2081855`](https://github.com/eea/volto-clms-theme/commit/2081855301f4c708776e0dbab39db143cee00dbc)]
1999
2008
  - HomeSearch block missing url behaviour [ionlizarazu - [`d20a378`](https://github.com/eea/volto-clms-theme/commit/d20a378ce3f254b8343692348f314bf281974542)]
2000
2009
  - babel configuration [ionlizarazu - [`203ea2d`](https://github.com/eea/volto-clms-theme/commit/203ea2de07f99ca3403e4ca220ca74d7ce69b61d)]
2001
2010
  - prettier [ionlizarazu - [`e79e26b`](https://github.com/eea/volto-clms-theme/commit/e79e26bf2fa40ba7b4eb53a24dabd87928221c28)]
2011
+ - add yarn lock [ionlizarazu - [`e1ab28b`](https://github.com/eea/volto-clms-theme/commit/e1ab28b060d5a74431c368b0de82a68dabce1eab)]
2002
2012
  - Jenkinsfile cypress test [ionlizarazu - [`b385d65`](https://github.com/eea/volto-clms-theme/commit/b385d65986f717c60f8c434a08fc11b829d08eb4)]
2003
2013
  - cypress [ionlizarazu - [`a243cf0`](https://github.com/eea/volto-clms-theme/commit/a243cf0182fa3dd113c16ff495c71e310252d83b)]
2004
2014
  - some fixes [ionlizarazu - [`046279b`](https://github.com/eea/volto-clms-theme/commit/046279b9d05bea8a64eca03eed493e02621534c9)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-clms-theme",
3
- "version": "1.0.184",
3
+ "version": "1.0.185",
4
4
  "description": "volto-clms-theme: Volto theme for CLMS site",
5
5
  "main": "src/index.js",
6
6
  "author": "CodeSyntax for the European Environment Agency",
@@ -0,0 +1,424 @@
1
+ /**
2
+ * ArrayWidget component.
3
+ * @module components/manage/Widgets/ArrayWidget
4
+ */
5
+
6
+ import React, { Component } from 'react';
7
+ import { defineMessages, injectIntl } from 'react-intl';
8
+ import PropTypes from 'prop-types';
9
+ import { compose } from 'redux';
10
+ import { connect } from 'react-redux';
11
+ import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable';
12
+ import { find, isObject } from 'lodash';
13
+
14
+ import {
15
+ getVocabFromHint,
16
+ getVocabFromField,
17
+ getVocabFromItems,
18
+ } from '@plone/volto/helpers';
19
+ import { getVocabulary } from '@plone/volto/actions';
20
+
21
+ import {
22
+ Option,
23
+ DropdownIndicator,
24
+ ClearIndicator,
25
+ selectTheme,
26
+ customSelectStyles,
27
+ // MenuList,
28
+ SortableMultiValue,
29
+ SortableMultiValueLabel,
30
+ MultiValueContainer,
31
+ } from '@plone/volto/components/manage/Widgets/SelectStyling';
32
+
33
+ import { FormFieldWrapper } from '@plone/volto/components';
34
+
35
+ const messages = defineMessages({
36
+ select: {
37
+ id: 'Select…',
38
+ defaultMessage: 'Select…',
39
+ },
40
+ no_value: {
41
+ id: 'No value',
42
+ defaultMessage: 'No value',
43
+ },
44
+ no_options: {
45
+ id: 'No options',
46
+ defaultMessage: 'No options',
47
+ },
48
+ });
49
+
50
+ function arrayMove(array, from, to) {
51
+ const slicedArray = array.slice();
52
+ slicedArray.splice(
53
+ to < 0 ? array.length + to : to,
54
+ 0,
55
+ slicedArray.splice(from, 1)[0],
56
+ );
57
+ return slicedArray;
58
+ }
59
+
60
+ function normalizeArrayValue(choices, value) {
61
+ if (!value || !Array.isArray(value)) return [];
62
+ if (value.length === 0) return value;
63
+
64
+ if (typeof value[0] === 'string') {
65
+ // raw value like ['foo', 'bar']
66
+ return value.map((v) => {
67
+ return {
68
+ label: find(choices, (c) => c.value === v)?.label || v,
69
+ value: v,
70
+ };
71
+ });
72
+ }
73
+
74
+ if (
75
+ isObject(value[0]) &&
76
+ Object.keys(value[0]).includes('token') // Array of objects, w/ label+value
77
+ ) {
78
+ return value
79
+ .map((v) => {
80
+ const item = find(choices, (c) => c.value === v.token);
81
+ return item
82
+ ? {
83
+ label: item.label || item.title || item.token,
84
+ value: v.token,
85
+ }
86
+ : {
87
+ // avoid a crash if choices doesn't include this item
88
+ label: v.label,
89
+ value: v.token,
90
+ };
91
+ })
92
+ .filter((f) => !!f);
93
+ }
94
+
95
+ return [];
96
+ }
97
+
98
+ function normalizeChoices(choices) {
99
+ if (Array.isArray(choices) && choices.length && Array.isArray(choices[0])) {
100
+ return choices.map((option) => ({
101
+ value: option[0],
102
+ label:
103
+ // Fix "None" on the serializer, to remove when fixed in p.restapi
104
+ option[1] !== 'None' && option[1] ? option[1] : option[0],
105
+ }));
106
+ }
107
+
108
+ return choices;
109
+ }
110
+
111
+ /**
112
+ * Compare values and return true if equal.
113
+ * Consider upper and lower case.
114
+ * @method compareOption
115
+ * @param {*} inputValue
116
+ * @param {*} option
117
+ * @param {*} accessors
118
+ * @returns {boolean}
119
+ */
120
+ const compareOption = (inputValue = '', option, accessors) => {
121
+ const candidate = String(inputValue);
122
+ const optionValue = String(accessors.getOptionValue(option));
123
+ const optionLabel = String(accessors.getOptionLabel(option));
124
+ return optionValue === candidate || optionLabel === candidate;
125
+ };
126
+
127
+ /**
128
+ * ArrayWidget component class.
129
+ * @class ArrayWidget
130
+ * @extends Component
131
+ *
132
+ * A createable select array widget will be rendered if the named vocabulary is
133
+ * in the widget definition (hint) like:
134
+ *
135
+ * ```
136
+ * list_field_voc_unconstrained = schema.List(
137
+ * title=u"List field with values from vocabulary but not constrained to them.",
138
+ * description=u"zope.schema.List",
139
+ * value_type=schema.TextLine(),
140
+ * required=False,
141
+ * missing_value=[],
142
+ * )
143
+ * directives.widget(
144
+ * "list_field_voc_unconstrained",
145
+ * AjaxSelectFieldWidget,
146
+ * vocabulary="plone.app.vocabularies.PortalTypes",
147
+ * )
148
+ * ```
149
+ */
150
+ class ArrayWidget extends Component {
151
+ /**
152
+ * Property types.
153
+ * @property {Object} propTypes Property types.
154
+ * @static
155
+ */
156
+ static propTypes = {
157
+ id: PropTypes.string.isRequired,
158
+ title: PropTypes.string.isRequired,
159
+ description: PropTypes.string,
160
+ required: PropTypes.bool,
161
+ error: PropTypes.arrayOf(PropTypes.string),
162
+ getVocabulary: PropTypes.func.isRequired,
163
+ choices: PropTypes.arrayOf(
164
+ PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
165
+ ),
166
+ vocabLoading: PropTypes.bool,
167
+ vocabLoaded: PropTypes.bool,
168
+ items: PropTypes.shape({
169
+ vocabulary: PropTypes.object,
170
+ }),
171
+ widgetOptions: PropTypes.shape({
172
+ vocabulary: PropTypes.object,
173
+ }),
174
+ value: PropTypes.arrayOf(
175
+ PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
176
+ ),
177
+ placeholder: PropTypes.string,
178
+ onChange: PropTypes.func.isRequired,
179
+ wrapped: PropTypes.bool,
180
+ creatable: PropTypes.bool, //if widget has no vocab and you want to be creatable
181
+ };
182
+
183
+ /**
184
+ * Default properties
185
+ * @property {Object} defaultProps Default properties.
186
+ * @static
187
+ */
188
+ static defaultProps = {
189
+ description: null,
190
+ required: false,
191
+ items: {
192
+ vocabulary: null,
193
+ },
194
+ widgetOptions: {
195
+ vocabulary: null,
196
+ },
197
+ error: [],
198
+ choices: [],
199
+ value: null,
200
+ creatable: false,
201
+ };
202
+
203
+ /**
204
+ * Constructor
205
+ * @method constructor
206
+ * @param {Object} props Component properties
207
+ * @constructs Actions
208
+ */
209
+ constructor(props) {
210
+ super(props);
211
+
212
+ this.handleChange = this.handleChange.bind(this);
213
+ }
214
+
215
+ /**
216
+ * Component did mount
217
+ * @method componentDidMount
218
+ * @returns {undefined}
219
+ */
220
+ componentDidMount() {
221
+ if (
222
+ !this.props.items?.choices?.length &&
223
+ !this.props.choices?.length &&
224
+ this.props.vocabBaseUrl
225
+ ) {
226
+ this.props.getVocabulary({
227
+ vocabNameOrURL: this.props.vocabBaseUrl,
228
+ size: -1,
229
+ subrequest: this.props.lang,
230
+ });
231
+ }
232
+ }
233
+
234
+ componentDidUpdate() {
235
+ if (
236
+ !this.props.items?.choices?.length &&
237
+ !this.props.choices?.length &&
238
+ this.props.vocabLoading === undefined &&
239
+ !this.props.vocabLoaded &&
240
+ this.props.vocabBaseUrl
241
+ ) {
242
+ this.props.getVocabulary({
243
+ vocabNameOrURL: this.props.vocabBaseUrl,
244
+ size: -1,
245
+ subrequest: this.props.lang,
246
+ });
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Handle the field change, store it in the local state and back to simple
252
+ * array of tokens for correct serialization
253
+ * @method handleChange
254
+ * @param {array} selectedOption The selected options (already aggregated).
255
+ * @returns {undefined}
256
+ */
257
+ handleChange(selectedOption) {
258
+ this.props.onChange(
259
+ this.props.id,
260
+ selectedOption ? selectedOption.map((item) => item.value) : null,
261
+ );
262
+ }
263
+
264
+ onSortEnd = (selectedOption, { oldIndex, newIndex }) => {
265
+ const newValue = arrayMove(selectedOption, oldIndex, newIndex);
266
+
267
+ this.handleChange(newValue);
268
+ };
269
+
270
+ /**
271
+ * Render method.
272
+ * @method render
273
+ * @returns {string} Markup for the component.
274
+ */
275
+ render() {
276
+ const choices = normalizeChoices(this.props?.choices || []);
277
+ const selectedOption = normalizeArrayValue(choices, this.props.value);
278
+
279
+ const CreatableSelect = this.props.reactSelectCreateable.default;
280
+ const { SortableContainer } = this.props.reactSortableHOC;
281
+ const Select = this.props.reactSelect.default;
282
+ const SortableSelect =
283
+ // It will be only createable if the named vocabulary is in the widget definition
284
+ // (hint) like:
285
+ // list_field_voc_unconstrained = schema.List(
286
+ // title=u"List field with values from vocabulary but not constrained to them.",
287
+ // description=u"zope.schema.List",
288
+ // value_type=schema.TextLine(),
289
+ // required=False,
290
+ // missing_value=[],
291
+ // )
292
+ // directives.widget(
293
+ // "list_field_voc_unconstrained",
294
+ // AjaxSelectFieldWidget,
295
+ // vocabulary="plone.app.vocabularies.PortalTypes",
296
+ // )
297
+ this.props?.choices &&
298
+ !getVocabFromHint(this.props) &&
299
+ !this.props.creatable
300
+ ? SortableContainer(Select)
301
+ : SortableContainer(CreatableSelect);
302
+
303
+ return (
304
+ <FormFieldWrapper {...this.props}>
305
+ <SortableSelect
306
+ useDragHandle
307
+ // react-sortable-hoc props:
308
+ axis="xy"
309
+ onSortEnd={this.onSortEnd}
310
+ menuShouldScrollIntoView={false}
311
+ distance={4}
312
+ // small fix for https://github.com/clauderic/react-sortable-hoc/pull/352:
313
+ getHelperDimensions={({ node }) => node.getBoundingClientRect()}
314
+ id={`field-${this.props.id}`}
315
+ key={this.props.id}
316
+ isDisabled={this.props.disabled || this.props.isDisabled}
317
+ className="react-select-container"
318
+ classNamePrefix="react-select"
319
+ /* eslint-disable jsx-a11y/no-autofocus */
320
+ autoFocus={this.props.focus}
321
+ /* eslint-enable jsx-a11y/no-autofocus */
322
+ options={
323
+ this.props.vocabBaseUrl
324
+ ? choices
325
+ : this.props.choices
326
+ ? [
327
+ ...choices,
328
+ ...(this.props.noValueOption && !this.props.default
329
+ ? [
330
+ {
331
+ label: this.props.intl.formatMessage(
332
+ messages.no_value,
333
+ ),
334
+ value: 'no-value',
335
+ },
336
+ ]
337
+ : []),
338
+ ]
339
+ : [
340
+ {
341
+ label: this.props.intl.formatMessage(messages.no_value),
342
+ value: 'no-value',
343
+ },
344
+ ]
345
+ }
346
+ styles={customSelectStyles}
347
+ theme={selectTheme}
348
+ components={{
349
+ // ...(this.props.choices?.length > 25 && {
350
+ // MenuList,
351
+ // }),
352
+ MultiValueContainer,
353
+ MultiValue: SortableMultiValue,
354
+ MultiValueLabel: SortableMultiValueLabel,
355
+ DropdownIndicator,
356
+ ClearIndicator,
357
+ Option,
358
+ }}
359
+ value={selectedOption || []}
360
+ placeholder={
361
+ this.props.placeholder ??
362
+ this.props.intl.formatMessage(messages.select)
363
+ }
364
+ onChange={this.handleChange}
365
+ isValidNewOption={(
366
+ inputValue,
367
+ selectValue,
368
+ selectOptions,
369
+ accessors,
370
+ ) =>
371
+ !(
372
+ !inputValue ||
373
+ selectValue.some((option) =>
374
+ compareOption(inputValue, option, accessors),
375
+ ) ||
376
+ selectOptions.some((option) =>
377
+ compareOption(inputValue, option, accessors),
378
+ )
379
+ )
380
+ }
381
+ isClearable
382
+ isMulti
383
+ />
384
+ </FormFieldWrapper>
385
+ );
386
+ }
387
+ }
388
+
389
+ export const ArrayWidgetComponent = injectIntl(ArrayWidget);
390
+
391
+ export default compose(
392
+ injectIntl,
393
+ injectLazyLibs(['reactSelect', 'reactSelectCreateable', 'reactSortableHOC']),
394
+ connect(
395
+ (state, props) => {
396
+ const vocabBaseUrl =
397
+ getVocabFromHint(props) ||
398
+ getVocabFromField(props) ||
399
+ getVocabFromItems(props);
400
+
401
+ const vocabState =
402
+ state.vocabularies?.[vocabBaseUrl]?.subrequests?.[state.intl.locale];
403
+
404
+ // If the schema already has the choices in it, then do not try to get the vocab,
405
+ // even if there is one
406
+ if (props.items?.choices) {
407
+ return {
408
+ choices: props.items.choices,
409
+ lang: state.intl.locale,
410
+ };
411
+ } else if (vocabState) {
412
+ return {
413
+ choices: vocabState.items,
414
+ vocabBaseUrl,
415
+ vocabLoading: vocabState.loading,
416
+ vocabLoaded: vocabState.loaded,
417
+ lang: state.intl.locale,
418
+ };
419
+ }
420
+ return { vocabBaseUrl, lang: state.intl.locale };
421
+ },
422
+ { getVocabulary },
423
+ ),
424
+ )(ArrayWidget);