@eeacms/volto-tableau 5.0.0 → 5.0.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.
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import cx from 'classnames';
3
+ import { Popup } from 'semantic-ui-react';
4
+ import {
5
+ serializeNodes,
6
+ serializeNodesToText,
7
+ } from '@plone/volto-slate/editor/render';
8
+ import { isArray } from 'lodash';
9
+
10
+ export const serializeText = (note) => {
11
+ if (!serializeNodesToText(note))
12
+ return <p>There are no notes set for this visualization</p>;
13
+ return isArray(note) ? serializeNodes(note) : note;
14
+ };
15
+
16
+ const FigureNote = ({ note = [] }) => {
17
+ const [expanded, setExpanded] = React.useState(false);
18
+
19
+ return (
20
+ <div className="tableau-note-container">
21
+ <Popup
22
+ position="bottom left"
23
+ popper={{ id: 'tableau-note-popup' }}
24
+ trigger={
25
+ <button className={cx('tableau-note-button', { expanded })}>
26
+ Note
27
+ </button>
28
+ }
29
+ on="click"
30
+ onClose={() => {
31
+ setExpanded(false);
32
+ }}
33
+ onOpen={() => {
34
+ setExpanded(true);
35
+ }}
36
+ >
37
+ <Popup.Content>{serializeText(note)}</Popup.Content>
38
+ </Popup>
39
+ </div>
40
+ );
41
+ };
42
+
43
+ export default FigureNote;
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import '@testing-library/jest-dom/extend-expect';
4
+
5
+ import FigureNote from './FigureNote';
6
+
7
+ window.URL.createObjectURL = jest.fn(() => 'test');
8
+
9
+ const slateEditor = require('@plone/volto-slate/editor/render');
10
+ slateEditor.serializeNodes = jest.fn();
11
+
12
+ jest.mock('@plone/volto-slate/editor/render', () => ({
13
+ serializeNodesToText: ({ note = [] }) => note,
14
+ }));
15
+
16
+ describe('FigureNote', () => {
17
+ const note = [];
18
+
19
+ it('should render the component', () => {
20
+ const { container } = render(<FigureNote note={note} />);
21
+ expect(
22
+ container.querySelector('.tableau-note-container'),
23
+ ).toBeInTheDocument();
24
+ });
25
+ });
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import cx from 'classnames';
3
+ import { UniversalLink } from '@plone/volto/components';
4
+
5
+ const Link = ({ children, ...props }) => {
6
+ if (props.href) {
7
+ return <UniversalLink {...props}>{children}</UniversalLink>;
8
+ }
9
+ return <span {...props}>{children}</span>;
10
+ };
11
+
12
+ const MoreInfoLink = ({ contentTypeLink }) => {
13
+ return (
14
+ <Link href={contentTypeLink}>
15
+ <button className={cx('tableau-more-info-button')}>
16
+ More info <i class="ri-external-link-line"></i>
17
+ </button>
18
+ </Link>
19
+ );
20
+ };
21
+
22
+ export default MoreInfoLink;
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import '@testing-library/jest-dom/extend-expect';
4
+
5
+ import MoreInfoLink from './MoreInfoLink';
6
+
7
+ window.URL.createObjectURL = jest.fn(() => 'test');
8
+
9
+ jest.mock('@plone/volto/components', () => ({
10
+ UniversalLink: ({ children }) => <div>{children}</div>,
11
+ }));
12
+
13
+ describe('MoreInfoLink', () => {
14
+ const contentTypeLink = '/tableau-content-type';
15
+
16
+ it('should render the component', () => {
17
+ const { container } = render(
18
+ <MoreInfoLink contentTypeLink={contentTypeLink} />,
19
+ );
20
+ expect(
21
+ container.querySelector('.tableau-more-info-button'),
22
+ ).toBeInTheDocument();
23
+ });
24
+ });
@@ -1,20 +1,68 @@
1
1
  import React from 'react';
2
- import { Icon } from '@plone/volto/components';
3
- import shareSVG from '@plone/volto/icons/share.svg';
2
+ import { Popup, Input, Button } from 'semantic-ui-react';
3
+ import { useCopyToClipboard } from '../../helpers.js';
4
+ import cx from 'classnames';
4
5
 
