@@ -23,7 +23,7 @@ export interface Props {
23
23
refetch : ( variables : object ) => any ;
24
24
}
25
25
26
- type SelectionKey = 'to' | 'from' | 'sectors' | 'channels' | 'forms' | 'years' ;
26
+ export type SelectionKey = 'to' | 'from' | 'sectors' | 'channels' | 'forms' | 'years' ;
27
27
28
28
export interface State {
29
29
position : number ;
@@ -88,28 +88,28 @@ class UnbundlingTreemap extends React.Component<Props, State> {
88
88
return value ? [ ...valuesItems , { key, value } ] : valuesItems ;
89
89
}
90
90
91
- public static getActiveOption = ( position : number ) : string =>
92
- Object . keys ( UnbundlingTreemap . groupers ) [ position ]
91
+ // public static getActiveOption = (position: number): string =>
92
+ // Object.keys(UnbundlingTreemap.groupers)[position]
93
93
94
94
constructor ( props : Props ) {
95
95
super ( props ) ;
96
96
97
- const position = 1 ;
98
- const keys = Object . keys ( props . selections ) as SelectionKey [ ] ;
97
+ const position = 0 ;
98
+ const keys = Object . keys ( props . selections ) . filter ( key => key !== 'years' ) as SelectionKey [ ] ;
99
99
const values = [ { key : 'years' , value : props . startYear . toString ( ) } ] ;
100
100
this . state = { position, keys, values, active : 'to' } ;
101
101
this . history . push ( this . state ) ;
102
102
}
103
103
104
104
public onZoomIn = ( { id, color } : Selected ) => {
105
- const position = this . state . position <= 1 ? 1 : this . state . position ;
105
+ const position = this . state . position ;
106
106
107
- if ( ( position + 1 ) < Object . keys ( UnbundlingTreemap . groupers ) . length ) {
107
+ if ( ( position + 1 ) < this . state . keys . length ) {
108
108
// const newKey = this.state.keys[position + 1];
109
109
// TODO: check if key already exists
110
- const currentActive = UnbundlingTreemap . getActiveOption ( position ) ;
110
+ const currentActive = this . state . keys [ position ] ;
111
111
const values = UnbundlingTreemap . addNewValue ( { key : currentActive , value : id } , this . state . values ) ;
112
- const active = UnbundlingTreemap . getActiveOption ( position + 1 ) as SelectionKey ;
112
+ const active = this . state . keys [ position + 1 ] as SelectionKey ;
113
113
this . setState ( { position : position + 1 , values, dimmerColor : color , active } ) ;
114
114
this . history . push ( this . state ) ;
115
115
this . fetch ( active , values ) ;
@@ -129,19 +129,23 @@ class UnbundlingTreemap extends React.Component<Props, State> {
129
129
public updateValue = ( key : string ) => ( value : string ) => {
130
130
// making sure we dont have duplicates
131
131
const values = UnbundlingTreemap . addNewValue ( { key, value } , this . state . values ) ;
132
- const active = UnbundlingTreemap . getActiveOption ( this . state . position ) as SelectionKey ;
132
+ const active = this . state . keys [ this . state . position ] as SelectionKey ;
133
133
this . setState ( { values, active } ) ;
134
134
this . history . push ( this . state ) ;
135
135
this . fetch ( active , values ) ;
136
136
}
137
137
138
- public onMove = ( key : string ) => {
139
- const groupersKeys = Object . keys ( UnbundlingTreemap . groupers ) as SelectionKey [ ] ;
140
- const activeKeyPosition = indexOf ( key , groupersKeys ) ;
141
- this . setState ( { position : activeKeyPosition , active : key as SelectionKey } ) ;
142
- this . history . push ( this . state ) ;
138
+ public onMove = ( key : string , keys : SelectionKey [ ] ) => {
139
+ // const groupersKeys = Object.keys(UnbundlingTreemap.groupers) as SelectionKey[];
140
+ const keyPosition = indexOf ( key , keys ) ;
141
+ if ( keyPosition === this . state . position ) {
142
+ this . setState ( { active : key as SelectionKey , keys } ) ;
143
+ this . history . push ( this . state ) ;
143
144
144
- return this . fetch ( key , this . state . values ) ;
145
+ this . fetch ( key , this . state . values ) ;
146
+ } else {
147
+ this . setState ( { keys } ) ;
148
+ }
145
149
}
146
150
147
151
public fetch ( active : string , values : KeyValue [ ] ) {
@@ -215,21 +219,26 @@ class UnbundlingTreemap extends React.Component<Props, State> {
215
219
onClick = { this . onZoomIn }
216
220
/>
217
221
}
218
- {
219
- this . state . position <= 1
220
- ? ''
221
- :
222
- < Up className = "up" onClick = { this . onZoomOut } >
223
- < Icon name = { 'chevron left' } size = "big" inverted />
224
- </ Up >
225
- }
222
+ { this . renderBackButton ( ) }
226
223
</ Intro >
227
224
</ Container >
228
225
}
229
226
230
227
</ div >
231
228
) ;
232
229
}
230
+
231
+ private renderBackButton ( ) {
232
+ if ( this . state . position > 0 ) {
233
+ return (
234
+ < Up className = "up" onClick = { this . onZoomOut } >
235
+ < Icon name = { 'chevron left' } size = "big" inverted />
236
+ </ Up >
237
+ ) ;
238
+ }
239
+
240
+ return null ;
241
+ }
233
242
}
234
243
235
244
export default UnbundlingTreemap ;
0 commit comments