@eeacms/volto-tableau 4.0.0 → 4.1.1

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.
@@ -8,10 +8,29 @@ import getSchema from './schema';
8
8
  import '@eeacms/volto-tableau/less/tableau.less';
9
9
 
10
10
  const VisualizationWidget = (props) => {
11
+ const viz = React.useRef();
12
+ const [vizState, setVizState] = React.useState({
13
+ loaded: false,
14
+ loading: false,
15
+ error: null,
16
+ });
11
17
  const [open, setOpen] = React.useState(false);
12
- const [schema] = React.useState(getSchema(config));
13
18
  const [value, setValue] = React.useState(props.value);
14
19
 
20
+ const schema = React.useMemo(() => getSchema(config, viz.current, vizState), [
21
+ vizState,
22
+ ]);
23
+
24
+ const extraOptions = React.useMemo(() => {
25
+ const options = {};
26
+ (value.staticParameters || []).forEach((parameter) => {
27
+ if (parameter.field) {
28
+ options[parameter.field] = parameter.value;
29
+ }
30
+ });
31
+ return options;
32
+ }, [value]);
33
+
15
34
  const handleApplyChanges = () => {
16
35
  props.onChange(props.id, value);
17
36
  setOpen(false);
@@ -52,12 +71,18 @@ const VisualizationWidget = (props) => {
52
71
  className="tableau-visualization-column"
53
72
  >
54
73
  <Tableau
74
+ ref={viz}
55
75
  data={value}
76
+ mode="edit"
77
+ breakpoints={
78
+ config.blocks.blocksConfig.embed_tableau_visualization
79
+ .breakpoints
80
+ }
81
+ extraOptions={extraOptions}
82
+ setVizState={setVizState}
56
83
  onChangeBlock={(_, newValue) => {
57
84
  setValue(newValue);
58
85
  }}
59
- mode="edit"
60
- noSizeUpdate
61
86
  />
62
87
  </Grid.Column>
63
88
  </Grid>
@@ -87,7 +112,16 @@ const VisualizationWidget = (props) => {
87
112
  Open Tableau Editor
88
113
  </Button>
89
114
  </div>
90
- <Tableau data={props.value} noSizeUpdate />
115
+ <Tableau
116
+ data={{
117
+ ...props.value,
118
+ autoScale: true,
119
+ }}
120
+ breakpoints={
121
+ config.blocks.blocksConfig.embed_tableau_visualization.breakpoints
122
+ }
123
+ extraOptions={extraOptions}
124
+ />
91
125
  </FormFieldWrapper>
92
126
  );
93
127
  };
@@ -1,3 +1,4 @@
1
1
  import VisualizationWidget from './VisualizationWidget';
2
+ import VisualizationViewWidget from './VisualizationViewWidget';
2
3
 
3
- export { VisualizationWidget };
4
+ export { VisualizationWidget, VisualizationViewWidget };
@@ -1,3 +1,8 @@
1
+ import {
2
+ getSheetnamesChoices,
3
+ canChangeVizData,
4
+ } from '@eeacms/volto-tableau/Tableau/helpers';
5
+
1
6
  const urlParametersSchema = {
2
7
  title: 'Parameter',
3
8
  fieldsets: [
@@ -16,6 +21,22 @@ const urlParametersSchema = {
16
21
  required: [],
17
22
  };
18
23
 
24
+ const staticParameters = {
25
+ title: 'Parameter',
26
+ fieldsets: [{ id: 'default', title: 'Default', fields: ['field', 'value'] }],
27
+ properties: {
28
+ field: {
29
+ title: 'Tableau fieldname',
30
+ type: 'text',
31
+ },
32
+ value: {
33
+ title: 'Value',
34
+ type: 'text',
35
+ },
36
+ },
37
+ required: [],
38
+ };
39
+
19
40
  const breakpointUrlSchema = (config) => {
20
41
  const breakpoints = config.blocks.blocksConfig.tableau_block.breakpoints;
21
42
 
@@ -25,7 +46,6 @@ const breakpointUrlSchema = (config) => {
25
46
  properties: {
26
47
  device: {
27
48
  title: 'Device',
28
- type: 'array',
29
49
  choices: Object.keys(breakpoints).map((breakpoint) => [
30
50
  breakpoint,
31
51
  breakpoint,
@@ -40,76 +60,98 @@ const breakpointUrlSchema = (config) => {
40
60
  };
41
61
  };
42
62
 
43
- export default (config) => ({
44
- title: 'Tableau',
45
- fieldsets: [
46
- {
47
- id: 'default',
48
- title: 'Default',
49
- fields: ['url'],
50
- },
51
- {
52
- id: 'options',
53
- title: 'Options',
54
- fields: [
55
- 'sheetname',
56
- 'hideTabs',
57
- 'hideToolbar',
58
- 'autoScale',
59
- 'toolbarPosition',
60
- ],
61
- },
62
- {
63
- id: 'extra_options',
64
- title: 'Extra options',
65
- fields: ['urlParameters', 'breakpointUrls'],
66
- },
67
- ],
68
- properties: {
69
- url: {
70
- title: 'Url',
71
- widget: 'textarea',
72
- },
73
- sheetname: {
74
- title: 'Sheetname',
75
- type: 'text',
76
- },
77
- hideTabs: {
78
- title: 'Hide tabs',
79
- type: 'boolean',
80
- default: false,
81
- },
82
- hideToolbar: {
83
- title: 'Hide toolbar',
84
- type: 'boolean',
85
- default: false,
86
- },
87
- autoScale: {
88
- title: 'Auto scale',
89
- type: 'boolean',
90
- default: false,
91
- description: 'Scale down tableau according to width',
92
- },
93
- toolbarPosition: {
94
- title: 'Toolbar position',
95
- choices: [
96
- ['Top', 'Top'],
97
- ['Bottom', 'Bottom'],
98
- ],
99
- default: 'Top',
100
- },
101
- urlParameters: {
102
- title: 'URL parameters',
103
- widget: 'object_list',
104
- schema: urlParametersSchema,
105
- description: 'Set a list of url parameters to filter the tableau',
106
- },
107
- breakpointUrls: {
108
- title: 'Breakpoint urls',
109
- widget: 'object_list',
110
- schema: breakpointUrlSchema(config),
111
- description: 'Set different vizualization for specific breakpoint',
63
+ export default (config, viz, vizState) => {
64
+ const isDisabled = !canChangeVizData(viz, vizState);
65
+
66
+ return {
67
+ title: 'Tableau',
68
+ fieldsets: [
69
+ {
70
+ id: 'default',
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'],
89
+ },
90
+ ],
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
+ },
127
+ urlParameters: {
128
+ title: 'URL parameters',
129
+ widget: 'object_list',
130
+ schema: urlParametersSchema,
131
+ description: 'Set a list of url parameters to filter the tableau',
132
+ isDisabled,
133
+ },
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,
146
+ },
147
+ breakpointUrls: {
148
+ title: 'Breakpoint urls',
149
+ widget: 'object_list',
150
+ schema: breakpointUrlSchema(config),
151
+ description: 'Set different vizualization for specific breakpoint',
152
+ isDisabled,
153
+ },
112
154
  },
113
- },
114
- required: ['url'],
115
- });
155
+ required: ['url'],
156
+ };
157
+ };
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import installBlocks from './Blocks';
2
2
  import { VisualizationView } from './Views';
3
- import { VisualizationWidget } from './Widgets';
3
+ import { VisualizationWidget, VisualizationViewWidget } from './Widgets';
4
4
 
5
5
  const applyConfig = (config) => {
6
6
  config.settings.allowed_cors_destinations = [
@@ -12,6 +12,7 @@ const applyConfig = (config) => {
12
12
 
13
13
  config.views.contentTypesViews.tableau_visualization = VisualizationView;
14
14
  config.widgets.id.tableau_visualization = VisualizationWidget;
15
+ config.widgets.views.id.tableau_visualization = VisualizationViewWidget;
15
16
 
16
17
  return [installBlocks].reduce((acc, apply) => apply(acc), config);
17
18
  };
@@ -17,8 +17,8 @@
17
17
  }
18
18
 
19
19
  .tableau-wrapper {
20
- overflow: auto;
21
20
  padding: @tableauWrapperPadding;
21
+ margin: @tableauWrapperMargin;
22
22
  background-color: @tableauWrapperBackground;
23
23
 
24
24
  .tableau-debug {
@@ -30,10 +30,20 @@
30
30
  }
31
31
 
32
32
  .tableau-info {
33
- margin: 0 auto 1rem auto;
33
+ margin: 0 auto;
34
34
  }
35
35
 
36
36
  .tableau {
37
+ margin-bottom: 1rem;
38
+
39
+ &:not(.tableau-autoscale) {
40
+ overflow: auto;
41
+ }
42
+
43
+ &.tableau-autoscale {
44
+ overflow: hidden;
45
+ }
46
+
37
47
  iframe {
38
48
  padding: @tableauIframePadding;
39
49
  border: @tableauIframeBorder;
@@ -47,7 +57,7 @@
47
57
  display: flex;
48
58
  overflow: hidden;
49
59
  width: 100%;
50
- height: 100%;
60
+ height: auto;
51
61
  align-items: center;
52
62
  justify-content: center;
53
63
  margin: 0 auto 1rem auto;
@@ -71,6 +81,39 @@
71
81
  text-align: center;
72
82
  }
73
83
  }
84
+
85
+ .tableau-error {
86
+ color: @errorTextColor;
87
+ }
88
+
89
+ .reload-tableau {
90
+ position: absolute;
91
+ right: 1rem;
92
+ }
93
+
94
+ .json-snippet {
95
+ .key {
96
+ color: @secondaryColor;
97
+ }
98
+ }
99
+
100
+ .important-note {
101
+ color: @secondaryColor;
102
+
103
+ .clear-filter-button {
104
+ padding: 0;
105
+ border: none;
106
+ margin: 0;
107
+ background-color: transparent;
108
+ color: inherit;
109
+ cursor: pointer;
110
+ text-decoration: underline;
111
+
112
+ &:hover {
113
+ color: @primaryColor;
114
+ }
115
+ }
116
+ }
74
117
  }
75
118
 
76
119
  // ========= Sources ==========
@@ -1,5 +1,6 @@
1
1
  @tableauWrapperBackground : #f5f5f5;
2
- @tableauWrapperPadding : 1rem 1rem 0 1rem;
2
+ @tableauWrapperPadding : 1rem;
3
+ @tableauWrapperMargin : 0 0 1rem 0;
3
4
 
4
5
  @tableauIframePadding : 0;
5
6
  @tableauIframeMargin : 0 auto 1rem auto;