@@ -52,28 +52,38 @@ export interface EncodingShelfCardProps {
52
52
noBorder ?: boolean ;
53
53
}
54
54
55
- let selectBaseTables = ( activeFields : FieldItem [ ] , conceptShelfItems : FieldItem [ ] , tables : DictTable [ ] ) : DictTable [ ] => {
55
+ let selectBaseTables = ( activeFields : FieldItem [ ] , conceptShelfItems : FieldItem [ ] , tables : DictTable [ ] , currentTable : DictTable ) : DictTable [ ] => {
56
56
57
- // if there is no active fields at all!!
58
- if ( activeFields . length == 0 ) {
59
- return [ tables [ 0 ] ] ;
60
- }
57
+ let baseTables = [ ] ;
61
58
62
- let activeBaseFields = conceptShelfItems . filter ( ( field ) => {
63
- return activeFields . map ( f => f . source == "derived" ? findBaseFields ( f , conceptShelfItems ) . map ( f2 => f2 . id ) : [ f . id ] ) . flat ( ) . includes ( field . id ) ;
64
- } ) ;
59
+ if ( currentTable . derive ) {
60
+ baseTables = currentTable . derive . source . map ( t => tables . find ( t2 => t2 . id == t ) as DictTable ) ;
61
+ } else {
62
+ baseTables . push ( currentTable ) ;
63
+ }
65
64
66
- let activeOriginalFields = activeBaseFields . filter ( field => field . source == "original" ) ;
67
- let activeCustomFields = activeBaseFields . filter ( field => field . source == "custom" ) ;
68
- let activeDerivedFields = activeFields . filter ( f => f . source == "derived" ) ;
65
+ // if there is no active fields at all!!
66
+ if ( activeFields . length == 0 ) {
67
+ return [ currentTable ] ;
68
+ } else {
69
+ // find what are other tables that was used to derive the active fields
70
+ let activeBaseFields = conceptShelfItems . filter ( ( field ) => {
71
+ return activeFields . map ( f => f . source == "derived" ? findBaseFields ( f , conceptShelfItems ) . map ( f2 => f2 . id ) : [ f . id ] ) . flat ( ) . includes ( field . id ) ;
72
+ } ) ;
73
+
74
+ let activeOriginalFields = activeBaseFields . filter ( field => field . source == "original" ) ;
75
+
76
+ if ( activeOriginalFields . length == 0 && activeFields . length > 0 && tables . length > 0 ) {
77
+ return [ currentTable ] ;
78
+ }
79
+
80
+ // find all tables that contains the active original fields
81
+ let tablesToAdd = tables . filter ( t => activeOriginalFields . map ( f => f . tableRef as string ) . includes ( t . id ) ) ;
69
82
70
- if ( activeOriginalFields . length == 0 && activeFields . length > 0 && tables . length > 0 ) {
71
- return [ tables [ 0 ] ] ;
83
+ baseTables . push ( ...tablesToAdd . filter ( t => ! baseTables . map ( t2 => t2 . id ) . includes ( t . id ) ) ) ;
72
84
}
73
85
74
- let baseTables = tables . filter ( t => activeOriginalFields . map ( f => f . tableRef as string ) . includes ( t . id ) ) ;
75
-
76
- return baseTables
86
+ return baseTables ;
77
87
}
78
88
79
89
export const TriggerCard : FC < { className ?: string , trigger : Trigger , hideFields ?: boolean , label ?: string } > = function ( { label, className, trigger, hideFields } ) {
@@ -104,7 +114,7 @@ export const TriggerCard: FC<{className?: string, trigger: Trigger, hideFields?:
104
114
sx = { { color :'inherit' , maxWidth : '110px' , marginLeft : "2px" , height : 18 , fontSize : 12 , borderRadius : '4px' ,
105
115
border : '1px solid rgb(250 235 215)' , background : 'rgb(250 235 215 / 70%)' ,
106
116
'& .MuiChip-label' : { paddingLeft : '6px' , paddingRight : '6px' } } }
107
- label = { `${ field . name } ` } /> ]
117
+ label = { `${ field ? .name } ` } /> ]
108
118
} )
109
119
}
110
120
@@ -190,6 +200,7 @@ export const EncodingShelfCard: FC<EncodingShelfCardProps> = function ({ chartId
190
200
const tables = useSelector ( ( state : DataFormulatorState ) => state . tables ) ;
191
201
const charts = useSelector ( ( state : DataFormulatorState ) => state . charts ) ;
192
202
const betaMode = useSelector ( ( state : DataFormulatorState ) => state . betaMode ) ;
203
+
193
204
let activeModel = useSelector ( dfSelectors . getActiveModel ) ;
194
205
195
206
let [ prompt , setPrompt ] = useState < string > ( trigger ?. instruction || "" ) ;
@@ -233,7 +244,7 @@ export const EncodingShelfCard: FC<EncodingShelfCardProps> = function ({ chartId
233
244
let deriveNewData = ( overrideTableId ?: string ) => {
234
245
235
246
let mode = 'formulate' ;
236
- let baseTables = selectBaseTables ( activeFields , conceptShelfItems , tables ) ;
247
+ let baseTables = selectBaseTables ( activeFields , conceptShelfItems , tables , currentTable ) ;
237
248
238
249
let instruction = ( chart . chartType == 'Auto' && prompt == "" ) ? "let's get started" : prompt ;
239
250
@@ -352,6 +363,7 @@ export const EncodingShelfCard: FC<EncodingShelfCardProps> = function ({ chartId
352
363
let triggerChartSpec = duplicateChart ( chart ) ;
353
364
let currentTrigger : Trigger = {
354
365
tableId : currentTable . id ,
366
+ sourceTableIds : baseTables . map ( t => t . id ) ,
355
367
instruction : instruction ,
356
368
chartRef : triggerChartSpec . id ,
357
369
resultTableId : candidateTableId
0 commit comments