@eeacms/volto-tableau 3.0.8 → 4.1.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +20 -7
  2. package/Jenkinsfile +2 -0
  3. package/jest-addon.config.js +2 -2
  4. package/package.json +1 -1
  5. package/src/{TableauBlock → Blocks/EmbedTableauVisualization}/Edit.jsx +7 -7
  6. package/src/Blocks/EmbedTableauVisualization/View.jsx +66 -0
  7. package/src/Blocks/EmbedTableauVisualization/index.js +30 -0
  8. package/src/Blocks/{EmbedEEATableauBlock → EmbedTableauVisualization}/schema.js +32 -13
  9. package/src/Blocks/TableauBlock/Edit.jsx +41 -0
  10. package/src/Blocks/TableauBlock/View.jsx +101 -0
  11. package/src/Blocks/TableauBlock/index.js +30 -0
  12. package/src/Blocks/TableauBlock/schema.js +224 -0
  13. package/src/Blocks/index.js +9 -0
  14. package/src/Tableau/Tableau.jsx +430 -0
  15. package/src/Tableau/helpers.js +41 -0
  16. package/src/Utils/Download/Download.jsx +72 -0
  17. package/src/Utils/JsonCodeSnippet/JsonCodeSnippet.jsx +48 -0
  18. package/src/Utils/Share/Share.jsx +21 -0
  19. package/src/Utils/Sources/Sources.jsx +66 -0
  20. package/src/Views/VisualizationView.jsx +18 -32
  21. package/src/Widgets/VisualizationWidget.jsx +92 -122
  22. package/src/Widgets/schema.js +88 -115
  23. package/src/helpers.js +15 -34
  24. package/src/hooks.js +18 -0
  25. package/src/icons/download.svg +5 -0
  26. package/src/index.js +4 -66
  27. package/src/less/tableau.less +172 -70
  28. package/src/less/tableau.variables +7 -13
  29. package/src/Blocks/EmbedEEATableauBlock/Edit.jsx +0 -56
  30. package/src/Blocks/EmbedEEATableauBlock/View.jsx +0 -74
  31. package/src/ConnectedTableau/ConnectedTableau.jsx +0 -29
  32. package/src/CustomWidgets/UrlParamsWidget.jsx +0 -29
  33. package/src/DownloadExtras/TableauDownload.jsx +0 -124
  34. package/src/DownloadExtras/TableauFullscreen.jsx +0 -78
  35. package/src/DownloadExtras/TableauShare.jsx +0 -81
  36. package/src/DownloadExtras/style.less +0 -152
  37. package/src/Sources/Sources.jsx +0 -50
  38. package/src/Sources/index.js +0 -3
  39. package/src/Sources/style.css +0 -7
  40. package/src/Tableau/View.jsx +0 -254
  41. package/src/TableauBlock/View.jsx +0 -109
  42. package/src/TableauBlock/schema.js +0 -124
  43. package/src/Widgets/style.less +0 -8
  44. package/src/actions.js +0 -9
  45. package/src/constants.js +0 -1
  46. package/src/downloadHelpers/downloadHelpers.js +0 -25
  47. package/src/middleware.js +0 -39
  48. package/src/store.js +0 -72
