design-comuni-plone-theme 11.20.1 → 11.20.2

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.
Binary file
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
 
2
2
 
3
+ ## [11.20.2](https://github.com/RedTurtle/design-comuni-plone-theme/compare/v11.20.1...v11.20.2) (2024-08-12)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 302 redirects for aliases, removed custom cors error logging ([8348e94](https://github.com/RedTurtle/design-comuni-plone-theme/commit/8348e94940feeddc85c8f3d0364f37daa2145404))
9
+ * icons lazy loading race condition ([4e32354](https://github.com/RedTurtle/design-comuni-plone-theme/commit/4e3235467b886144afcc240aacda9116b729aeb8))
10
+
11
+
12
+ ### Maintenance
13
+
14
+ * remove unused performance workflow ([adc31a7](https://github.com/RedTurtle/design-comuni-plone-theme/commit/adc31a718b491075b03d789714354089de09a06e))
15
+
16
+
17
+ ### Documentation
18
+
19
+ * updated publiccode and release log ([e9a2e52](https://github.com/RedTurtle/design-comuni-plone-theme/commit/e9a2e52247683876b2599bf6938e65354457f6f4))
20
+
3
21
  ## [11.20.1](https://github.com/RedTurtle/design-comuni-plone-theme/compare/v11.20.0...v11.20.1) (2024-08-09)
4
22
 
5
23
 
package/RELEASE.md CHANGED
@@ -41,6 +41,12 @@
41
41
  - ...
42
42
  -->
43
43
 
44
+ ## Versione 11.20.2 (12/08/2024)
45
+
46
+ ### Fix
47
+
48
+ - Risolto un problema per cui veniva mostrato temporaneamente un messaggio di errore quando si visitava un indirizzo alternativo creato con lo strumento Gestione URL.
49
+
44
50
  ## Versione 11.20.1 (09/08/2024)
45
51
 
46
52
  ### Fix
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "design-comuni-plone-theme",
3
3
  "description": "Volto Theme for Italia design guidelines",
4
4
  "license": "GPL-v3",
5
- "version": "11.20.1",
5
+ "version": "11.20.2",
6
6
  "main": "src/index.js",
7
7
  "repository": {
8
8
  "type": "git",
package/publiccode.yml CHANGED
@@ -227,9 +227,9 @@ maintenance:
227
227
  name: io-Comune - Il sito AgID per Comuni ed Enti Pubblici
228
228
  platforms:
229
229
  - web
230
- releaseDate: '2024-08-09'
230
+ releaseDate: '2024-08-12'
231
231
  softwareType: standalone/web
232
- softwareVersion: 11.20.1
232
+ softwareVersion: 11.20.2
233
233
  url: 'https://github.com/italia/design-comuni-plone-theme'
234
234
  usedBy:
235
235
  - ASP Comuni Modenesi Area Nord
@@ -36,12 +36,12 @@ const FontAwesomeIcon = (props) => {
36
36
  prefixKey === 'fab'
37
37
  ? 'brands'
38
38
  : prefixKey === 'far'
39
- ? 'regular'
40
- : prefixKey === 'fas'
41
- ? 'solid'
42
- : prefixKey != null
43
- ? prefixKey
44
- : 'solid',
39
+ ? 'regular'
40
+ : prefixKey === 'fas'
41
+ ? 'solid'
42
+ : prefixKey != null
43
+ ? prefixKey
44
+ : 'solid',
45
45
  iconName,
46
46
  ];
47
47
  };
@@ -24,17 +24,9 @@ export {
24
24
 
25
25
  /********* ICONS ********* */
26
26
  export getItemIcon from 'design-comuni-plone-theme/components/ItaliaTheme/Icons/common/common';
27
- export const Icon = loadable(() =>
28
- import(
29
- /* webpackChunkName: "DCPTIcons" */ 'design-comuni-plone-theme/components/ItaliaTheme/Icons/Icon'
30
- ),
31
- );
27
+ export Icon from 'design-comuni-plone-theme/components/ItaliaTheme/Icons/Icon';
32
28
  export SectionIcon from 'design-comuni-plone-theme/components/ItaliaTheme/Icons/SectionIcon';
33
- export const FontAwesomeIcon = loadable(() =>
34
- import(
35
- /* webpackChunkName: "DCPTIcons" */ 'design-comuni-plone-theme/components/ItaliaTheme/Icons/FontAwesomeIcon'
36
- ),
37
- );
29
+ export FontAwesomeIcon from 'design-comuni-plone-theme/components/ItaliaTheme/Icons/FontAwesomeIcon';
38
30
 
39
31
  /********* COMMONS ********* */
40
32
  export CardCategory from 'design-comuni-plone-theme/components/ItaliaTheme/Cards/CardCategory';
@@ -56,25 +48,29 @@ export SubsiteHeader from 'design-comuni-plone-theme/components/ItaliaTheme/Head
56
48
  export ParentSiteMenu from 'design-comuni-plone-theme/components/ItaliaTheme/Header/ParentSiteMenu';
57
49
  export HeaderSearch from 'design-comuni-plone-theme/components/ItaliaTheme/Header/HeaderSearch/HeaderSearch';
58
50
  export SearchModal from 'design-comuni-plone-theme/components/ItaliaTheme/Header/HeaderSearch/SearchModal';
59
- export const SearchTopics = loadable(() =>
60
- import(
61
- /* webpackChunkName: "DCPTSearch" */ 'design-comuni-plone-theme/components/ItaliaTheme/Search/SearchTopics'
62
- ),
51
+ export const SearchTopics = loadable(
52
+ () =>
53
+ import(
54
+ /* webpackChunkName: "DCPTSearch" */ 'design-comuni-plone-theme/components/ItaliaTheme/Search/SearchTopics'
55
+ ),
63
56
  );
64
- export const SearchCTs = loadable(() =>
65
- import(
66
- /* webpackChunkName: "DCPTSearch" */ 'design-comuni-plone-theme/components/ItaliaTheme/Search/SearchCTs'
67
- ),
57
+ export const SearchCTs = loadable(
58
+ () =>
59
+ import(
60
+ /* webpackChunkName: "DCPTSearch" */ 'design-comuni-plone-theme/components/ItaliaTheme/Search/SearchCTs'
61
+ ),
68
62
  );
69
- export const SearchResultItem = loadable(() =>
70
- import(
71
- /* webpackChunkName: "DCPTSearch" */ 'design-comuni-plone-theme/components/ItaliaTheme/Search/ResultItem'
72
- ),
63
+ export const SearchResultItem = loadable(
64
+ () =>
65
+ import(
66
+ /* webpackChunkName: "DCPTSearch" */ 'design-comuni-plone-theme/components/ItaliaTheme/Search/ResultItem'
67
+ ),
73
68
  );
74
- export const SearchSections = loadable(() =>
75
- import(
76
- /* webpackChunkName: "DCPTSearch" */ 'design-comuni-plone-theme/components/ItaliaTheme/Search/SearchSections'
77
- ),
69
+ export const SearchSections = loadable(
70
+ () =>
71
+ import(
72
+ /* webpackChunkName: "DCPTSearch" */ 'design-comuni-plone-theme/components/ItaliaTheme/Search/SearchSections'
73
+ ),
78
74
  );
79
75
  export MegaMenu from 'design-comuni-plone-theme/components/ItaliaTheme/MegaMenu/MegaMenu';
80
76
  export MenuSecondary from 'design-comuni-plone-theme/components/ItaliaTheme/MenuSecondary/MenuSecondary';
@@ -5,10 +5,11 @@ export const loadables = {
5
5
  reactSlick: loadable.lib(() => import('react-slick')),
6
6
  rrule: loadable.lib(() => import('rrule')),
7
7
  htmlDiffLib: loadable.lib(() => import('htmldiff-js')),
8
- fontAwesomeAliases: loadable.lib(() =>
9
- import(
10
- /* webpackChunkName: "DCPTIcons" */ 'design-comuni-plone-theme/helpers/IconWidget/IconAliasHelper'
11
- ),
8
+ fontAwesomeAliases: loadable.lib(
9
+ () =>
10
+ import(
11
+ /* webpackChunkName: "DCPTIcons" */ 'design-comuni-plone-theme/helpers/IconWidget/IconAliasHelper'
12
+ ),
12
13
  ),
13
14
  ...subsitesLoadables,
14
15
  };
@@ -1,47 +0,0 @@
1
- name: Docker build for latest performance test version
2
- on:
3
- push:
4
- branches: [performance]
5
-
6
- jobs:
7
- build_develop:
8
- runs-on: ubuntu-latest
9
- steps:
10
- - uses: actions/checkout@v3
11
-
12
- - name: Set up Docker Buildx
13
- uses: docker/setup-buildx-action@v2
14
-
15
- - name: Login to DockerHub
16
- uses: docker/login-action@v2
17
- with:
18
- username: ${{ secrets.DOCKERHUB_USERNAME }}
19
- password: ${{ secrets.DOCKERHUB_TOKEN }}
20
-
21
- - name: Build and push Docker images
22
- uses: docker/build-push-action@v4
23
- with:
24
- context: .
25
- file: ./dockerfiles/Dockerfile
26
- tags: redturtletech/io-comune-base:perf
27
- pull: true
28
- push: true
29
- cache-from: type=registry,ref=redturtletech/io-comune-base:perf
30
- cache-to: type=inline
31
- build-args: |
32
- ADDON_NAME=design-comuni-plone-theme
33
- ADDON_PATH=design-comuni-plone-theme
34
- VOLTO_VERSION=17.18.2
35
-
36
- - name: Deploy to rancher
37
- uses: redturtle/rancher-deploy-action@v0.2.0
38
- with:
39
- host: ${{ secrets.RANCHER_HOST }}
40
- api-username: ${{ secrets.RANCHER_API_USERNAME }}
41
- api-password: ${{ secrets.RANCHER_API_PASSWORD }}
42
- cluster-id: ${{ secrets.RANCHER_CLUSTER_ID }}
43
- project-id: ${{ secrets.RANCHER_PROJECT_ID }}
44
- namespace: ${{ secrets.RANCHER_NAMESPACE_DEVELOP }}
45
- workload: ${{ secrets.RANCHER_WORKLOAD_PERF }}
46
- image: redturtletech/io-comune-base:perf
47
- slack-hook-url: ${{ secrets.RANCHER_SLACK_HOOK_URL }}
@@ -1,353 +0,0 @@
1
- /**
2
- * View container.
3
- * @module components/theme/View/View
4
- * Customization:
5
- * - added logging of errors
6
- */
7
-
8
- import React, { Component } from 'react';
9
- import PropTypes from 'prop-types';
10
- import { connect } from 'react-redux';
11
- import { compose } from 'redux';
12
- import { Redirect } from 'react-router-dom';
13
- import { Portal } from 'react-portal';
14
- import { injectIntl } from 'react-intl';
15
- import qs from 'query-string';
16
-
17
- import loadable from '@loadable/component';
18
-
19
- import {
20
- ContentMetadataTags,
21
- Comments,
22
- Tags,
23
- Toolbar,
24
- } from '@plone/volto/components';
25
- import { listActions, getContent } from '@plone/volto/actions';
26
- import {
27
- BodyClass,
28
- getBaseUrl,
29
- flattenToAppURL,
30
- getLayoutFieldname,
31
- hasApiExpander,
32
- } from '@plone/volto/helpers';
33
-
34
- import config from '@plone/volto/registry';
35
-
36
- const sentryLibraries = {
37
- Sentry: loadable.lib(
38
- () => import(/* webpackChunkName: "s_entry-browser" */ '@sentry/browser'),
39
- ),
40
- };
41
-
42
- /**
43
- * View container class.
44
- * @class View
45
- * @extends Component
46
- */
47
- class View extends Component {
48
- /**
49
- * Property types.
50
- * @property {Object} propTypes Property types.
51
- * @static
52
- */
53
- static propTypes = {
54
- actions: PropTypes.shape({
55
- object: PropTypes.arrayOf(PropTypes.object),
56
- object_buttons: PropTypes.arrayOf(PropTypes.object),
57
- user: PropTypes.arrayOf(PropTypes.object),
58
- }),
59
- listActions: PropTypes.func.isRequired,
60
- /**
61
- * Action to get the content
62
- */
63
- getContent: PropTypes.func.isRequired,
64
- /**
65
- * Pathname of the object
66
- */
67
- pathname: PropTypes.string.isRequired,
68
- location: PropTypes.shape({
69
- search: PropTypes.string,
70
- pathname: PropTypes.string,
71
- }).isRequired,
72
- /**
73
- * Version id of the object
74
- */
75
- versionId: PropTypes.string,
76
- /**
77
- * Content of the object
78
- */
79
- content: PropTypes.shape({
80
- /**
81
- * Layout of the object
82
- */
83
- layout: PropTypes.string,
84
- /**
85
- * Allow discussion of the object
86
- */
87
- allow_discussion: PropTypes.bool,
88
- /**
89
- * Title of the object
90
- */
91
- title: PropTypes.string,
92
- /**
93
- * Description of the object
94
- */
95
- description: PropTypes.string,
96
- /**
97
- * Type of the object
98
- */
99
- '@type': PropTypes.string,
100
- /**
101
- * Subjects of the object
102
- */
103
- subjects: PropTypes.arrayOf(PropTypes.string),
104
- is_folderish: PropTypes.bool,
105
- }),
106
- error: PropTypes.shape({
107
- /**
108
- * Error type
109
- */
110
- status: PropTypes.number,
111
- }),
112
- };
113
-
114
- /**
115
- * Default properties.
116
- * @property {Object} defaultProps Default properties.
117
- * @static
118
- */
119
- static defaultProps = {
120
- actions: null,
121
- content: null,
122
- versionId: null,
123
- error: null,
124
- };
125
-
126
- state = {
127
- hasObjectButtons: null,
128
- isClient: false,
129
- };
130
-
131
- componentDidMount() {
132
- // Do not trigger the actions action if the expander is present
133
- if (!hasApiExpander('actions', getBaseUrl(this.props.pathname))) {
134
- this.props.listActions(getBaseUrl(this.props.pathname));
135
- }
136
-
137
- this.props.getContent(
138
- getBaseUrl(this.props.pathname),
139
- this.props.versionId,
140
- );
141
- this.setState({ isClient: true });
142
- }
143
-
144
- /**
145
- * Component will receive props
146
- * @method componentWillReceiveProps
147
- * @param {Object} nextProps Next properties
148
- * @returns {undefined}
149
- */
150
- UNSAFE_componentWillReceiveProps(nextProps) {
151
- if (nextProps.pathname !== this.props.pathname) {
152
- // Do not trigger the actions action if the expander is present
153
- if (!hasApiExpander('actions', getBaseUrl(nextProps.pathname))) {
154
- this.props.listActions(getBaseUrl(nextProps.pathname));
155
- }
156
-
157
- this.props.getContent(
158
- getBaseUrl(nextProps.pathname),
159
- this.props.versionId,
160
- );
161
- }
162
-
163
- if (nextProps.actions.object_buttons) {
164
- const objectButtons = nextProps.actions.object_buttons;
165
- this.setState({
166
- hasObjectButtons: !!objectButtons.length,
167
- });
168
- }
169
- }
170
-
171
- /**
172
- * Default fallback view
173
- * @method getViewDefault
174
- * @returns {string} Markup for component.
175
- */
176
- getViewDefault = () => config.views.defaultView;
177
-
178
- /**
179
- * Get view by content type
180
- * @method getViewByType
181
- * @returns {string} Markup for component.
182
- */
183
- getViewByType = () =>
184
- config.views.contentTypesViews[this.props.content['@type']] || null;
185
-
186
- /**
187
- * Get view by content layout property
188
- * @method getViewByLayout
189
- * @returns {string} Markup for component.
190
- */
191
- getViewByLayout = () =>
192
- config.views.layoutViews[
193
- this.props.content[getLayoutFieldname(this.props.content)]
194
- ] || null;
195
-
196
- /**
197
- * Cleans the component displayName (specially for connected components)
198
- * which have the Connect(componentDisplayName)
199
- * @method cleanViewName
200
- * @param {string} dirtyDisplayName The displayName
201
- * @returns {string} Clean displayName (no Connect(...)).
202
- */
203
- cleanViewName = (dirtyDisplayName) =>
204
- dirtyDisplayName
205
- .replace('Connect(', '')
206
- .replace('injectIntl(', '')
207
- .replace(')', '')
208
- .replace('connect(', '')
209
- .toLowerCase();
210
-
211
- // CUSTOMIZATION: added logging of errors
212
- notifySentry = (message) => {
213
- const loaders = Object.entries(sentryLibraries).map(
214
- ([name, Lib]) =>
215
- new Promise((resolve) =>
216
- Lib.load().then((mod) => resolve([name, mod])),
217
- ),
218
- );
219
- Promise.all(loaders).then((libs) => {
220
- const libraries = Object.assign(
221
- {},
222
- ...libs.map(([name, lib]) => ({ [name]: lib })),
223
- );
224
- class MaybeCorsError extends Error {
225
- constructor(...args) {
226
- super(...args);
227
- this.name = 'MaybeCorsError';
228
- }
229
- }
230
- libraries.Sentry.captureException(new MaybeCorsError(message), {
231
- contexts: {
232
- props: {
233
- isAnonymous: !this.props.token,
234
- ...this.props,
235
- },
236
- },
237
- });
238
- });
239
- };
240
-
241
- /**
242
- * Render method.
243
- * @method render
244
- * @returns {string} Markup for the component.
245
- */
246
- render() {
247
- const { views } = config;
248
- if (this.props.error && this.props.error.code === 301) {
249
- const redirect = flattenToAppURL(this.props.error.url).split('?')[0];
250
- return <Redirect to={`${redirect}${this.props.location.search}`} />;
251
- } else if (this.props.error && !this.props.connectionRefused) {
252
- let FoundView;
253
- if (this.props.error.status === undefined) {
254
- // For some reason, while development and if CORS is in place and the
255
- // requested resource is 404, it returns undefined as status, then the
256
- // next statement will fail
257
- // eslint-disable-next-line no-console
258
- console.error(
259
- 'DEV MODE CORS ERROR in View component: ',
260
- JSON.stringify(this.props, null, 2),
261
- );
262
- this.notifySentry('DEV MODE CORS ERROR in View component');
263
- FoundView = views.errorViews.corsError;
264
- } else {
265
- if (this.props.error.status.toString() === 'corsError') {
266
- // eslint-disable-next-line no-console
267
- console.error(
268
- 'CORS ERROR in View component: ',
269
- JSON.stringify(this.props, null, 2),
270
- );
271
- this.notifySentry('CORS ERROR in View component');
272
- }
273
- FoundView = views.errorViews[this.props.error.status.toString()];
274
- }
275
- if (!FoundView) {
276
- FoundView = views.errorViews['404']; // default to 404
277
- }
278
- return (
279
- <div id="view">
280
- <FoundView {...this.props} />
281
- </div>
282
- );
283
- }
284
- if (!this.props.content) {
285
- return <span />;
286
- }
287
- const RenderedView =
288
- this.getViewByLayout() || this.getViewByType() || this.getViewDefault();
289
-
290
- return (
291
- <div id="view">
292
- <ContentMetadataTags content={this.props.content} />
293
- {/* Body class if displayName in component is set */}
294
- <BodyClass
295
- className={
296
- RenderedView.displayName
297
- ? `view-${this.cleanViewName(RenderedView.displayName)}`
298
- : null
299
- }
300
- />
301
- <RenderedView
302
- key={this.props.content['@id']}
303
- content={this.props.content}
304
- location={this.props.location}
305
- token={this.props.token}
306
- history={this.props.history}
307
- />
308
- {config.settings.showTags &&
309
- this.props.content.subjects &&
310
- this.props.content.subjects.length > 0 && (
311
- <Tags tags={this.props.content.subjects} />
312
- )}
313
- {/* Add opt-in social sharing if required, disabled by default */}
314
- {/* In the future this might be parameterized from the app config */}
315
- {/* <SocialSharing
316
- url={typeof window === 'undefined' ? '' : window.location.href}
317
- title={this.props.content.title}
318
- description={this.props.content.description || ''}
319
- /> */}
320
- {this.props.content.allow_discussion && (
321
- <Comments pathname={this.props.pathname} />
322
- )}
323
- {this.state.isClient && (
324
- <Portal node={document.getElementById('toolbar')}>
325
- <Toolbar pathname={this.props.pathname} inner={<span />} />
326
- </Portal>
327
- )}
328
- </div>
329
- );
330
- }
331
- }
332
-
333
- export default compose(
334
- injectIntl,
335
- connect(
336
- (state, props) => ({
337
- actions: state.actions.actions,
338
- token: state.userSession.token,
339
- content: state.content.data,
340
- error: state.content.get.error,
341
- apiError: state.apierror.error,
342
- connectionRefused: state.apierror.connectionRefused,
343
- pathname: props.location.pathname,
344
- versionId:
345
- qs.parse(props.location.search) &&
346
- qs.parse(props.location.search).version,
347
- }),
348
- {
349
- listActions,
350
- getContent,
351
- },
352
- ),
353
- )(View);
@@ -1,308 +0,0 @@
1
- /**
2
- * backport https://github.com/plone/volto/pull/4854
3
- *
4
- * View container.
5
- * @module components/theme/View/View
6
- */
7
-
8
- import React, { Component } from 'react';
9
- import PropTypes from 'prop-types';
10
- import { connect } from 'react-redux';
11
- import { compose } from 'redux';
12
- import { Redirect } from 'react-router-dom';
13
- import { Portal } from 'react-portal';
14
- import { injectIntl } from 'react-intl';
15
- import qs from 'query-string';
16
-
17
- import {
18
- ContentMetadataTags,
19
- Comments,
20
- Tags,
21
- Toolbar,
22
- } from '@plone/volto/components';
23
- import { listActions, getContent } from '@plone/volto/actions';
24
- import {
25
- BodyClass,
26
- getBaseUrl,
27
- flattenToAppURL,
28
- getLayoutFieldname,
29
- hasApiExpander,
30
- } from '@plone/volto/helpers';
31
-
32
- import config from '@plone/volto/registry';
33
-
34
- /**
35
- * View container class.
36
- * @class View
37
- * @extends Component
38
- */
39
- class View extends Component {
40
- /**
41
- * Property types.
42
- * @property {Object} propTypes Property types.
43
- * @static
44
- */
45
- static propTypes = {
46
- actions: PropTypes.shape({
47
- object: PropTypes.arrayOf(PropTypes.object),
48
- object_buttons: PropTypes.arrayOf(PropTypes.object),
49
- user: PropTypes.arrayOf(PropTypes.object),
50
- }),
51
- listActions: PropTypes.func.isRequired,
52
- /**
53
- * Action to get the content
54
- */
55
- getContent: PropTypes.func.isRequired,
56
- /**
57
- * Pathname of the object
58
- */
59
- pathname: PropTypes.string.isRequired,
60
- location: PropTypes.shape({
61
- search: PropTypes.string,
62
- pathname: PropTypes.string,
63
- }).isRequired,
64
- /**
65
- * Version id of the object
66
- */
67
- versionId: PropTypes.string,
68
- /**
69
- * Content of the object
70
- */
71
- content: PropTypes.shape({
72
- /**
73
- * Layout of the object
74
- */
75
- layout: PropTypes.string,
76
- /**
77
- * Allow discussion of the object
78
- */
79
- allow_discussion: PropTypes.bool,
80
- /**
81
- * Title of the object
82
- */
83
- title: PropTypes.string,
84
- /**
85
- * Description of the object
86
- */
87
- description: PropTypes.string,
88
- /**
89
- * Type of the object
90
- */
91
- '@type': PropTypes.string,
92
- /**
93
- * Subjects of the object
94
- */
95
- subjects: PropTypes.arrayOf(PropTypes.string),
96
- is_folderish: PropTypes.bool,
97
- }),
98
- error: PropTypes.shape({
99
- /**
100
- * Error type
101
- */
102
- status: PropTypes.number,
103
- }),
104
- };
105
-
106
- /**
107
- * Default properties.
108
- * @property {Object} defaultProps Default properties.
109
- * @static
110
- */
111
- static defaultProps = {
112
- actions: null,
113
- content: null,
114
- versionId: null,
115
- error: null,
116
- };
117
-
118
- state = {
119
- hasObjectButtons: null,
120
- isClient: false,
121
- };
122
-
123
- componentDidMount() {
124
- // Do not trigger the actions action if the expander is present
125
- if (!hasApiExpander('actions', getBaseUrl(this.props.pathname))) {
126
- this.props.listActions(getBaseUrl(this.props.pathname));
127
- }
128
- this.props.getContent(
129
- getBaseUrl(this.props.pathname),
130
- this.props.versionId,
131
- );
132
- this.setState({ isClient: true });
133
- }
134
-
135
- /**
136
- * Component will receive props
137
- * @method componentWillReceiveProps
138
- * @param {Object} nextProps Next properties
139
- * @returns {undefined}
140
- */
141
- UNSAFE_componentWillReceiveProps(nextProps) {
142
- if (nextProps.pathname !== this.props.pathname) {
143
- // Do not trigger the actions action if the expander is present
144
- if (!hasApiExpander('actions', getBaseUrl(nextProps.pathname))) {
145
- this.props.listActions(getBaseUrl(nextProps.pathname));
146
- }
147
- this.props.getContent(
148
- getBaseUrl(nextProps.pathname),
149
- this.props.versionId,
150
- );
151
- }
152
-
153
- if (nextProps.actions.object_buttons) {
154
- const objectButtons = nextProps.actions.object_buttons;
155
- this.setState({
156
- hasObjectButtons: !!objectButtons.length,
157
- });
158
- }
159
- }
160
-
161
- /**
162
- * Default fallback view
163
- * @method getViewDefault
164
- * @returns {string} Markup for component.
165
- */
166
- getViewDefault = () => config.views.defaultView;
167
-
168
- /**
169
- * Get view by content type
170
- * @method getViewByType
171
- * @returns {string} Markup for component.
172
- */
173
- getViewByType = () =>
174
- config.views.contentTypesViews[this.props.content['@type']] || null;
175
-
176
- /**
177
- * Get view by content layout property
178
- * @method getViewByLayout
179
- * @returns {string} Markup for component.
180
- */
181
- getViewByLayout = () =>
182
- config.views.layoutViews[
183
- this.props.content[getLayoutFieldname(this.props.content)]
184
- ] || null;
185
-
186
- /**
187
- * Cleans the component displayName (specially for connected components)
188
- * which have the Connect(componentDisplayName)
189
- * @method cleanViewName
190
- * @param {string} dirtyDisplayName The displayName
191
- * @returns {string} Clean displayName (no Connect(...)).
192
- */
193
- cleanViewName = (dirtyDisplayName) =>
194
- dirtyDisplayName
195
- .replace('Connect(', '')
196
- .replace('injectIntl(', '')
197
- .replace(')', '')
198
- .replace('connect(', '')
199
- .toLowerCase();
200
-
201
- /**
202
- * Render method.
203
- * @method render
204
- * @returns {string} Markup for the component.
205
- */
206
- render() {
207
- const { views } = config;
208
- const status = __SERVER__
209
- ? this.props.error?.status
210
- : this.props.error?.code;
211
- // Checking to see if it's a 3XX HTTP status code. error.status only works on the server
212
- if (['301', '302', '307', '308'].includes(status?.toString())) {
213
- const redirectUrl = __SERVER__
214
- ? this.props.error.response.headers.location
215
- : this.props.error.url;
216
- let redirect = flattenToAppURL(redirectUrl);
217
- // We can hit situations where we end up being redirected to an api route. We don't want that so lets remove ++api++.
218
- redirect = redirect.replace('/++api++', '');
219
- return <Redirect to={`${redirect}${this.props.location.search}`} />;
220
- } else if (this.props.error && !this.props.connectionRefused) {
221
- let FoundView;
222
- if (this.props.error.status === undefined) {
223
- // For some reason, while development and if CORS is in place and the
224
- // requested resource is 404, it returns undefined as status, then the
225
- // next statement will fail
226
- FoundView = views.errorViews.corsError;
227
- } else {
228
- FoundView = views.errorViews[this.props.error.status.toString()];
229
- }
230
- if (!FoundView) {
231
- FoundView = views.errorViews['404']; // default to 404
232
- }
233
- return (
234
- <div id="view">
235
- <FoundView {...this.props} />
236
- </div>
237
- );
238
- }
239
- if (!this.props.content) {
240
- return <span />;
241
- }
242
- const RenderedView =
243
- this.getViewByLayout() || this.getViewByType() || this.getViewDefault();
244
-
245
- return (
246
- <div id="view">
247
- <ContentMetadataTags content={this.props.content} />
248
- {/* Body class if displayName in component is set */}
249
- <BodyClass
250
- className={
251
- RenderedView.displayName
252
- ? `view-${this.cleanViewName(RenderedView.displayName)}`
253
- : null
254
- }
255
- />
256
- <RenderedView
257
- key={this.props.content['@id']}
258
- content={this.props.content}
259
- location={this.props.location}
260
- token={this.props.token}
261
- history={this.props.history}
262
- />
263
- {config.settings.showTags &&
264
- this.props.content.subjects &&
265
- this.props.content.subjects.length > 0 && (
266
- <Tags tags={this.props.content.subjects} />
267
- )}
268
- {/* Add opt-in social sharing if required, disabled by default */}
269
- {/* In the future this might be parameterized from the app config */}
270
- {/* <SocialSharing
271
- url={typeof window === 'undefined' ? '' : window.location.href}
272
- title={this.props.content.title}
273
- description={this.props.content.description || ''}
274
- /> */}
275
- {this.props.content.allow_discussion && (
276
- <Comments pathname={this.props.pathname} />
277
- )}
278
- {this.state.isClient && (
279
- <Portal node={document.getElementById('toolbar')}>
280
- <Toolbar pathname={this.props.pathname} inner={<span />} />
281
- </Portal>
282
- )}
283
- </div>
284
- );
285
- }
286
- }
287
-
288
- export default compose(
289
- injectIntl,
290
- connect(
291
- (state, props) => ({
292
- actions: state.actions.actions,
293
- token: state.userSession.token,
294
- content: state.content.data,
295
- error: state.content.get.error,
296
- apiError: state.apierror.error,
297
- connectionRefused: state.apierror.connectionRefused,
298
- pathname: props.location.pathname,
299
- versionId:
300
- qs.parse(props.location.search) &&
301
- qs.parse(props.location.search).version,
302
- }),
303
- {
304
- listActions,
305
- getContent,
306
- },
307
- ),
308
- )(View);
@@ -1,131 +0,0 @@
1
- /**
2
- * backport https://github.com/plone/volto/pull/4854
3
- *
4
- * Api helper.
5
- * @module helpers/Api
6
- */
7
-
8
- import superagent from 'superagent';
9
- import Cookies from 'universal-cookie';
10
- import config from '@plone/volto/registry';
11
- import { addHeadersFactory } from '@plone/volto/helpers/Proxy/Proxy';
12
- import { stripQuerystring } from '@plone/volto/helpers';
13
-
14
- const methods = ['get', 'post', 'put', 'patch', 'del'];
15
-
16
- /**
17
- * Format the url.
18
- * @function formatUrl
19
- * @param {string} path Path (or URL) to be formatted.
20
- * @returns {string} Formatted path.
21
- */
22
- function formatUrl(path) {
23
- const { settings } = config;
24
- const APISUFIX = settings.legacyTraverse ? '' : '/++api++';
25
-
26
- if (path.startsWith('http://') || path.startsWith('https://')) return path;
27
-
28
- const adjustedPath = path[0] !== '/' ? `/${path}` : path;
29
- let apiPath = '';
30
- if (settings.internalApiPath && __SERVER__) {
31
- apiPath = settings.internalApiPath;
32
- } else if (settings.apiPath) {
33
- apiPath = settings.apiPath;
34
- }
35
-
36
- return `${apiPath}${APISUFIX}${adjustedPath}`;
37
- }
38
-
39
- /**
40
- * Api class.
41
- * @class Api
42
- */
43
- class Api {
44
- /**
45
- * Constructor
46
- * @method constructor
47
- * @constructs Api
48
- */
49
- constructor(req) {
50
- const cookies = new Cookies();
51
-
52
- methods.forEach((method) => {
53
- this[method] = (
54
- path,
55
- { params, data, type, headers = {}, checkUrl = false } = {},
56
- ) => {
57
- let request;
58
- let promise = new Promise((resolve, reject) => {
59
- request = superagent[method](formatUrl(path));
60
-
61
- if (params) {
62
- request.query(params);
63
- }
64
-
65
- let authToken;
66
- if (req) {
67
- // We are in SSR
68
- authToken = req.universalCookies.get('auth_token');
69
- request.use(addHeadersFactory(req));
70
- } else {
71
- authToken = cookies.get('auth_token');
72
- }
73
- if (authToken) {
74
- request.set('Authorization', `Bearer ${authToken}`);
75
- }
76
-
77
- request.set('Accept', 'application/json');
78
-
79
- if (type) {
80
- request.type(type);
81
- }
82
-
83
- Object.keys(headers).forEach((key) => request.set(key, headers[key]));
84
-
85
- if (__SERVER__ && checkUrl && ['get', 'head'].includes(method)) {
86
- request.redirects(0);
87
- }
88
-
89
- if (data) {
90
- request.send(data);
91
- }
92
-
93
- request.end((err, response) => {
94
- if (
95
- checkUrl &&
96
- request.url &&
97
- request.xhr &&
98
- encodeURI(stripQuerystring(request.url)) !==
99
- stripQuerystring(request.xhr.responseURL)
100
- ) {
101
- if (request.xhr.responseURL?.length === 0) {
102
- return reject({
103
- code: 408,
104
- status: 408,
105
- url: request.xhr.responseURL,
106
- });
107
- }
108
- return reject({
109
- code: 301,
110
- url: request.xhr.responseURL,
111
- });
112
- }
113
-
114
- if (['301', '302', '307', '308'].includes(err?.status)) {
115
- return reject({
116
- code: err.status,
117
- url: err.response.headers.location,
118
- });
119
- }
120
-
121
- return err ? reject(err) : resolve(response.body || response.text);
122
- });
123
- });
124
- promise.request = request;
125
- return promise;
126
- };
127
- });
128
- }
129
- }
130
-
131
- export default Api;