@@ -217,6 +217,8 @@ describe('should collect control values and create SFD', () => {
217217 // advanced analytics - resample
218218 resample_rule : '1D' ,
219219 resample_method : 'zerofill' ,
220+ // dashboard context
221+ dashboardId : 123 ,
220222 } ;
221223 const sourceMockFormData : QueryFormData = {
222224 ...sharedControlsFormData ,
@@ -240,12 +242,15 @@ describe('should collect control values and create SFD', () => {
240242 } ;
241243
242244 beforeAll ( ( ) => {
245+ // dashboardId is not a control, it's just context, so exclude it from control definitions
246+ const publicControlFields = publicControls . filter ( c => c !== 'dashboardId' ) ;
247+
243248 getChartControlPanelRegistry ( ) . registerValue ( 'source_viz' , {
244249 controlPanelSections : [
245250 sections . advancedAnalyticsControls ,
246251 {
247252 label : 'transform controls' ,
248- controlSetRows : publicControls . map ( control => [ control ] ) ,
253+ controlSetRows : publicControlFields . map ( control => [ control ] ) ,
249254 } ,
250255 {
251256 label : 'axis column' ,
@@ -258,7 +263,7 @@ describe('should collect control values and create SFD', () => {
258263 sections . advancedAnalyticsControls ,
259264 {
260265 label : 'transform controls' ,
261- controlSetRows : publicControls . map ( control => [ control ] ) ,
266+ controlSetRows : publicControlFields . map ( control => [ control ] ) ,
262267 } ,
263268 {
264269 label : 'axis column' ,
@@ -447,6 +452,83 @@ describe('should transform form_data between table and bigNumberTotal', () => {
447452 ] ) ;
448453 expect ( tblFormData . groupby ) . toEqual ( [ 'name' , 'gender' , adhocColumn ] ) ;
449454 } ) ;
455+
456+ test ( 'preserves dashboardId when transforming between viz types' , ( ) => {
457+ // Create form data with dashboardId (simulating opening explore from a dashboard)
458+ const formDataWithDashboard = {
459+ ...tableVizFormData ,
460+ dashboardId : 42 ,
461+ } ;
462+ const storeWithDashboard = {
463+ ...tableVizStore ,
464+ form_data : formDataWithDashboard ,
465+ } ;
466+
467+ // Transform table -> bigNumberTotal
468+ const sfd = new StandardizedFormData ( formDataWithDashboard ) ;
469+ const { formData : bntFormData } = sfd . transform (
470+ VizType . BigNumberTotal ,
471+ storeWithDashboard ,
472+ ) ;
473+
474+ // Verify dashboardId is preserved after transformation
475+ expect ( bntFormData . dashboardId ) . toBe ( 42 ) ;
476+
477+ // Transform back bigNumberTotal -> table
478+ const sfd2 = new StandardizedFormData ( bntFormData ) ;
479+ const { formData : tblFormData } = sfd2 . transform ( 'table' , {
480+ ...storeWithDashboard ,
481+ form_data : bntFormData ,
482+ controls : {
483+ ...tableVizStore . controls ,
484+ } ,
485+ } ) ;
486+
487+ // Verify dashboardId is still preserved after second transformation
488+ expect ( tblFormData . dashboardId ) . toBe ( 42 ) ;
489+ } ) ;
490+
491+ test ( 'handles missing dashboardId gracefully' , ( ) => {
492+ // Test with no dashboardId (exploring a chart not from a dashboard)
493+ const formDataNoDashboard = {
494+ ...tableVizFormData ,
495+ // dashboardId is undefined
496+ } ;
497+ const storeNoDashboard = {
498+ ...tableVizStore ,
499+ form_data : formDataNoDashboard ,
500+ } ;
501+
502+ const sfd = new StandardizedFormData ( formDataNoDashboard ) ;
503+ const { formData : bntFormData } = sfd . transform (
504+ VizType . BigNumberTotal ,
505+ storeNoDashboard ,
506+ ) ;
507+
508+ // dashboardId should not be present when it was never set
509+ expect ( bntFormData . dashboardId ) . toBeUndefined ( ) ;
510+ } ) ;
511+
512+ test ( 'handles null dashboardId' , ( ) => {
513+ // Test with explicit null dashboardId
514+ const formDataNullDashboard = {
515+ ...tableVizFormData ,
516+ dashboardId : null ,
517+ } ;
518+ const storeNullDashboard = {
519+ ...tableVizStore ,
520+ form_data : formDataNullDashboard ,
521+ } ;
522+
523+ const sfd = new StandardizedFormData ( formDataNullDashboard ) ;
524+ const { formData : bntFormData } = sfd . transform (
525+ VizType . BigNumberTotal ,
526+ storeNullDashboard ,
527+ ) ;
528+
529+ // null is falsy, so dashboardId should not be added
530+ expect ( bntFormData . dashboardId ) . toBeUndefined ( ) ;
531+ } ) ;
450532} ) ;
451533
452534// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
0 commit comments