@@ -1,90 +1,36 @@
1
- const generalSchema = {
2
- title: 'General',
3
-
4
- fieldsets: [
5
- {
6
- id: 'general',
7
- title: 'General',
8
- fields: ['url'],
9
- },
10
- ],
11
-
12
- properties: {
13
- url: {
14
- title: 'Url',
15
- type: 'textarea',
16
- },
17
- },
18
- required: ['url'],
19
- };
20
-
21
- const optionsSchema = {
22
- title: 'Options',
1
+ import {
2
+ getSheetnamesChoices,
3
+ canChangeVizData,
4
+ } from '@eeacms/volto-tableau/Tableau/helpers';
23
5
 
6
+ const urlParametersSchema = {
7
+ title: 'Parameter',
24
8
  fieldsets: [
25
- {
26
- id: 'options',
27
- title: 'Options',
28
- fields: [
29
- 'sheetname',
30
- 'hideTabs',
31
- 'hideToolbar',
32
- 'autoScale',
33
- 'toolbarPosition',
34
- ],
35
- },
9
+ { id: 'default', title: 'Default', fields: ['field', 'urlParam'] },
36
10
  ],
37
-
38
11
  properties: {
39
- sheetname: {
40
- title: 'Sheetname',
12
+ field: {
13
+ title: 'Tableau fieldname',
41
14
  type: 'text',
42
15
  },
43
- hideTabs: {
44
- title: 'Hide tabs',
45
- type: 'boolean',
46
- default: false,
47
- },
48
- hideToolbar: {
49
- title: 'Hide toolbar',
50
- type: 'boolean',
51
- default: false,
52
- },
53
- autoScale: {
54
- title: 'Auto scale',
55
- type: 'boolean',
56
- default: false,
57
- description: 'Scale down tableau according to width',
58
- },
59
- toolbarPosition: {
60
- title: 'Toolbar position',
61
- type: 'array',
62
- choices: [
63
- ['Top', 'Top'],
64
- ['Bottom', 'Bottom'],
65
- ],
66
- default: 'Top',
16
+ urlParam: {
17
+ title: 'URL param',
18
+ type: 'text',
67
19
  },
68
20
  },
69
21
  required: [],
70
22
  };
71
23
 
72
- const urlParametersSchema = {
24
+ const staticParameters = {
73
25
  title: 'Parameter',
74
- fieldsets: [
75
- {
76
- id: 'default',
77
- title: 'Default',
78
- fields: ['field', 'urlParam'],
79
- },
80
- ],
26
+ fieldsets: [{ id: 'default', title: 'Default', fields: ['field', 'value'] }],
81
27
  properties: {
82
28
  field: {
83
29
  title: 'Tableau fieldname',
84
30
  type: 'text',
85
31
  },
86
- urlParam: {
87
- title: 'URL param',
32
+ value: {
33
+ title: 'Value',
88
34
  type: 'text',
89
35
  },
90
36
  },
@@ -100,7 +46,6 @@ const breakpointUrlSchema = (config) => {
100
46
  properties: {
101
47
  device: {
102
48
  title: 'Device',
103
- type: 'array',
104
49
  choices: Object.keys(breakpoints).map((breakpoint) => [
105
50
  breakpoint,
106
51
  breakpoint,
@@ -115,70 +60,98 @@ const breakpointUrlSchema = (config) => {
115
60
  };
116
61
  };
117
62
 
118
- const extraOptionsSchema = (config) => {
119
- return {
120
- title: 'Extra Options',
63
+ export default (config, viz, vizState) => {
64
+ const isDisabled = !canChangeVizData(viz, vizState);
121
65
 
66
+ return {
67
+ title: 'Tableau',
122
68
  fieldsets: [
123
69
  {
124
70
  id: 'default',
125
- title: 'Extra Options Data',
126
- fields: ['urlParameters', 'availableFields', 'breakpointUrls'],
71
+ title: 'Default',
72
+ fields: ['url'],
73
+ },
74
+ {
75
+ id: 'options',
76
+ title: 'Options',
77
+ fields: [
78
+ 'sheetname',
79
+ 'hideTabs',
80
+ 'hideToolbar',
81
+ 'autoScale',
82
+ 'toolbarPosition',
83
+ ],
84
+ },
85
+ {
86
+ id: 'extra_options',
87
+ title: 'Extra options',
88
+ fields: ['urlParameters', 'staticParameters', 'breakpointUrls'],
127
89
  },
128
90
  ],
129
-
130
91
  properties: {
92
+ url: {
93
+ title: 'Url',
94
+ widget: 'textarea',
95
+ isDisabled,
96
+ },
97
+ sheetname: {
98
+ title: 'Sheetname',
99
+ choices: getSheetnamesChoices(viz),
100
+ isDisabled,
101
+ },
102
+ hideTabs: {
103
+ title: 'Hide tabs',
104
+ type: 'boolean',
105
+ isDisabled,
106
+ },
107
+ hideToolbar: {
108
+ title: 'Hide toolbar',
109
+ type: 'boolean',
110
+ isDisabled,
111
+ },
112
+ autoScale: {
113
+ title: 'Auto scale',
114
+ type: 'boolean',
115
+ description: 'Scale down tableau according to width',
116
+ isDisabled,
117
+ },
118
+ toolbarPosition: {
119
+ title: 'Toolbar position',
120
+ choices: [
121
+ ['Top', 'Top'],
122
+ ['Bottom', 'Bottom'],
123
+ ],
124
+ default: 'Top',
125
+ isDisabled,
126
+ },
131
127
  urlParameters: {
132
128
  title: 'URL parameters',
133
129
  widget: 'object_list',
134
130
  schema: urlParametersSchema,
135
131
  description: 'Set a list of url parameters to filter the tableau',
132
+ isDisabled,
136
133
  },
137
- availableFields: {
138
- title: 'Available Fields:',
139
- widget: 'url_params_widget',
134
+ staticParameters: {
135
+ title: 'Static parameters',
136
+ widget: 'object_list',
137
+ schema: staticParameters,
138
+ description: (
139
+ <>
140
+ Set a list of static parameters.
141
+ <br />
142
+ <b>NOTE: You need to trigger a refresh for this to take effect</b>
143
+ </>
144
+ ),
145
+ isDisabled,
140
146
  },
141
147
  breakpointUrls: {
142
148
  title: 'Breakpoint urls',
143
149
  widget: 'object_list',
144
150
  schema: breakpointUrlSchema(config),
145
151
  description: 'Set different vizualization for specific breakpoint',
152
+ isDisabled,
146
153
  },
147
154
  },
148
- required: [],
149
- };
150
- };
151
-
152
- export default (config) => {
153
- return {
154
- title: 'Tableau Editor',
155
- fieldsets: [
156
- {
157
- id: 'default',
158
- title: 'Tableau Editor Sections',
159
- fields: ['tableau_data'],
160
- },
161
- ],
162
- properties: {
163
- tableau_data: {
164
- title: 'Panels',
165
- widget: 'object_types_widget',
166
- schemas: [
167
- {
168
- id: 'general',
169
- schema: generalSchema,
170
- },
171
- {
172
- id: 'options',
173
- schema: optionsSchema,
174
- },
175
- {
176
- id: 'extraOptions',
177
- schema: extraOptionsSchema(config),
178
- },
179
- ],
180
- },
181
- },
182
- required: [],
155
+ required: ['url'],
183
156
  };
184
157
  };
package/src/helpers.js CHANGED
@@ -1,47 +1,28 @@
1
- const loadTableauScript = (callback, version) => {
2
- const existingScript = __CLIENT__ && document.getElementById(`tableauJS`);
3
- //replace script loaded on each version change
4
- if (existingScript) {
5
- existingScript.setAttribute(
6
- 'src',
7
- `https://public.tableau.com/javascripts/api/tableau-${version}.min.js`,
8
- );
1
+ export const loadTableauScript = (callback, version) => {
2
+ if (!__CLIENT__) return;
3
+ const source = `https://public.tableau.com/javascripts/api/tableau-${version}.min.js`;
4
+ const existingScript = document.getElementById(`tableauJS-${version}`);
5
+ const existingScriptSource =
6
+ existingScript && existingScript.getAttribute('src');
7
+ // Replace script loaded on each version change
8
+ if (existingScript && existingScriptSource !== source) {
9
+ existingScript.setAttribute('src', source);
9
10
  }
10
- if (!existingScript && __CLIENT__) {
11
+ if (!existingScript) {
11
12
  const script = document.createElement('script');
12
- script.src = `https://public.tableau.com/javascripts/api/tableau-${version}.min.js`;
13
- script.id = `tableauJS`;
13
+ script.src = source;
14
+ script.id = `tableauJS-${version}`;
14
15
  document.body.appendChild(script);
15
16
  script.onload = () => {
17
+ window[`tableau_${version}`] = window.tableau;
16
18
  if (callback) callback();
17
19
  };
18
20
  }
19
- //callback, if needed
21
+ // Trigger callback
20
22
  if (existingScript && callback) callback();
21
-
22
- const tableau = isMyScriptLoaded(version) && __CLIENT__ ? window.tableau : '';
23
- return tableau;
24
23
  };
25
24
 
26
- const isMyScriptLoaded = (version) => {
27
- //check for loaded Tableau script in dom scripts
28
- var scripts = __CLIENT__ && document.getElementsByTagName('script');
29
- if (scripts) {
30
- for (var i = scripts.length; i--; ) {
31
- // eslint-disable-next-line eqeqeq
32
- if (
33
- scripts[i].src ===
34
- `https://public.tableau.com/javascripts/api/tableau-${version}.min.js`
35
- )
36
- return true;
37
- }
38
- }
39
- return false;
40
- };
41
-
42
- export { loadTableauScript, isMyScriptLoaded };
43
-
44
- //script url for each version. In case you might need to add them in the load balancer
25
+ // Script url for each version. In case you might need to add them in the load balancer
45
26
  // https://public.tableau.com/javascripts/api/tableau-2.8.0.min.js
46
27
  // https://public.tableau.com/javascripts/api/tableau-2.7.0.min.js
47
28
  // https://public.tableau.com/javascripts/api/tableau-2.6.0.min.js
package/src/hooks.js ADDED
@@ -0,0 +1,18 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { loadTableauScript } from './helpers';
3
+
4
+ export const useTableau = (version) => {
5
+ const [tableau, setTableau] = useState();
6
+
7
+ useEffect(() => {
8
+ loadTableauScript(() => {
9
+ if (window[`tableau_${version}`]) {
10
+ setTableau(window[`tableau_${version}`]);
11
+ } else {
12
+ setTableau(undefined);
13
+ }
14
+ }, version);
15
+ }, [version]);
16
+
17
+ return tableau;
18
+ };
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
2
+ <path
3
+ d="M4 19H20V12H22V20C22 20.5523 21.5523 21 21 21H3C2.44772 21 2 20.5523 2 20V12H4V19ZM14 9H19L12 16L5 9H10V3H14V9Z">
4
+ </path>
5
+ </svg>
package/src/index.js CHANGED
@@ -1,81 +1,19 @@
1
- import sliderSVG from '@plone/volto/icons/slider.svg';
2
- import TableauEdit from './TableauBlock/Edit';
3
- import TableauView from './TableauBlock/View';
4
- import EmbedTableauView from './Blocks/EmbedEEATableauBlock/View';
5
- import EmbedTableauEdit from './Blocks/EmbedEEATableauBlock/Edit';
1
+ import installBlocks from './Blocks';
6
2
  import { VisualizationView } from './Views';
7
3
  import { VisualizationWidget } from './Widgets';
8
- import UrlParamsWidget from './CustomWidgets/UrlParamsWidget';
9
-
10
- import tableauStore from './store';
11
-
12
- import tableauMiddleware from './middleware';
13
4
 
14
5
  const applyConfig = (config) => {
15
- config.addonReducers = {
16
- ...config.addonReducers,
17
- tableau: tableauStore,
18
- };
19
-
20
6
  config.settings.allowed_cors_destinations = [
21
7
  ...(config.settings.allowed_cors_destinations || []),
22
8
  'public.tableau.com',
23
9
  ];
24
10
 
25
- config.settings.storeExtenders = [
26
- ...(config.settings.storeExtenders || []),
27
- tableauMiddleware,
28
- ];
29
-
30
- config.blocks.blocksConfig.tableau_block = {
31
- id: 'tableau_block',
32
- title: 'Tableau',
33
- icon: sliderSVG,
34
- group: 'common',
35
- edit: TableauEdit,
36
- view: TableauView,
37
- restricted: false,
38
- mostUsed: false,
39
- sidebarTab: 1,
40
- blocks: {},
41
- security: {
42
- addPermission: [],
43
- view: [],
44
- },
45
- breakpoints: {
46
- desktop: [Infinity, 982],
47
- tablet: [981, 768],
48
- mobile: [767, 0],
49
- },
50
- };
51
-
52
- config.blocks.blocksConfig.embed_eea_tableau_block = {
53
- id: 'embed_eea_tableau_block',
54
- title: 'Embed EEA Tableau',
55
- icon: sliderSVG,
56
- group: 'common',
57
- edit: EmbedTableauEdit,
58
- view: EmbedTableauView,
59
- restricted: false,
60
- mostUsed: false,
61
- sidebarTab: 1,
62
- blocks: {},
63
- security: {
64
- addPermission: [],
65
- view: [],
66
- },
67
- breakpoints: {
68
- desktop: [Infinity, 982],
69
- tablet: [981, 768],
70
- mobile: [767, 0],
71
- },
72
- };
11
+ config.settings.storeExtenders = [...(config.settings.storeExtenders || [])];
73
12
 
74
13
  config.views.contentTypesViews.tableau_visualization = VisualizationView;
75
- config.widgets.id.tableau_visualization_data = VisualizationWidget;
76
- config.widgets.widget.url_params_widget = UrlParamsWidget;
14
+ config.widgets.id.tableau_visualization = VisualizationWidget;
77
15
 
78
- return config;
16
+ return [installBlocks].reduce((acc, apply) => apply(acc), config);
79
17
  };
80
18
 
81
19
  export default applyConfig;