@@ -16,12 +16,11 @@ import { handleSSEMessage } from './SSEActions';
16
16
17
17
enableMapSet ( ) ;
18
18
19
- export const generateFreshChart = ( tableRef : string , chartType ?: string , source : "user" | "trigger" = "user" ) : Chart => {
20
- let realChartType = chartType || "?"
19
+ export const generateFreshChart = ( tableRef : string , chartType : string , source : "user" | "trigger" = "user" ) : Chart => {
21
20
return {
22
21
id : `chart-${ Date . now ( ) - Math . floor ( Math . random ( ) * 10000 ) } ` ,
23
- chartType : realChartType ,
24
- encodingMap : Object . assign ( { } , ...getChartChannels ( realChartType ) . map ( ( channel ) => ( { [ channel ] : { channel : channel , bin : false } } ) ) ) ,
22
+ chartType : chartType ,
23
+ encodingMap : Object . assign ( { } , ...getChartChannels ( chartType ) . map ( ( channel ) => ( { [ channel ] : { channel : channel , bin : false } } ) ) ) ,
25
24
tableRef : tableRef ,
26
25
saved : false ,
27
26
source : source ,
@@ -48,10 +47,8 @@ export interface ModelConfig {
48
47
export const MODEL_SLOT_TYPES = [ 'generation' , 'hint' ] as const ;
49
48
export type ModelSlotType = typeof MODEL_SLOT_TYPES [ number ] ;
50
49
51
- export interface ModelSlots {
52
- generation ?: string ; // model id assigned to generation tasks
53
- hint ?: string ; // model id assigned to hint tasks
54
- }
50
+ // Derive ModelSlots interface from the constant
51
+ export type ModelSlots = Partial < Record < ModelSlotType , string > > ;
55
52
56
53
// Define a type for the slice state
57
54
export interface DataFormulatorState {
@@ -359,11 +356,13 @@ export const dataFormulatorSlice = createSlice({
359
356
} ,
360
357
loadTable : ( state , action : PayloadAction < DictTable > ) => {
361
358
let table = action . payload ;
359
+ let freshChart = generateFreshChart ( table . id , '?' ) as Chart ;
362
360
state . tables = [ ...state . tables , table ] ;
361
+ state . charts = [ ...state . charts , freshChart ] ;
363
362
state . conceptShelfItems = [ ...state . conceptShelfItems , ...getDataFieldItems ( table ) ] ;
364
363
365
364
state . focusedTableId = table . id ;
366
- state . focusedChartId = undefined ;
365
+ state . focusedChartId = freshChart . id ;
367
366
} ,
368
367
deleteTable : ( state , action : PayloadAction < string > ) => {
369
368
let tableId = action . payload ;
@@ -453,7 +452,7 @@ export const dataFormulatorSlice = createSlice({
453
452
} ) ;
454
453
}
455
454
} ,
456
- createNewChart : ( state , action : PayloadAction < { chartType ? : string , tableId ? : string } > ) => {
455
+ createNewChart : ( state , action : PayloadAction < { chartType : string , tableId : string } > ) => {
457
456
let chartType = action . payload . chartType ;
458
457
let tableId = action . payload . tableId || state . tables [ 0 ] . id ;
459
458
let freshChart = generateFreshChart ( tableId , chartType , "user" ) as Chart ;
0 commit comments