@@ -253,7 +253,10 @@ class SaveModal extends Component<SaveModalProps, SaveModalState> {
253253 ? sliceDashboards
254254 : [ ...sliceDashboards , dashboard . id ] ;
255255 formData . dashboards = sliceDashboards ;
256- if ( this . state . action === 'saveas' ) {
256+ if (
257+ this . state . action === 'saveas' &&
258+ this . state . selectedTab ?. value !== 'OUT_OF_TAB'
259+ ) {
257260 selectedTabId = this . state . selectedTab ?. value as string ;
258261 }
259262 }
@@ -497,20 +500,51 @@ class SaveModal extends Component<SaveModalProps, SaveModalState> {
497500 return [ ] ;
498501 }
499502 const tabTree = result . tab_tree ;
500-
503+ const gridTabIds = new Set < string > ( ) ;
501504 const convertToTreeData = ( nodes : TabNode [ ] ) : TabTreeNode [ ] =>
502- nodes . map ( node => ( {
503- value : node . value ,
504- title : node . title ,
505- key : node . value ,
506- children :
507- node . children && node . children . length > 0
508- ? convertToTreeData ( node . children )
509- : undefined ,
510- } ) ) ;
505+ nodes . map ( node => {
506+ const isGridTab =
507+ Array . isArray ( node . parents ) && node . parents . includes ( 'GRID_ID' ) ;
508+ if ( isGridTab ) {
509+ gridTabIds . add ( node . value ) ;
510+ }
511+ return {
512+ value : node . value ,
513+ title : node . title ,
514+ key : node . value ,
515+ children :
516+ node . children && node . children . length > 0
517+ ? convertToTreeData ( node . children )
518+ : undefined ,
519+ } ;
520+ } ) ;
511521
512522 const treeData = convertToTreeData ( tabTree ) ;
513- this . setState ( { tabsData : treeData } ) ;
523+
524+ // Add "Out of tab" option at the beginning
525+ if ( gridTabIds . size > 0 ) {
526+ const tabsDataWithOutOfTab = [
527+ {
528+ value : 'OUT_OF_TAB' ,
529+ title : 'Out of tab' ,
530+ key : 'OUT_OF_TAB' ,
531+ children : undefined ,
532+ } ,
533+ ...treeData ,
534+ ] ;
535+
536+ this . setState ( {
537+ tabsData : tabsDataWithOutOfTab ,
538+ selectedTab : { value : 'OUT_OF_TAB' , label : 'Out of tab' } ,
539+ } ) ;
540+ } else {
541+ const firstTab = treeData [ 0 ] ;
542+ this . setState ( {
543+ tabsData : treeData ,
544+ selectedTab : { value : firstTab . value , label : firstTab . title } ,
545+ } ) ;
546+ }
547+
514548 return treeData ;
515549 } catch ( error ) {
516550 logging . error ( 'Error loading tabs:' , error ) ;
0 commit comments