@@ -23,19 +23,21 @@ class TraceAccordion extends Component {
2323 setLocals ( props , context ) {
2424 // we don't want to include analysis transforms when we're in the create panel
2525 const base = props . canGroup ? context . fullData : context . data ;
26+ const traceFilterCondition =
27+ this . props . traceFilterCondition || ( ( ) => true ) ;
2628
27- this . filteredTracesFullDataPositions = [ ] ;
29+ this . filteredTracesIndexes = [ ] ;
2830 this . filteredTraces = base . filter ( ( t , i ) => {
29- if ( props . excludeFits ) {
30- return ! ( t . transforms && t . transforms . every ( tr => tr . type === 'fit' ) ) ;
31+ if ( traceFilterCondition ( t , context . fullData [ i ] ) ) {
32+ this . filteredTracesIndexes . push ( i ) ;
33+ return true ;
3134 }
32- this . filteredTracesFullDataPositions . push ( i ) ;
33- return true ;
35+ return false ;
3436 } ) ;
3537 }
3638
3739 renderGroupedTraceFolds ( ) {
38- if ( ! this . filteredTraces . length || this . filteredTraces . length < 2 ) {
40+ if ( ! this . filteredTraces . length || this . filteredTraces . length <= 1 ) {
3941 return null ;
4042 }
4143
@@ -55,61 +57,45 @@ class TraceAccordion extends Component {
5557
5658 dataArrayPositionsByTraceType [ traceType ] . push ( trace . index ) ;
5759 fullDataArrayPositionsByTraceType [ traceType ] . push (
58- this . filteredTracesFullDataPositions [ index ]
60+ this . filteredTracesIndexes [ index ]
5961 ) ;
6062 } ) ;
6163
62- return Object . keys ( fullDataArrayPositionsByTraceType ) . map ( ( type , index ) => {
63- return (
64- < TraceFold
65- key = { index }
66- traceIndexes = { dataArrayPositionsByTraceType [ type ] }
67- name = { traceTypes ( _ ) . find ( t => t . value === type ) . label }
68- fullDataArrayPosition = { fullDataArrayPositionsByTraceType [ type ] }
69- >
70- { this . props . children }
71- </ TraceFold >
72- ) ;
73- } ) ;
64+ return Object . keys ( fullDataArrayPositionsByTraceType ) . map ( ( type , index ) => (
65+ < TraceFold
66+ key = { index }
67+ traceIndexes = { dataArrayPositionsByTraceType [ type ] }
68+ name = { traceTypes ( _ ) . find ( t => t . value === type ) . label }
69+ fullDataArrayPosition = { fullDataArrayPositionsByTraceType [ type ] }
70+ >
71+ { this . props . children }
72+ </ TraceFold >
73+ ) ) ;
7474 }
7575
7676 renderUngroupedTraceFolds ( ) {
77- if ( ! this . filteredTraces . length ) {
78- return null ;
79- }
80-
81- return this . filteredTraces . map ( ( d , i ) => {
82- return (
83- < TraceFold
84- key = { i }
85- traceIndexes = { [ d . index ] }
86- canDelete = { this . props . canAdd }
87- messageIfEmpty = { this . props . messageIfEmptyFold }
88- fullDataArrayPosition = { [ this . filteredTracesFullDataPositions [ i ] ] }
89- >
90- { this . props . children }
91- </ TraceFold >
92- ) ;
93- } ) ;
77+ return this . filteredTraces . map ( ( d , i ) => (
78+ < TraceFold
79+ key = { i }
80+ traceIndexes = { [ d . index ] }
81+ canDelete = { this . props . canAdd }
82+ fullDataArrayPosition = { [ this . filteredTracesIndexes [ i ] ] }
83+ >
84+ { this . props . children }
85+ </ TraceFold >
86+ ) ) ;
9487 }
9588
9689 renderTraceFolds ( ) {
97- if ( ! this . filteredTraces . length ) {
98- return null ;
99- }
100-
101- return this . filteredTraces . map ( ( d , i ) => {
102- return (
103- < TraceFold
104- key = { i }
105- traceIndexes = { [ i ] }
106- canDelete = { this . props . canAdd }
107- messageIfEmpty = { this . props . messageIfEmptyFold }
108- >
109- { this . props . children }
110- </ TraceFold >
111- ) ;
112- } ) ;
90+ return this . filteredTraces . map ( ( d , i ) => (
91+ < TraceFold
92+ key = { i }
93+ traceIndexes = { [ this . filteredTracesIndexes [ i ] ] }
94+ canDelete = { this . props . canAdd }
95+ >
96+ { this . props . children }
97+ </ TraceFold >
98+ ) ) ;
11399 }
114100
115101 render ( ) {
@@ -178,8 +164,7 @@ TraceAccordion.propTypes = {
178164 canAdd : PropTypes . bool ,
179165 canGroup : PropTypes . bool ,
180166 children : PropTypes . node ,
181- excludeFits : PropTypes . bool ,
182- messageIfEmptyFold : PropTypes . string ,
167+ traceFilterCondition : PropTypes . func ,
183168} ;
184169
185170export default TraceAccordion ;
0 commit comments