@@ -14,6 +14,8 @@ class TransformAccordion extends Component {
1414 fullContainer,
1515 fullContainer : { transforms = [ ] } ,
1616 localize : _ ,
17+ container,
18+ dataSourceOptions,
1719 } = this . context ;
1820 const { children} = this . props ;
1921
@@ -23,7 +25,9 @@ class TransformAccordion extends Component {
2325 { label : _ ( 'Aggregate' ) , type : 'aggregate' } ,
2426 ] ;
2527
26- if ( [ 'scatter' , 'bar' , 'scattergl' ] . indexOf ( fullContainer . type ) === - 1 ) {
28+ const transformableCharts = [ 'scatter' , 'bar' , 'scattergl' ] ;
29+
30+ if ( ! transformableCharts . includes ( fullContainer . type ) ) {
2731 return (
2832 < FoldEmpty
2933 icon = { PlotScatterIcon }
@@ -32,39 +36,70 @@ class TransformAccordion extends Component {
3236 ) ;
3337 }
3438
39+ const transformBy =
40+ container . transforms &&
41+ container . transforms . map ( tr => {
42+ let foldNameSuffix = '' ;
43+ if ( tr . groupssrc ) {
44+ const groupssrc =
45+ dataSourceOptions &&
46+ dataSourceOptions . find ( d => d . value === tr . groupssrc ) ;
47+ foldNameSuffix = `: ${
48+ groupssrc && groupssrc . label ? groupssrc . label : tr . groupssrc
49+ } `;
50+ } else if ( tr . targetsrc ) {
51+ const targetsrc =
52+ dataSourceOptions &&
53+ dataSourceOptions . find ( d => d . value === tr . targetsrc ) ;
54+ foldNameSuffix = `: ${
55+ targetsrc && targetsrc . label ? targetsrc . label : tr . targetsrc
56+ } `;
57+ }
58+ return foldNameSuffix ;
59+ } ) ;
60+
3561 const filteredTransforms = transforms . filter ( ( { type} ) => Boolean ( type ) ) ;
3662 const content =
3763 filteredTransforms . length &&
3864 filteredTransforms . map ( ( tr , i ) => (
3965 < TransformFold
4066 key = { i }
4167 transformIndex = { i }
42- name = { transformTypes . filter ( ( { type} ) => type === tr . type ) [ 0 ] . label }
68+ name = { `${
69+ transformTypes . filter ( ( { type} ) => type === tr . type ) [ 0 ] . label
70+ } ${ transformBy [ i ] } `}
4371 canDelete = { true }
4472 >
4573 { children }
4674 </ TransformFold >
4775 ) ) ;
4876
49- const handlers = transformTypes . map ( ( { label, type} ) => {
50- return {
51- label,
52- handler : context => {
53- const { fullContainer, updateContainer} = context ;
54- if ( updateContainer ) {
55- const transformIndex = Array . isArray ( fullContainer . transforms )
56- ? fullContainer . transforms . length
57- : 0 ;
58- const key = `transforms[${ transformIndex } ]` ;
59- updateContainer ( { [ key ] : { type} } ) ;
60- }
61- } ,
62- } ;
63- } ) ;
64-
6577 const addAction = {
66- label : _ ( 'Aggregation' ) ,
67- handler : handlers [ 2 ] . handler ,
78+ label : _ ( 'Transform' ) ,
79+ handler : transformTypes . map ( ( { label, type} ) => {
80+ return {
81+ label,
82+ handler : context => {
83+ const { fullContainer, updateContainer} = context ;
84+ if ( updateContainer ) {
85+ const transformIndex = Array . isArray ( fullContainer . transforms )
86+ ? fullContainer . transforms . length
87+ : 0 ;
88+ const key = `transforms[${ transformIndex } ]` ;
89+
90+ const payload = { type} ;
91+ const firstDataSource = dataSourceOptions [ 0 ] . value ;
92+ if ( type === 'filter' ) {
93+ payload . targetsrc = firstDataSource ;
94+ } else {
95+ payload . groupssrc = firstDataSource ;
96+ }
97+
98+ updateContainer ( { [ key ] : payload } ) ;
99+ }
100+ } ,
101+ } ;
102+ } ) ,
68103 } ;
69104
70105 return (
@@ -78,6 +113,8 @@ class TransformAccordion extends Component {
78113TransformAccordion . contextTypes = {
79114 fullContainer : PropTypes . object ,
80115 localize : PropTypes . func ,
116+ container : PropTypes . object ,
117+ dataSourceOptions : PropTypes . array ,
81118} ;
82119
83120TransformAccordion . propTypes = {
0 commit comments