5
- const Share = ({ viz }) => {
6
- return (
7
- <div className="tableau-share-container">
8
- <button
9
- className="tableau-share-button"
10
- onClick={() => {
11
- viz.showShareDialog();
12
- }}
6
+ const Share = ({ contentTypeLink = '' }) => {
7
+ const [expanded, setExpanded] = React.useState(false);
8
+ const popupRef = React.useRef();
9
+
10
+ const CopyUrlButton = ({ className, url, buttonText }) => {
11
+ const [copyUrlStatus, copyUrl] = useCopyToClipboard(url);
12
+
13
+ if (copyUrlStatus === 'copied') {
14
+ buttonText = 'Copied!';
15
+ } else if (copyUrlStatus === 'failed') {
16
+ buttonText = 'Copy failed. Please try again.';
17
+ }
18
+
19
+ return (
20
+ <Button
21
+ primary
22
+ onClick={copyUrl}
23
+ className={cx('copy-button', className)}
13
24
  >
14
- <span>Share</span>
15
- <Icon name={shareSVG} size="24px" />
16
- </button>
17
- </div>
25
+ {buttonText}
26
+ </Button>
27
+ );
28
+ };
29
+
30
+ return (
31
+ <Popup
32
+ popper={{ id: 'tableau-share-popup' }}
33
+ trigger={
34
+ <div className="tableau-share-container">
35
+ <button className={cx('tableau-share-button', { expanded })}>
36
+ <span>Share</span>
37
+ <i class="ri-share-fill"></i>
38
+ </button>
39
+ </div>
40
+ }
41
+ position="bottom left"
42
+ on="click"
43
+ onClose={() => {
44
+ setExpanded(false);
45
+ }}
46
+ onOpen={() => {
47
+ setExpanded(true);
48
+ }}
49
+ ref={popupRef}
50
+ >
51
+ <div>
52
+ <span className="tableau-share-popup-text">Copy link</span>
53
+ <div className="tableau-share-popup-container">
54
+ <Input
55
+ className="tableau-share-link"
56
+ defaultValue={contentTypeLink}
57
+ />
58
+ <CopyUrlButton
59
+ className="tableau-copy-button"
60
+ url={contentTypeLink}
61
+ buttonText="Copy"
62
+ />
63
+ </div>
64
+ </div>
65
+ </Popup>
18
66
  );
19
67
  };
20
68
 
@@ -14,11 +14,12 @@ const Source = ({ source }) => {
14
14
  return (
15
15
  <>
16
16
  <Link className="embed-sources-param-title" href={source.link}>
17
- {source.title},{' '}
18
- <span className="embed-sources-param-description">
19
- {source.organisation}
20
- </span>
17
+ {source.title}
21
18
  </Link>
19
+ ,
20
+ <span className="embed-sources-param-description">
21
+ {source.organisation}
22
+ </span>
22
23
  </>
23
24
  );
24
25
  };
@@ -7,7 +7,7 @@ import Tableau from '@eeacms/volto-tableau/Tableau/Tableau';
7
7
 
8
8
  const VisualizationView = (props) => {
9
9
  const { content = {} } = props;
10
- const { tableau_visualization = {}, data_provenance = {} } = content;
10
+ const { tableau_visualization = {} } = content;
11
11
 
12
12
  return (
13
13
  <Container id="page-document">
@@ -17,11 +17,8 @@ const VisualizationView = (props) => {
17
17
  <Tableau
18
18
  data={{
19
19
  ...tableau_visualization,
20
- with_sources: true,
21
20
  with_download: true,
22
- with_share: true,
23
21
  }}
24
- sources={data_provenance.data || []}
25
22
  breakpoints={
26
23
  config.blocks.blocksConfig.embed_tableau_visualization.breakpoints
27
24
  }
@@ -7,11 +7,8 @@ export default function VisualizationViewWidget(props) {
7
7
  <Tableau
8
8
  data={{
9
9
  ...value,
10
- with_sources: true,
11
10
  with_download: true,
12
- with_share: true,
13
11
  }}
14
- sources={[]}
15
12
  breakpoints={
16
13
  config.blocks.blocksConfig.embed_tableau_visualization.breakpoints
17
14
  }
package/src/helpers.js CHANGED
@@ -1,3 +1,5 @@
1
+ import React from 'react';
2
+
1
3
  export const loadTableauScript = (callback, version) => {
2
4
  if (!__CLIENT__) return;
3
5
  const source = `https://public.tableau.com/javascripts/api/tableau-${version}.min.js`;
@@ -32,3 +34,25 @@ export const loadTableauScript = (callback, version) => {
32
34
  // https://public.tableau.com/javascripts/api/tableau-2.2.2.min.js
33
35
  // https://public.tableau.com/javascripts/api/tableau-2.1.2.min.js
34
36
  // https://public.tableau.com/javascripts/api/tableau-2.0.3.min.js
37
+
38
+ export const useCopyToClipboard = (text) => {
39
+ const [copyStatus, setCopyStatus] = React.useState('inactive');
40
+ const copy = React.useCallback(() => {
41
+ navigator.clipboard.writeText(text).then(
42
+ () => setCopyStatus('copied'),
43
+ () => setCopyStatus('failed'),
44
+ );
45
+ }, [text]);
46
+
47
+ React.useEffect(() => {
48
+ if (copyStatus === 'inactive') {
49
+ return;
50
+ }
51
+
52
+ const timeout = setTimeout(() => setCopyStatus('inactive'), 3000);
53
+
54
+ return () => clearTimeout(timeout);
55
+ }, [copyStatus]);
56
+
57
+ return [copyStatus, copy];
58
+ };
@@ -19,7 +19,6 @@
19
19
  .tableau-wrapper {
20
20
  padding: @tableauWrapperPadding;
21
21
  margin: @tableauWrapperMargin;
22
- background-color: @tableauWrapperBackground;
23
22
 
24
23
  .tableau-debug {
25
24
  margin: 0 auto 1rem auto;
@@ -29,10 +28,6 @@
29
28
  }
30
29
  }
31
30
 
32
- .tableau-info {
33
- margin: 0 auto;
34
- }
35
-
36
31
  .tableau {
37
32
  margin-bottom: 1rem;
38
33
 
@@ -118,25 +113,47 @@
118
113
 
119
114
  // ========= Sources ==========
120
115
 
121
- .tableau-wrapper .tableau-info {
116
+ .tableau-wrapper .visualization-info-container {
122
117
  display: flex;
118
+ flex-wrap: wrap;
123
119
  align-items: center;
124
-
125
- > * {
126
- padding: 0 0.5rem;
127
- border-collapse: collapse;
128
- }
120
+ justify-content: space-between;
121
+ gap: 1.2rem;
129
122
 
130
123
  > *:first-child {
131
- padding-left: 0;
124
+ margin-left: auto;
125
+
126
+ > *:not(:last-child) {
127
+ border-right: 1px solid @textColor;
128
+ }
132
129
  }
133
130
 
134
131
  > *:last-child {
135
- padding-right: 0;
132
+ justify-content: flex-end;
136
133
  }
137
134
 
138
- > *:not(:last-child) {
139
- border-right: 2px solid @textColor;
135
+ .visualization-info {
136
+ display: flex;
137
+ flex-grow: 0.5;
138
+ align-items: center;
139
+
140
+ > * {
141
+ padding: 0 0.5rem;
142
+ border-collapse: collapse;
143
+ }
144
+
145
+ > *:first-child {
146
+ padding-left: 0;
147
+ }
148
+
149
+ > *:last-child {
150
+ padding-right: 0;
151
+ margin-right: 0;
152
+
153
+ &.tableau-download-container {
154
+ margin-left: auto;
155
+ }
156
+ }
140
157
  }
141
158
  }
142
159
 
@@ -144,9 +161,52 @@
144
161
  cursor: pointer;
145
162
  }
146
163
 
164
+ #tableau-share-popup {
165
+ .ui.popup {
166
+ padding-right: 15px;
167
+ padding-left: 0;
168
+ }
169
+
170
+ .tableau-share-popup-text {
171
+ margin-left: 7px;
172
+ }
173
+ }
174
+
175
+ .tableau-share-popup-container {
176
+ display: flex;
177
+ justify-content: space-between;
178
+ gap: 1rem;
179
+
180
+ .tableau-share-link {
181
+ input {
182
+ padding-left: 7px !important;
183
+ border-left: 0 !important;
184
+
185
+ &:focus {
186
+ outline: 1px solid var(--focus-visible, #0083e0);
187
+ }
188
+ }
189
+ }
190
+
191
+ .tableau-copy-button {
192
+ max-width: 80px;
193
+ padding: 10px 17px !important;
194
+ border: 1px solid black !important;
195
+ margin: 0 !important;
196
+ background-color: #4472c4 !important;
197
+ border-radius: 7px !important;
198
+ }
199
+
200
+ @media screen and (max-width: @largestMobileScreen) {
201
+ flex-direction: column;
202
+ }
203
+ }
204
+
205
+ .tableau-note-button,
206
+ .tableau-more-info-button,
147
207
  .tableau-download-button,
148
- .tableau-share-button,
149
- .tableau-sources-button {
208
+ .tableau-sources-button,
209
+ .tableau-share-button {
150
210
  display: inline-flex;
151
211
  align-items: center;
152
212
  padding-bottom: 3px;
@@ -154,7 +214,6 @@
154
214
  background-color: transparent;
155
215
  color: @textColor;
156
216
  cursor: pointer;
157
- font-weight: bold;
158
217
 
159
218
  .icon {
160
219
  margin-left: 0.5rem;
@@ -171,24 +230,25 @@
171
230
  }
172
231
  }
173
232
 
233
+ .tableau-more-info-button,
234
+ .tableau-download-button,
235
+ .tableau-share-button {
236
+ gap: 0.25rem;
237
+
238
+ i {
239
+ margin-bottom: 1px;
240
+ }
241
+ }
242
+
243
+ #tableau-note-popup,
174
244
  #tableau-sources-popup,
175
245
  #tableau-download-popup {
176
246
  .ui.popup {
177
- min-width: 600px;
178
- background-color: #f9f9f9;
247
+ background-color: @grey-1;
179
248
  box-shadow: rgba(0, 0, 0, 0.15) 1.95px 1.95px 2.6px;
180
249
 
181
250
  &::before {
182
- background-color: #f9f9f9;
183
- }
184
-
185
- .sources-list > li,
186
- .sources-list > li > * {
187
- color: @textColor;
188
- }
189
-
190
- a:hover {
191
- color: @secondaryColor;
251
+ background-color: @grey-1;
192
252
  }
193
253
  }
194
254
 
@@ -198,24 +258,72 @@
198
258
  padding-inline-start: 0;
199
259
  }
200
260
 
201
- @media screen and (max-width: @largestMobileScreen) {
261
+ .embed-sources-param-description {
262
+ margin-left: 5px;
263
+ }
264
+
265
+ @media screen and (min-width: @largestMobileScreen) {
202
266
  .ui.popup {
203
- min-width: 300px;
267
+ max-width: 600px;
204
268
  }
205
269
  }
206
270
  }
207
271
 
208
272
  #tableau-download-popup {
209
- .ui.popup {
210
- min-width: 460px;
211
- text-align: center;
273
+ ul.no-bullets {
274
+ padding: 0;
275
+ margin: 0;
276
+ list-style-type: none;
277
+ }
278
+
279
+ .visualization-wrapper {
280
+ position: relative;
281
+
282
+ .visualization-info {
283
+ display: flex;
284
+ align-items: center;
285
+
286
+ > * {
287
+ padding: 0 0.5rem;
288
+ border-collapse: collapse;
289
+ }
290
+
291
+ > *:first-child {
292
+ padding-left: 0;
293
+ }
294
+
295
+ > *:last-child {
296
+ padding-right: 0;
297
+ margin-right: 0;
298
+
299
+ &.tableau-download-container {
300
+ margin-left: auto;
301
+ }
302
+ }
303
+
304
+ > *:not(:last-child) {
305
+ border-right: 2px solid @textColor;
306
+ }
307
+ }
308
+ }
309
+
310
+ .tableau-download-button.tableau-format-download {
311
+ padding: 0;
312
+ color: #679ad6;
313
+ font-weight: normal;
314
+
315
+ &:hover {
316
+ color: #164b7f;
317
+ }
212
318
  }
213
319
  }
214
320
 
215
321
  @media print {
216
322
  .tableau-download-container,
323
+ .tableau-note-container,
217
324
  .tableau-sources-container,
218
325
  .tableau-share-container,
326
+ #tableau-note-popup,
219
327
  #tableau-sources-popup {
220
328
  display: none;
221
329
  }
@@ -5,4 +5,6 @@
5
5
  @tableauIframePadding : 0;
6
6
  @tableauIframeMargin : 0 auto 1rem auto;
7
7
  @tableauIframeBorder : none;
8
- @tableauIframeBorderRadius : 0;
8
+ @tableauIframeBorderRadius : 0;
9
+
10
+ @grey-1 : #f9f9f9;
@@ -1 +0,0 @@
1
- module.exports = require('@plone/volto/babel');