@@ -47,6 +47,8 @@ export class FilePicker extends React.Component<
47
47
private orgAssetsService : OrgAssetsService ;
48
48
private fileSearchService : FilesSearchService ;
49
49
50
+ private tabOrder = this . props . tabOrder ?? [ "keyRecent" , "keyStockImages" , "keyWeb" , "keyOrgAssets" , "keyOneDrive" , "keySite" , "keyUpload" , "keyLink" , "keyMultipleUpload" ] ;
51
+
50
52
constructor ( props : IFilePickerProps ) {
51
53
super ( props ) ;
52
54
@@ -89,7 +91,7 @@ export class FilePicker extends React.Component<
89
91
90
92
this . setState ( {
91
93
organisationAssetsEnabled : orgAssetsEnabled ,
92
- selectedTab : this . getDefaultSelectedTabKey ( this . props , orgAssetsEnabled ) ,
94
+ selectedTab : this . _getDefaultSelectedTabKey ( this . props , orgAssetsEnabled ) ,
93
95
} ) ;
94
96
if ( ! ! this . props . context && ! ! this . props . webAbsoluteUrl ) {
95
97
const { title, id } = await this . fileBrowserService . getSiteTitleAndId ( ) ;
@@ -294,7 +296,7 @@ export class FilePicker extends React.Component<
294
296
private _handleOpenPanel = ( ) : void => {
295
297
this . setState ( {
296
298
panelOpen : true ,
297
- selectedTab : this . getDefaultSelectedTabKey (
299
+ selectedTab : this . _getDefaultSelectedTabKey (
298
300
this . props ,
299
301
this . state . organisationAssetsEnabled
300
302
) ,
@@ -344,7 +346,7 @@ export class FilePicker extends React.Component<
344
346
*/
345
347
private _getNavPanelOptions = ( ) : INavLinkGroup [ ] => {
346
348
const addUrl = this . props . storeLastActiveTab !== false ;
347
- const links = [ ] ;
349
+ let links : INavLink [ ] = [ ] ;
348
350
349
351
if ( ! this . props . hideRecentTab ) {
350
352
links . push ( {
@@ -422,41 +424,57 @@ export class FilePicker extends React.Component<
422
424
} ) ;
423
425
}
424
426
427
+ if ( this . props . tabOrder ) {
428
+ links = this . _getTabOrder ( links ) ;
429
+ }
430
+
425
431
const groups : INavLinkGroup [ ] = [ { links } ] ;
426
432
return groups ;
427
433
}
428
434
429
- private getDefaultSelectedTabKey = (
435
+ /**
436
+ * Sorts navigation tabs based on the tabOrder prop
437
+ */
438
+ private _getTabOrder = ( links : INavLink [ ] ) : INavLink [ ] => {
439
+ const sortedKeys = [
440
+ ...this . tabOrder ,
441
+ ...links . map ( l => l . key ) . filter ( key => ! this . tabOrder . includes ( key ) ) ,
442
+ ] ;
443
+
444
+ links . sort ( ( a , b ) => {
445
+ return sortedKeys . indexOf ( a . key ) - sortedKeys . indexOf ( b . key ) ;
446
+ } ) ;
447
+
448
+ return links ;
449
+ } ;
450
+
451
+ /**
452
+ * Returns the default selected tab key
453
+ */
454
+ private _getDefaultSelectedTabKey = (
430
455
props : IFilePickerProps ,
431
456
orgAssetsEnabled : boolean
432
457
) : string => {
433
- if ( ! props . hideRecentTab ) {
434
- return "keyRecent" ;
435
- }
436
- if ( ! props . hideStockImages ) {
437
- return "keyStockImages" ;
438
- }
439
- if ( props . bingAPIKey && ! props . hideWebSearchTab ) {
440
- return "keyWeb" ;
441
- }
442
- if ( ! props . hideOrganisationalAssetTab && orgAssetsEnabled ) {
443
- return "keyOrgAssets" ;
444
- }
445
- if ( ! props . hideOneDriveTab ) {
446
- return "keyOneDrive" ;
447
- }
448
- if ( ! props . hideSiteFilesTab ) {
449
- return "keySite" ;
450
- }
451
- if ( ! props . hideLocalUploadTab ) {
452
- return "keyUpload" ;
453
- }
454
- if ( ! props . hideLinkUploadTab ) {
455
- return "keyLink" ;
456
- }
457
- if ( ! props . hideLocalMultipleUploadTab ) {
458
- return "keyMultipleUpload" ;
459
- }
458
+ const tabConfig = [
459
+ { isTabVisible : ! props . hideRecentTab , tabKey : "keyRecent" } ,
460
+ { isTabVisible : ! props . hideStockImages , tabKey : "keyStockImages" } ,
461
+ { isTabVisible : props . bingAPIKey && ! props . hideWebSearchTab , tabKey : "keyWeb" } ,
462
+ { isTabVisible : ! props . hideOrganisationalAssetTab && orgAssetsEnabled , tabKey : "keyOrgAssets" } ,
463
+ { isTabVisible : ! props . hideOneDriveTab , tabKey : "keyOneDrive" } ,
464
+ { isTabVisible : ! props . hideSiteFilesTab , tabKey : "keySite" } ,
465
+ { isTabVisible : ! props . hideLocalUploadTab , tabKey : "keyUpload" } ,
466
+ { isTabVisible : ! props . hideLinkUploadTab , tabKey : "keyLink" } ,
467
+ { isTabVisible : ! props . hideLocalMultipleUploadTab , tabKey : "keyMultipleUpload" }
468
+ ] ;
460
469
470
+ const visibleTabs = tabConfig . filter ( tab => tab . isTabVisible ) ;
471
+ const visibleTabKeys = visibleTabs . map ( tab => tab . tabKey ) ;
472
+
473
+ if ( this . props . tabOrder ) {
474
+ const visibleTabSet = new Set ( visibleTabKeys ) ;
475
+ return this . tabOrder . find ( key => visibleTabSet . has ( key ) ) ;
476
+ } else {
477
+ return visibleTabKeys [ 0 ] ; // first visible tab from default order
478
+ }
461
479
}
462
480
}
0 commit comments