@plone/volto 17.0.0-alpha.17 → 17.0.0-alpha.18
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/.yarn/install-state.gz +0 -0
- package/CHANGELOG.md +37 -0
- package/cypress/support/commands.js +17 -0
- package/locales/it/LC_MESSAGES/volto.po +1 -1
- package/locales/it.json +1 -1
- package/package.json +2 -2
- package/packages/volto-slate/package.json +1 -1
- package/packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx +21 -212
- package/packages/volto-slate/src/blocks/Table/schema.js +122 -0
- package/packages/volto-slate/src/editor/plugins/StyleMenu/utils.js +14 -5
- package/packages/volto-slate/src/utils/blocks.js +7 -0
- package/packages/volto-slate/src/widgets/RichTextWidget.jsx +15 -8
- package/src/components/manage/Blocks/Search/components/Facets.jsx +6 -2
- package/src/components/manage/Blocks/ToC/Schema.jsx +5 -1
- package/src/components/manage/Blocks/ToC/variations/HorizontalMenu.jsx +142 -8
- package/src/components/theme/Breadcrumbs/Breadcrumbs.jsx +52 -99
- package/src/components/theme/Breadcrumbs/Breadcrumbs.stories.jsx +14 -13
- package/src/components/theme/Comments/CommentEditModal.jsx +63 -115
- package/src/components/theme/ContactForm/ContactForm.jsx +108 -192
- package/src/components/theme/ContactForm/ContactForm.stories.jsx +1 -1
- package/src/components/theme/ContactForm/ContactForm.test.jsx +2 -3
- package/src/components/theme/Login/Login.jsx +1 -1
- package/src/components/theme/SearchWidget/SearchWidget.jsx +38 -98
- package/src/components/theme/View/LinkView.jsx +51 -79
- package/src/hooks/client/useClient.js +11 -0
- package/src/hooks/index.js +1 -0
- package/theme/themes/pastanaga/extras/main.less +2 -1
- package/theme/themes/pastanaga/extras/toc.less +29 -0
- package/news/4351.bugfix +0 -1
- package/news/4725.bugfix +0 -1
- package/news/4932.bugfix +0 -1
- package/news/4941.documentation +0 -1
- package/news/4951.breaking +0 -1
- package/news/4962.feature +0 -1
- package/news/4964.bugfix +0 -1
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
* Contact Form container.
|
|
3
|
-
* @module components/theme/ContactForm/ContactForm
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { Component } from 'react';
|
|
7
|
-
import PropTypes from 'prop-types';
|
|
8
|
-
import { Helmet } from '@plone/volto/helpers';
|
|
9
|
-
import { connect } from 'react-redux';
|
|
10
|
-
import { compose } from 'redux';
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
11
2
|
import { Portal } from 'react-portal';
|
|
12
3
|
import { Container, Message, Icon } from 'semantic-ui-react';
|
|
13
|
-
import { defineMessages,
|
|
14
|
-
import { Link,
|
|
4
|
+
import { defineMessages, useIntl } from 'react-intl';
|
|
5
|
+
import { Link, useHistory, useLocation } from 'react-router-dom';
|
|
15
6
|
import { toast } from 'react-toastify';
|
|
16
7
|
|
|
17
|
-
import { Form, Toolbar, Toast } from '@plone/volto/components';
|
|
18
8
|
import { emailNotification } from '@plone/volto/actions';
|
|
19
|
-
import {
|
|
9
|
+
import { useDispatch, useSelector } from 'react-redux';
|
|
10
|
+
import { Form, Toolbar, Toast } from '@plone/volto/components';
|
|
11
|
+
import { getBaseUrl, Helmet, usePrevious } from '@plone/volto/helpers';
|
|
12
|
+
import { useClient } from '@plone/volto/hooks';
|
|
20
13
|
|
|
21
14
|
const messages = defineMessages({
|
|
22
15
|
send: {
|
|
@@ -65,195 +58,118 @@ const messages = defineMessages({
|
|
|
65
58
|
},
|
|
66
59
|
});
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*/
|
|
73
|
-
export class ContactFormComponent extends Component {
|
|
74
|
-
/**
|
|
75
|
-
* Property types.
|
|
76
|
-
* @property {Object} propTypes Property types.
|
|
77
|
-
* @static
|
|
78
|
-
*/
|
|
79
|
-
static propTypes = {
|
|
80
|
-
emailNotification: PropTypes.func.isRequired,
|
|
81
|
-
error: PropTypes.shape({
|
|
82
|
-
message: PropTypes.string,
|
|
83
|
-
}),
|
|
84
|
-
loading: PropTypes.bool,
|
|
85
|
-
loaded: PropTypes.bool,
|
|
86
|
-
pathname: PropTypes.string.isRequired,
|
|
87
|
-
};
|
|
61
|
+
const useEmailNotification = () => {
|
|
62
|
+
const loading = useSelector((state) => state.emailNotification.loading);
|
|
63
|
+
const loaded = useSelector((state) => state.emailNotification.loaded);
|
|
64
|
+
const error = useSelector((state) => state.emailNotification.error);
|
|
88
65
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
66
|
+
return { loading, loaded, error };
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const ContactFormComponent = () => {
|
|
70
|
+
const history = useHistory();
|
|
71
|
+
const { pathname } = useLocation();
|
|
72
|
+
const dispatch = useDispatch();
|
|
73
|
+
const intl = useIntl();
|
|
74
|
+
const isClient = useClient();
|
|
99
75
|
|
|
100
|
-
|
|
101
|
-
* Constructor
|
|
102
|
-
* @method constructor
|
|
103
|
-
* @param {Object} props Component properties
|
|
104
|
-
* @constructs WysiwygEditor
|
|
105
|
-
*/
|
|
106
|
-
constructor(props) {
|
|
107
|
-
super(props);
|
|
108
|
-
this.onSubmit = this.onSubmit.bind(this);
|
|
109
|
-
this.onCancel = this.onCancel.bind(this);
|
|
110
|
-
this.state = { isClient: false };
|
|
111
|
-
}
|
|
76
|
+
const { loaded, loading, error } = useEmailNotification();
|
|
112
77
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* @returns {undefined}
|
|
118
|
-
*/
|
|
119
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
120
|
-
if (this.props.loading && nextProps.loaded) {
|
|
78
|
+
const prevloading = usePrevious(loading);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (prevloading && loaded) {
|
|
121
82
|
toast.success(
|
|
122
83
|
<Toast
|
|
123
84
|
success
|
|
124
|
-
title={
|
|
125
|
-
content={
|
|
85
|
+
title={intl.formatMessage(messages.success)}
|
|
86
|
+
content={intl.formatMessage(messages.messageSent)}
|
|
126
87
|
/>,
|
|
127
88
|
);
|
|
128
89
|
}
|
|
129
|
-
}
|
|
90
|
+
}, [intl, loaded, prevloading]);
|
|
130
91
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
*/
|
|
136
|
-
componentDidMount() {
|
|
137
|
-
this.setState({ isClient: true });
|
|
138
|
-
}
|
|
92
|
+
const onSubmit = (data) => {
|
|
93
|
+
const { from, message, name, subject } = data;
|
|
94
|
+
dispatch(emailNotification(from, message, name, subject));
|
|
95
|
+
};
|
|
139
96
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
* @param {Object} data Data object.
|
|
144
|
-
* @returns {undefined}
|
|
145
|
-
*/
|
|
146
|
-
onSubmit(data) {
|
|
147
|
-
this.props.emailNotification(
|
|
148
|
-
data.from,
|
|
149
|
-
data.message,
|
|
150
|
-
data.name,
|
|
151
|
-
data.subject,
|
|
152
|
-
);
|
|
153
|
-
}
|
|
97
|
+
const onCancel = useCallback(() => {
|
|
98
|
+
history.goBack();
|
|
99
|
+
}, [history]);
|
|
154
100
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
* @returns {string} Markup for the component.
|
|
167
|
-
*/
|
|
168
|
-
render() {
|
|
169
|
-
return (
|
|
170
|
-
<div id="contact-form">
|
|
171
|
-
<Container id="view">
|
|
172
|
-
<Helmet title={this.props.intl.formatMessage(messages.contactForm)} />
|
|
173
|
-
{this.props.error && (
|
|
174
|
-
<Message
|
|
175
|
-
icon="warning"
|
|
176
|
-
negative
|
|
177
|
-
attached
|
|
178
|
-
header={this.props.intl.formatMessage(messages.error)}
|
|
179
|
-
content={this.props.error.message}
|
|
180
|
-
/>
|
|
181
|
-
)}
|
|
182
|
-
<Form
|
|
183
|
-
onSubmit={this.onSubmit}
|
|
184
|
-
onCancel={this.onCancel}
|
|
185
|
-
formData={{ blocksLayoutFieldname: {} }}
|
|
186
|
-
submitLabel={this.props.intl.formatMessage(messages.send)}
|
|
187
|
-
resetAfterSubmit
|
|
188
|
-
title={this.props.intl.formatMessage(messages.contactForm)}
|
|
189
|
-
loading={this.props.loading}
|
|
190
|
-
schema={{
|
|
191
|
-
fieldsets: [
|
|
192
|
-
{
|
|
193
|
-
fields: ['name', 'from', 'subject', 'message'],
|
|
194
|
-
id: 'default',
|
|
195
|
-
title: this.props.intl.formatMessage(messages.default),
|
|
196
|
-
},
|
|
197
|
-
],
|
|
198
|
-
properties: {
|
|
199
|
-
name: {
|
|
200
|
-
title: this.props.intl.formatMessage(messages.name),
|
|
201
|
-
type: 'string',
|
|
202
|
-
},
|
|
203
|
-
from: {
|
|
204
|
-
title: this.props.intl.formatMessage(messages.from),
|
|
205
|
-
type: 'email',
|
|
206
|
-
},
|
|
207
|
-
subject: {
|
|
208
|
-
title: this.props.intl.formatMessage(messages.subject),
|
|
209
|
-
type: 'string',
|
|
210
|
-
},
|
|
211
|
-
message: {
|
|
212
|
-
title: this.props.intl.formatMessage(messages.message),
|
|
213
|
-
type: 'string',
|
|
214
|
-
widget: 'textarea',
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
required: ['from', 'message'],
|
|
218
|
-
}}
|
|
101
|
+
return (
|
|
102
|
+
<div id="contact-form">
|
|
103
|
+
<Container id="view">
|
|
104
|
+
<Helmet title={intl.formatMessage(messages.contactForm)} />
|
|
105
|
+
{error && (
|
|
106
|
+
<Message
|
|
107
|
+
icon="warning"
|
|
108
|
+
negative
|
|
109
|
+
attached
|
|
110
|
+
header={intl.formatMessage(messages.error)}
|
|
111
|
+
content={error.message}
|
|
219
112
|
/>
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
113
|
+
)}
|
|
114
|
+
<Form
|
|
115
|
+
onSubmit={onSubmit}
|
|
116
|
+
onCancel={onCancel}
|
|
117
|
+
formData={{ blocksLayoutFieldname: {} }}
|
|
118
|
+
submitLabel={intl.formatMessage(messages.send)}
|
|
119
|
+
resetAfterSubmit
|
|
120
|
+
title={intl.formatMessage(messages.contactForm)}
|
|
121
|
+
loading={loading}
|
|
122
|
+
schema={{
|
|
123
|
+
fieldsets: [
|
|
124
|
+
{
|
|
125
|
+
fields: ['name', 'from', 'subject', 'message'],
|
|
126
|
+
id: 'default',
|
|
127
|
+
title: intl.formatMessage(messages.default),
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
properties: {
|
|
131
|
+
name: {
|
|
132
|
+
title: intl.formatMessage(messages.name),
|
|
133
|
+
type: 'string',
|
|
134
|
+
},
|
|
135
|
+
from: {
|
|
136
|
+
title: intl.formatMessage(messages.from),
|
|
137
|
+
type: 'email',
|
|
138
|
+
},
|
|
139
|
+
subject: {
|
|
140
|
+
title: intl.formatMessage(messages.subject),
|
|
141
|
+
type: 'string',
|
|
142
|
+
},
|
|
143
|
+
message: {
|
|
144
|
+
title: intl.formatMessage(messages.message),
|
|
145
|
+
type: 'string',
|
|
146
|
+
widget: 'textarea',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
required: ['from', 'message'],
|
|
150
|
+
}}
|
|
151
|
+
/>
|
|
152
|
+
{isClient && (
|
|
153
|
+
<Portal node={document.getElementById('toolbar')}>
|
|
154
|
+
<Toolbar
|
|
155
|
+
pathname={pathname}
|
|
156
|
+
hideDefaultViewButtons
|
|
157
|
+
inner={
|
|
158
|
+
<Link to={`${getBaseUrl(pathname)}`} className="item">
|
|
159
|
+
<Icon
|
|
160
|
+
name="arrow left"
|
|
161
|
+
size="big"
|
|
162
|
+
color="blue"
|
|
163
|
+
title={intl.formatMessage(messages.back)}
|
|
164
|
+
/>
|
|
165
|
+
</Link>
|
|
166
|
+
}
|
|
167
|
+
/>
|
|
168
|
+
</Portal>
|
|
169
|
+
)}
|
|
170
|
+
</Container>
|
|
171
|
+
</div>
|
|
172
|
+
);
|
|
173
|
+
};
|
|
246
174
|
|
|
247
|
-
export default
|
|
248
|
-
withRouter,
|
|
249
|
-
injectIntl,
|
|
250
|
-
connect(
|
|
251
|
-
(state, props) => ({
|
|
252
|
-
loading: state.emailNotification.loading,
|
|
253
|
-
loaded: state.emailNotification.loaded,
|
|
254
|
-
error: state.emailNotification.error,
|
|
255
|
-
pathname: props.location.pathname,
|
|
256
|
-
}),
|
|
257
|
-
{ emailNotification },
|
|
258
|
-
),
|
|
259
|
-
)(ContactFormComponent);
|
|
175
|
+
export default ContactFormComponent;
|
|
@@ -10,7 +10,6 @@ jest.mock('react-portal', () => ({
|
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
12
|
const mockStore = configureStore();
|
|
13
|
-
|
|
14
13
|
describe('Contact form', () => {
|
|
15
14
|
it('renders a contact form', () => {
|
|
16
15
|
const store = mockStore({
|
|
@@ -29,7 +28,7 @@ describe('Contact form', () => {
|
|
|
29
28
|
const component = renderer.create(
|
|
30
29
|
<Provider store={store}>
|
|
31
30
|
<MemoryRouter>
|
|
32
|
-
<ContactForm
|
|
31
|
+
<ContactForm />
|
|
33
32
|
</MemoryRouter>
|
|
34
33
|
</Provider>,
|
|
35
34
|
);
|
|
@@ -56,7 +55,7 @@ describe('Contact form', () => {
|
|
|
56
55
|
const component = renderer.create(
|
|
57
56
|
<Provider store={store}>
|
|
58
57
|
<MemoryRouter>
|
|
59
|
-
<ContactForm
|
|
58
|
+
<ContactForm />
|
|
60
59
|
</MemoryRouter>
|
|
61
60
|
</Provider>,
|
|
62
61
|
);
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @module components/theme/SearchWidget/SearchWidget
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { Component } from 'react';
|
|
7
|
-
import { withRouter } from 'react-router-dom';
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useHistory } from 'react-router-dom';
|
|
8
3
|
import { Form, Input } from 'semantic-ui-react';
|
|
9
|
-
import {
|
|
10
|
-
import { PropTypes } from 'prop-types';
|
|
11
|
-
import { defineMessages, injectIntl } from 'react-intl';
|
|
4
|
+
import { defineMessages, useIntl } from 'react-intl';
|
|
12
5
|
|
|
13
6
|
import { Icon } from '@plone/volto/components';
|
|
14
7
|
import zoomSVG from '@plone/volto/icons/zoom.svg';
|
|
@@ -24,96 +17,43 @@ const messages = defineMessages({
|
|
|
24
17
|
},
|
|
25
18
|
});
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Property types.
|
|
35
|
-
* @property {Object} propTypes Property types.
|
|
36
|
-
* @static
|
|
37
|
-
*/
|
|
38
|
-
static propTypes = {
|
|
39
|
-
pathname: PropTypes.string,
|
|
20
|
+
const SearchWidget = (props) => {
|
|
21
|
+
const intl = useIntl();
|
|
22
|
+
const [text, setText] = useState('');
|
|
23
|
+
const history = useHistory();
|
|
24
|
+
const onChangeText = (event, { value }) => {
|
|
25
|
+
setText(value);
|
|
40
26
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* Constructor
|
|
44
|
-
* @method constructor
|
|
45
|
-
* @param {Object} props Component properties
|
|
46
|
-
* @constructs WysiwygEditor
|
|
47
|
-
*/
|
|
48
|
-
constructor(props) {
|
|
49
|
-
super(props);
|
|
50
|
-
this.onChangeText = this.onChangeText.bind(this);
|
|
51
|
-
this.onSubmit = this.onSubmit.bind(this);
|
|
52
|
-
this.state = {
|
|
53
|
-
text: '',
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* On change text
|
|
59
|
-
* @method onChangeText
|
|
60
|
-
* @param {object} event Event object.
|
|
61
|
-
* @param {string} value Text value.
|
|
62
|
-
* @returns {undefined}
|
|
63
|
-
*/
|
|
64
|
-
onChangeText(event, { value }) {
|
|
65
|
-
this.setState({
|
|
66
|
-
text: value,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Submit handler
|
|
72
|
-
* @method onSubmit
|
|
73
|
-
* @param {event} event Event object.
|
|
74
|
-
* @returns {undefined}
|
|
75
|
-
*/
|
|
76
|
-
onSubmit(event) {
|
|
27
|
+
const pathname = props.pathname;
|
|
28
|
+
const onSubmit = (event) => {
|
|
77
29
|
const path =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.props.history.push(
|
|
82
|
-
`/search?SearchableText=${encodeURIComponent(this.state.text)}${path}`,
|
|
83
|
-
);
|
|
30
|
+
pathname?.length > 0 ? `&path=${encodeURIComponent(pathname)}` : '';
|
|
31
|
+
|
|
32
|
+
history.push(`/search?SearchableText=${encodeURIComponent(text)}${path}`);
|
|
84
33
|
// reset input value
|
|
85
|
-
|
|
86
|
-
text: '',
|
|
87
|
-
});
|
|
34
|
+
setText('');
|
|
88
35
|
event.preventDefault();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Render method.
|
|
93
|
-
* @method render
|
|
94
|
-
* @returns {string} Markup for the component.
|
|
95
|
-
*/
|
|
96
|
-
render() {
|
|
97
|
-
return (
|
|
98
|
-
<Form action="/search" onSubmit={this.onSubmit}>
|
|
99
|
-
<Form.Field className="searchbox">
|
|
100
|
-
<Input
|
|
101
|
-
aria-label={this.props.intl.formatMessage(messages.search)}
|
|
102
|
-
onChange={this.onChangeText}
|
|
103
|
-
name="SearchableText"
|
|
104
|
-
value={this.state.text}
|
|
105
|
-
transparent
|
|
106
|
-
autoComplete="off"
|
|
107
|
-
placeholder={this.props.intl.formatMessage(messages.searchSite)}
|
|
108
|
-
title={this.props.intl.formatMessage(messages.search)}
|
|
109
|
-
/>
|
|
110
|
-
<button aria-label={this.props.intl.formatMessage(messages.search)}>
|
|
111
|
-
<Icon name={zoomSVG} size="18px" />
|
|
112
|
-
</button>
|
|
113
|
-
</Form.Field>
|
|
114
|
-
</Form>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
36
|
+
};
|
|
118
37
|
|
|
119
|
-
|
|
38
|
+
return (
|
|
39
|
+
<Form action="/search" onSubmit={onSubmit}>
|
|
40
|
+
<Form.Field className="searchbox">
|
|
41
|
+
<Input
|
|
42
|
+
aria-label={intl.formatMessage(messages.search)}
|
|
43
|
+
onChange={onChangeText}
|
|
44
|
+
name="SearchableText"
|
|
45
|
+
value={text}
|
|
46
|
+
transparent
|
|
47
|
+
autoComplete="off"
|
|
48
|
+
placeholder={intl.formatMessage(messages.searchSite)}
|
|
49
|
+
title={intl.formatMessage(messages.search)}
|
|
50
|
+
/>
|
|
51
|
+
<button aria-label={intl.formatMessage(messages.search)}>
|
|
52
|
+
<Icon name={zoomSVG} size="18px" />
|
|
53
|
+
</button>
|
|
54
|
+
</Form.Field>
|
|
55
|
+
</Form>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default SearchWidget;
|
|
@@ -1,95 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
* Link View.
|
|
3
|
-
* @module components/theme/View/LinkView
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { Component } from 'react';
|
|
1
|
+
import { useEffect } from 'react';
|
|
7
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import { useHistory } from 'react-router-dom';
|
|
8
4
|
import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers';
|
|
9
5
|
import { Container as SemanticContainer } from 'semantic-ui-react';
|
|
10
6
|
import { UniversalLink } from '@plone/volto/components';
|
|
11
7
|
import { FormattedMessage } from 'react-intl';
|
|
12
8
|
import config from '@plone/volto/registry';
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class LinkView extends Component {
|
|
20
|
-
/**
|
|
21
|
-
* Property types.
|
|
22
|
-
* @property {Object} propTypes Property types.
|
|
23
|
-
* @static
|
|
24
|
-
*/
|
|
25
|
-
static propTypes = {
|
|
26
|
-
content: PropTypes.shape({
|
|
27
|
-
title: PropTypes.string,
|
|
28
|
-
description: PropTypes.string,
|
|
29
|
-
remoteUrl: PropTypes.string,
|
|
30
|
-
}),
|
|
31
|
-
token: PropTypes.string,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Default properties.
|
|
36
|
-
* @property {Object} defaultProps Default properties.
|
|
37
|
-
* @static
|
|
38
|
-
*/
|
|
39
|
-
static defaultProps = {
|
|
40
|
-
content: null,
|
|
41
|
-
token: null,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
componentDidMount() {
|
|
45
|
-
if (!this.props.token) {
|
|
46
|
-
const { remoteUrl } = this.props.content;
|
|
10
|
+
const LinkView = ({ token, content }) => {
|
|
11
|
+
const history = useHistory();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!token) {
|
|
14
|
+
const { remoteUrl } = content;
|
|
47
15
|
if (isInternalURL(remoteUrl)) {
|
|
48
|
-
|
|
16
|
+
history.replace(flattenToAppURL(remoteUrl));
|
|
49
17
|
} else if (!__SERVER__) {
|
|
50
18
|
window.location.href = flattenToAppURL(remoteUrl);
|
|
51
19
|
}
|
|
52
20
|
}
|
|
53
|
-
}
|
|
21
|
+
}, [content, history, token]);
|
|
22
|
+
const { title, description, remoteUrl } = content;
|
|
23
|
+
const { openExternalLinkInNewTab } = config.settings;
|
|
24
|
+
const Container =
|
|
25
|
+
config.getComponent({ name: 'Container' }).component || SemanticContainer;
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Container id="page-document">
|
|
29
|
+
<h1 className="documentFirstHeading">{title}</h1>
|
|
30
|
+
{content.description && (
|
|
31
|
+
<p className="documentDescription">{description}</p>
|
|
32
|
+
)}
|
|
33
|
+
{remoteUrl && (
|
|
34
|
+
<p>
|
|
35
|
+
<FormattedMessage
|
|
36
|
+
id="The link address is:"
|
|
37
|
+
defaultMessage="The link address is:"
|
|
38
|
+
/>{' '}
|
|
39
|
+
<UniversalLink
|
|
40
|
+
href={remoteUrl}
|
|
41
|
+
openLinkInNewTab={
|
|
42
|
+
openExternalLinkInNewTab && !isInternalURL(remoteUrl)
|
|
43
|
+
}
|
|
44
|
+
>
|
|
45
|
+
{flattenToAppURL(remoteUrl)}
|
|
46
|
+
</UniversalLink>
|
|
47
|
+
</p>
|
|
48
|
+
)}
|
|
49
|
+
</Container>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const Container =
|
|
64
|
-
config.getComponent({ name: 'Container' }).component || SemanticContainer;
|
|
53
|
+
LinkView.propTypes = {
|
|
54
|
+
content: PropTypes.shape({
|
|
55
|
+
title: PropTypes.string,
|
|
56
|
+
description: PropTypes.string,
|
|
57
|
+
remoteUrl: PropTypes.string,
|
|
58
|
+
}),
|
|
59
|
+
token: PropTypes.string,
|
|
60
|
+
};
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
<p className="documentDescription">
|
|
71
|
-
{this.props.content.description}
|
|
72
|
-
</p>
|
|
73
|
-
)}
|
|
74
|
-
{remoteUrl && (
|
|
75
|
-
<p>
|
|
76
|
-
<FormattedMessage
|
|
77
|
-
id="The link address is:"
|
|
78
|
-
defaultMessage="The link address is:"
|
|
79
|
-
/>{' '}
|
|
80
|
-
<UniversalLink
|
|
81
|
-
href={remoteUrl}
|
|
82
|
-
openLinkInNewTab={
|
|
83
|
-
openExternalLinkInNewTab && !isInternalURL(remoteUrl)
|
|
84
|
-
}
|
|
85
|
-
>
|
|
86
|
-
{flattenToAppURL(remoteUrl)}
|
|
87
|
-
</UniversalLink>
|
|
88
|
-
</p>
|
|
89
|
-
)}
|
|
90
|
-
</Container>
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
62
|
+
LinkView.defaultProps = {
|
|
63
|
+
content: null,
|
|
64
|
+
token: null,
|
|
65
|
+
};
|
|
94
66
|
|
|
95
67
|
export default LinkView;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//useClient hook to replace repetitive delcaration in the components
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
export function useClient() {
|
|
5
|
+
const [isClient, setisClient] = useState(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
setisClient(true);
|
|
8
|
+
}, []);
|
|
9
|
+
|
|
10
|
+
return isClient;
|
|
11
|
+
}
|
package/src/hooks/index.js
CHANGED