Skip to content

Commit

Permalink
importmap for versions of tableau
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiggr committed Jan 10, 2023
1 parent ac2158d commit 4e03cb2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/Tableau/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const Tableau = (props) => {
loaded = false,
mode = 'view',
screen = {},
setError = () => {},
setLoaded = () => {},
setError = () => { },
setLoaded = () => { },
version = '2.8.0',
} = props;
const {
Expand All @@ -35,8 +35,21 @@ const Tableau = (props) => {
const defaultUrl = data.url;
const url = props.url || defaultUrl;

const setTableauScript = (version) => {
switch (version) {
case '2.8.0':
console.log('Loading Tableau 2.8.0');
//import { tableau as tableau280 } from "tableau280"; && return tableau280
break;
default:
console.log(`Sorry, we don't support ${version} yet.`);
}
}


//load tableau from script tag
const tableau = isMyScriptLoaded(version) && __CLIENT__ ? window.tableau : '';
//TODO: if using an importmap then there would be tableau1, tableau2, etc and ^^ would need a switch for each version. This way, the scripts needed are there, loaded dinamicaly

const onFilterChange = (filter) => {
const newFilters = { ...filters.current };
Expand Down Expand Up @@ -162,7 +175,7 @@ const Tableau = (props) => {
props.setTableauApi(version, props.mode);
}
if (__CLIENT__) {
loadTableauScript(() => {}, version);
loadTableauScript(() => { }, version);
}
/* eslint-disable-next-line */
}, [version]);
Expand Down
14 changes: 13 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ const loadTableauScript = (callback, version) => {
}
//callback, if needed
if (existingScript && callback) callback();

//TODO: instead of replacing the tableau script
// <script type="importmap">
// {
// "imports": {
// "tableau1": "https://example.com/shapes/tableau1.js",
// "tableau2": "https://example.com/shapes/tableau2.js",
// "tableau3": "https://example.com/shapes/tableau3.js",
// }
// }
// </script>
//try creating an importmap script with each different tableau version https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#importing_modules_with_importmap
};

const isMyScriptLoaded = (id) => {
//check for loaded Tableau script in dom scripts
var scripts = document.getElementsByTagName('script');
for (var i = scripts.length; i--; ) {
for (var i = scripts.length; i--;) {
// eslint-disable-next-line eqeqeq
if (scripts[i].id == `tableauJS`) return true;
}
Expand Down

0 comments on commit 4e03cb2

Please sign in to comment.