@eeacms/volto-tableau 1.2.5 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -4,12 +4,18 @@ 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.3.0](https://github.com/eea/volto-tableau/compare/1.2.5...1.3.0) - 28 September 2022
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - refactor script set tableau [andreiggr - [`d78328e`](https://github.com/eea/volto-tableau/commit/d78328e74d67d685390ca0671a44a1bfe9b21e97)]
12
+ - Bump version [Miu Razvan - [`837f8a7`](https://github.com/eea/volto-tableau/commit/837f8a70257660253b70b818977693101d6576e9)]
13
+ - clear lint [andreiggr - [`69d83b8`](https://github.com/eea/volto-tableau/commit/69d83b806aa48a6a696e01b6e026de07e6a34dfe)]
7
14
  ### [1.2.5](https://github.com/eea/volto-tableau/compare/1.2.4...1.2.5) - 2 September 2022
8
15
 
9
16
  #### :hammer_and_wrench: Others
10
17
 
11
18
  - Use volto 16 alpha 14 [Miu Razvan - [`93641be`](https://github.com/eea/volto-tableau/commit/93641be4c2393f49008aff789400cf7c947949fd)]
12
- - Fix filter update [Miu Razvan - [`d613762`](https://github.com/eea/volto-tableau/commit/d613762734bbba2460ad8e8860d95197fc86786b)]
13
19
  - Revert volto-tableau group to common [Andrei Grigore - [`9d24c6d`](https://github.com/eea/volto-tableau/commit/9d24c6d2767fed6a840cddaee55dbd5cecb544b5)]
14
20
  - Tableaugroup typo fix [Andrei Grigore - [`b0b5378`](https://github.com/eea/volto-tableau/commit/b0b5378a437043120a96c9e5e8802584145daa22)]
15
21
  - Refs #142010 - Optimize Volto-addons gitflow pipelines [valentinab25 - [`d237e1c`](https://github.com/eea/volto-tableau/commit/d237e1c72817d7e68a3eb698563674d1514db24f)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-tableau",
3
- "version": "1.2.5",
3
+ "version": "1.3.0",
4
4
  "description": "@eeacms/volto-tableau: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -20,8 +20,7 @@
20
20
  "@eeacms/volto-resize-helper"
21
21
  ],
22
22
  "dependencies": {
23
- "@eeacms/volto-resize-helper": "^0.2.4",
24
- "tableau-api-js": "github:eea/tableau-api-js#1.1.1"
23
+ "@eeacms/volto-resize-helper": "^0.2.4"
25
24
  },
26
25
  "devDependencies": {
27
26
  "@cypress/code-coverage": "^3.9.5",
@@ -3,9 +3,9 @@ import { connect } from 'react-redux';
3
3
  import { compose } from 'redux';
4
4
  import { toast } from 'react-toastify';
5
5
  import { Toast } from '@plone/volto/components';
6
- import { getLatestTableauVersion } from 'tableau-api-js';
7
6
  import { setTableauApi } from '@eeacms/volto-tableau/actions';
8
7
  import cx from 'classnames';
8
+ import { isMyScriptLoaded, loadTableauScript } from '../helpers';
9
9
 
10
10
  const Tableau = (props) => {
11
11
  const ref = React.useRef(null);
@@ -23,7 +23,7 @@ const Tableau = (props) => {
23
23
  screen = {},
24
24
  setError = () => {},
25
25
  setLoaded = () => {},
26
- version = getLatestTableauVersion(),
26
+ version = '2.8.0',
27
27
  } = props;
28
28
  const {
29
29
  autoScale = false,
@@ -34,7 +34,9 @@ const Tableau = (props) => {
34
34
  } = data;
35
35
  const defaultUrl = data.url;
36
36
  const url = props.url || defaultUrl;
37
- const tableau = props.tableau[version];
37
+
38
+ //load tableau from script tag
39
+ const tableau = isMyScriptLoaded(version) && __CLIENT__ ? window.tableau : '';
38
40
 
39
41
  const onFilterChange = (filter) => {
40
42
  const newFilters = { ...filters.current };
@@ -159,6 +161,9 @@ const Tableau = (props) => {
159
161
  if (__CLIENT__ && !props.tableau[version]) {
160
162
  props.setTableauApi(version, props.mode);
161
163
  }
164
+ if (__CLIENT__) {
165
+ loadTableauScript(() => {}, version);
166
+ }
162
167
  /* eslint-disable-next-line */
163
168
  }, [version]);
164
169
 
@@ -197,22 +202,6 @@ const Tableau = (props) => {
197
202
  /* eslint-disable-next-line */
198
203
  }, [loaded, screen?.page?.width]);
199
204
 
200
- // React.useEffect(() => {
201
- // if (mounted.current && loaded && viz) {
202
- // const workbook = viz.getWorkbook();
203
- // if (extraOptions.device === 'desktop') {
204
- // workbook.activateSheetAsync(0);
205
- // } else if (extraOptions.device === 'tablet') {
206
- // workbook.activateSheetAsync(1);
207
- // } else {
208
- // workbook.activateSheetAsync(2);
209
- // }
210
- // console.log('HERE', workbook.getPublishedSheetsInfo());
211
- // addExtraFilters(extraOptions);
212
- // }
213
- // /* eslint-disable-next-line */
214
- // }, [JSON.stringify(extraOptions)]);
215
-
216
205
  return (
217
206
  <div id="tableau-wrap">
218
207
  <div id="tableau-outer">
@@ -11,7 +11,6 @@ const Edit = (props) => {
11
11
  return (
12
12
  <>
13
13
  <View {...props} mode="edit" />
14
-
15
14
  <SidebarPortal selected={props.selected}>
16
15
  <InlineForm
17
16
  schema={schema}
@@ -4,7 +4,6 @@ import { compose } from 'redux';
4
4
  import { withRouter } from 'react-router';
5
5
  import Tableau from '@eeacms/volto-tableau/Tableau/View';
6
6
  import config from '@plone/volto/registry';
7
- import { getLatestTableauVersion } from 'tableau-api-js';
8
7
  import qs from 'querystring';
9
8
  import '@eeacms/volto-tableau/less/tableau.less';
10
9
 
@@ -36,9 +35,7 @@ const View = (props) => {
36
35
  autoScale = false,
37
36
  } = data;
38
37
  const version =
39
- props.data.version ||
40
- config.settings.tableauVersion ||
41
- getLatestTableauVersion();
38
+ props.data.version || config.settings.tableauVersion || '2.8.0';
42
39
  const device = getDevice(config, screen.page?.width || Infinity);
43
40
  const breakpointUrl = breakpointUrls.filter(
44
41
  (breakpoint) => breakpoint.device === device,
@@ -1,5 +1,3 @@
1
- import { tableauVersions, getLatestTableauVersion } from 'tableau-api-js';
2
-
3
1
  const urlParametersSchema = {
4
2
  title: 'Parameter',
5
3
  fieldsets: [
@@ -72,9 +70,19 @@ export default (config) => ({
72
70
  title: 'Version',
73
71
  type: 'array',
74
72
  choices: [
75
- ...tableauVersions.map((version) => [version, `tableau-${version}`]),
73
+ ...[
74
+ '2.8.0',
75
+ '2.7.0',
76
+ '2.6.0',
77
+ '2.5.0',
78
+ '2.4.0',
79
+ '2.3.0',
80
+ '2.2.2',
81
+ '2.1.2',
82
+ '2.0.3',
83
+ ].map((version) => [version, `tableau-${version}`]),
76
84
  ],
77
- default: config.settings.tableauVersion || getLatestTableauVersion(),
85
+ default: config.settings.tableauVersion || '2.8.0',
78
86
  },
79
87
  url: {
80
88
  title: 'Url',
package/src/helpers.js ADDED
@@ -0,0 +1,33 @@
1
+ const loadTableauScript = (callback, version) => {
2
+ const existingScript = 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
+ );
9
+ }
10
+ if (!existingScript) {
11
+ const script = document.createElement('script');
12
+ script.src = `https://public.tableau.com/javascripts/api/tableau-${version}.min.js`;
13
+ script.id = `tableauJS`;
14
+ document.body.appendChild(script);
15
+ script.onload = () => {
16
+ if (callback) callback();
17
+ };
18
+ }
19
+ //callback, if needed
20
+ if (existingScript && callback) callback();
21
+ };
22
+
23
+ const isMyScriptLoaded = (id) => {
24
+ //check for loaded Tableau script in dom scripts
25
+ var scripts = document.getElementsByTagName('script');
26
+ for (var i = scripts.length; i--; ) {
27
+ // eslint-disable-next-line eqeqeq
28
+ if (scripts[i].id == `tableauJS`) return true;
29
+ }
30
+ return false;
31
+ };
32
+
33
+ export { loadTableauScript, isMyScriptLoaded };
package/src/index.js CHANGED
@@ -12,6 +12,11 @@ const applyConfig = (config) => {
12
12
  tableau: tableauStore,
13
13
  };
14
14
 
15
+ config.settings.allowed_cors_destinations = [
16
+ ...(config.settings.allowed_cors_destinations || []),
17
+ 'public.tableau.com',
18
+ ];
19
+
15
20
  config.settings.storeExtenders = [
16
21
  ...(config.settings.storeExtenders || []),
17
22
  tableauMiddleware,
package/src/middleware.js CHANGED
@@ -1,38 +1,36 @@
1
- import React from 'react';
2
- import { toast } from 'react-toastify';
3
- import { Toast } from '@plone/volto/components';
4
1
  import { SET_TABLEAU_API } from '@eeacms/volto-tableau/constants';
5
- import loadTableauApi from 'tableau-api-js';
6
2
 
3
+ //need to see if we need redux anymore for this
7
4
  export default (middlewares) => [
8
5
  (store) => (next) => (action) => {
9
6
  const state = store.getState();
10
- const { version = '', mode = 'view' } = action || {};
7
+ const { version = '' } = action || {};
11
8
 
12
9
  if (
13
10
  action.type === `${SET_TABLEAU_API}_PENDING` &&
14
11
  !state.tableau.loading[version]
15
12
  ) {
16
- loadTableauApi(version)
17
- .then((response) => {
18
- if (mode === 'edit') {
19
- toast.success(<Toast success title={response.message} />);
20
- }
21
- store.dispatch({
22
- type: `${SET_TABLEAU_API}_SUCCESS`,
23
- version,
24
- api: response.tableau,
25
- });
26
- })
27
- .catch((error) => {
28
- if (mode === 'edit') {
29
- toast.error(<Toast error title={error.message} />);
30
- }
31
- store.dispatch({
32
- type: `${SET_TABLEAU_API}_FAILED`,
33
- version,
34
- });
35
- });
13
+ // loadTableauScript(() => {}, version);
14
+ // fetchTableau(version)
15
+ // .then((response) => {
16
+ // if (mode === 'edit') {
17
+ // toast.success(<Toast success title={response.message} />);
18
+ // }
19
+ // store.dispatch({
20
+ // type: `${SET_TABLEAU_API}_SUCCESS`,
21
+ // version,
22
+ // api: response,
23
+ // });
24
+ // })
25
+ // .catch((error) => {
26
+ // if (mode === 'edit') {
27
+ // toast.error(<Toast error title={error.message} />);
28
+ // }
29
+ // store.dispatch({
30
+ // type: `${SET_TABLEAU_API}_FAILED`,
31
+ // version,
32
+ // });
33
+ // });
36
34
  }
37
35
 
38
36
  return next(action);
package/src/store.js CHANGED
@@ -34,7 +34,6 @@ export default function tableau(state = initialState, action = {}) {
34
34
  loading[action.version] = false;
35
35
  loaded[action.version] = true;
36
36
  errors[action.version] = false;
37
-
38
37
  return {
39
38
  ...state,
40
39
  [action.version]: action.api,