@@ -36,6 +36,7 @@ import { StockImages } from "./StockImagesTab/StockImages";
36
36
import UploadFilePickerTab from "./UploadFilePickerTab/UploadFilePickerTab" ;
37
37
import MultipleUploadFilePickerTab from "./MultipleUploadFilePickerTab/MultipleUploadFilePickerTab" ;
38
38
import WebSearchTab from "./WebSearchTab/WebSearchTab" ;
39
+ import { FilePickerTab } from "./FilePickerTab" ;
39
40
40
41
41
42
export class FilePicker extends React . Component <
@@ -89,7 +90,7 @@ export class FilePicker extends React.Component<
89
90
90
91
this . setState ( {
91
92
organisationAssetsEnabled : orgAssetsEnabled ,
92
- selectedTab : this . getDefaultSelectedTabKey ( this . props , orgAssetsEnabled ) ,
93
+ selectedTab : this . _getDefaultSelectedTabKey ( this . props , orgAssetsEnabled ) ,
93
94
} ) ;
94
95
if ( ! ! this . props . context && ! ! this . props . webAbsoluteUrl ) {
95
96
const { title, id } = await this . fileBrowserService . getSiteTitleAndId ( ) ;
@@ -190,7 +191,7 @@ export class FilePicker extends React.Component<
190
191
/>
191
192
</ div >
192
193
< div className = { styles . tabsContainer } >
193
- { this . state . selectedTab === "keyLink" && (
194
+ { this . state . selectedTab === FilePickerTab . Link && (
194
195
< LinkFilePickerTab
195
196
fileSearchService = { this . fileSearchService }
196
197
renderCustomLinkTabContent = {
@@ -201,7 +202,7 @@ export class FilePicker extends React.Component<
201
202
{ ...linkTabProps }
202
203
/>
203
204
) }
204
- { this . state . selectedTab === "keyUpload" && (
205
+ { this . state . selectedTab === FilePickerTab . Upload && (
205
206
< UploadFilePickerTab
206
207
renderCustomUploadTabContent = {
207
208
this . props . renderCustomUploadTabContent
@@ -210,7 +211,7 @@ export class FilePicker extends React.Component<
210
211
onChange = { this . _handleOnChange }
211
212
/>
212
213
) }
213
- { this . state . selectedTab === "keyMultipleUpload" && (
214
+ { this . state . selectedTab === FilePickerTab . MultipleUpload && (
214
215
< MultipleUploadFilePickerTab
215
216
renderCustomMultipleUploadTabContent = {
216
217
this . props . renderCustomMultipleUploadTabContent
@@ -219,7 +220,7 @@ export class FilePicker extends React.Component<
219
220
onChange = { this . _handleOnChange }
220
221
/>
221
222
) }
222
- { this . state . selectedTab === "keySite" && (
223
+ { this . state . selectedTab === FilePickerTab . Site && (
223
224
< SiteFilePickerTab
224
225
fileBrowserService = { this . fileBrowserService }
225
226
includePageLibraries = { this . props . includePageLibraries }
@@ -230,37 +231,37 @@ export class FilePicker extends React.Component<
230
231
{ ...linkTabProps }
231
232
/>
232
233
) }
233
- { this . state . selectedTab === "keyOrgAssets" && (
234
+ { this . state . selectedTab === FilePickerTab . OrgAssets && (
234
235
< SiteFilePickerTab
235
236
breadcrumbFirstNode = { {
236
237
isCurrentItem : true ,
237
238
text : strings . OrgAssetsTabLabel ,
238
- key : "keyOrgAssets" ,
239
+ key : FilePickerTab . OrgAssets ,
239
240
} }
240
241
fileBrowserService = { this . orgAssetsService }
241
242
webTitle = { this . state . webTitle }
242
243
{ ...linkTabProps }
243
244
/>
244
245
) }
245
- { this . state . selectedTab === "keyWeb" && (
246
+ { this . state . selectedTab === FilePickerTab . Web && (
246
247
< WebSearchTab
247
248
bingSearchService = { this . fileSearchService }
248
249
{ ...linkTabProps }
249
250
/>
250
251
) }
251
- { this . state . selectedTab === "keyOneDrive" && (
252
+ { this . state . selectedTab === FilePickerTab . OneDrive && (
252
253
< OneDriveFilesTab
253
254
oneDriveService = { this . oneDriveService }
254
255
{ ...linkTabProps }
255
256
/>
256
257
) }
257
- { this . state . selectedTab === "keyRecent" && (
258
+ { this . state . selectedTab === FilePickerTab . Recent && (
258
259
< RecentFilesTab
259
260
fileSearchService = { this . fileSearchService }
260
261
{ ...linkTabProps }
261
262
/>
262
263
) }
263
- { this . state . selectedTab === "keyStockImages" && (
264
+ { this . state . selectedTab === FilePickerTab . StockImages && (
264
265
< StockImages
265
266
language = {
266
267
this . props . context . pageContext . cultureInfo . currentCultureName
@@ -294,7 +295,7 @@ export class FilePicker extends React.Component<
294
295
private _handleOpenPanel = ( ) : void => {
295
296
this . setState ( {
296
297
panelOpen : true ,
297
- selectedTab : this . getDefaultSelectedTabKey (
298
+ selectedTab : this . _getDefaultSelectedTabKey (
298
299
this . props ,
299
300
this . state . organisationAssetsEnabled
300
301
) ,
@@ -344,29 +345,29 @@ export class FilePicker extends React.Component<
344
345
*/
345
346
private _getNavPanelOptions = ( ) : INavLinkGroup [ ] => {
346
347
const addUrl = this . props . storeLastActiveTab !== false ;
347
- const links = [ ] ;
348
+ let links = [ ] ;
348
349
349
350
if ( ! this . props . hideRecentTab ) {
350
351
links . push ( {
351
352
name : strings . RecentLinkLabel ,
352
353
url : addUrl ? "#recent" : undefined ,
353
354
icon : "Recent" ,
354
- key : "keyRecent" ,
355
+ key : FilePickerTab . Recent ,
355
356
} ) ;
356
357
}
357
358
if ( ! this . props . hideStockImages ) {
358
359
links . push ( {
359
360
name : strings . StockImagesLinkLabel ,
360
361
url : addUrl ? "#stockImages" : undefined ,
361
- key : "keyStockImages" ,
362
+ key : FilePickerTab . StockImages ,
362
363
icon : "ImageSearch" ,
363
364
} ) ;
364
365
}
365
366
if ( this . props . bingAPIKey && ! this . props . hideWebSearchTab ) {
366
367
links . push ( {
367
368
name : strings . WebSearchLinkLabel ,
368
369
url : addUrl ? "#search" : undefined ,
369
- key : "keyWeb" ,
370
+ key : FilePickerTab . Web ,
370
371
icon : "Search" ,
371
372
} ) ;
372
373
}
@@ -378,85 +379,107 @@ export class FilePicker extends React.Component<
378
379
name : strings . OrgAssetsLinkLabel ,
379
380
url : addUrl ? "#orgAssets" : undefined ,
380
381
icon : "FabricFolderConfirm" ,
381
- key : "keyOrgAssets" ,
382
+ key : FilePickerTab . OrgAssets ,
382
383
} ) ;
383
384
}
384
385
if ( ! this . props . hideOneDriveTab ) {
385
386
links . push ( {
386
387
name : "OneDrive" ,
387
388
url : addUrl ? "#onedrive" : undefined ,
388
- key : "keyOneDrive" ,
389
+ key : FilePickerTab . OneDrive ,
389
390
icon : "OneDrive" ,
390
391
} ) ;
391
392
}
392
393
if ( ! this . props . hideSiteFilesTab ) {
393
394
links . push ( {
394
395
name : strings . SiteLinkLabel ,
395
396
url : addUrl ? "#globe" : undefined ,
396
- key : "keySite" ,
397
+ key : FilePickerTab . Site ,
397
398
icon : "Globe" ,
398
399
} ) ;
399
400
}
400
401
if ( ! this . props . hideLocalUploadTab ) {
401
402
links . push ( {
402
403
name : strings . UploadLinkLabel ,
403
404
url : addUrl ? "#upload" : undefined ,
404
- key : "keyUpload" ,
405
+ key : FilePickerTab . Upload ,
405
406
icon : "System" ,
406
407
} ) ;
407
408
}
408
409
if ( ! this . props . hideLocalMultipleUploadTab ) {
409
410
links . push ( {
410
411
name : strings . UploadLinkLabel + " " + strings . OneDriveRootFolderName ,
411
412
url : addUrl ? "#Multipleupload" : undefined ,
412
- key : "keyMultipleUpload" ,
413
+ key : FilePickerTab . MultipleUpload ,
413
414
icon : "BulkUpload" ,
414
415
} ) ;
415
416
}
416
417
if ( ! this . props . hideLinkUploadTab ) {
417
418
links . push ( {
418
419
name : strings . FromLinkLinkLabel ,
419
420
url : addUrl ? "#link" : undefined ,
420
- key : "keyLink" ,
421
+ key : FilePickerTab . Link ,
421
422
icon : "Link" ,
422
423
} ) ;
423
424
}
424
425
426
+ if ( this . props . tabOrder ) {
427
+ links = this . _getTabOrder ( links ) ;
428
+ }
429
+
425
430
const groups : INavLinkGroup [ ] = [ { links } ] ;
426
431
return groups ;
427
432
}
428
433
429
- private getDefaultSelectedTabKey = (
434
+ /**
435
+ * Sorts navigation tabs based on the tabOrder prop
436
+ */
437
+ private _getTabOrder = ( links ) : INavLink [ ] => {
438
+ const sortedKeys = [
439
+ ...this . props . tabOrder ,
440
+ ...links . map ( l => l . key ) . filter ( key => ! this . props . tabOrder . includes ( key ) ) ,
441
+ ] ;
442
+
443
+ links . sort ( ( a , b ) => {
444
+ return sortedKeys . indexOf ( a . key ) - sortedKeys . indexOf ( b . key ) ;
445
+ } ) ;
446
+
447
+ return links ;
448
+ } ;
449
+
450
+ /**
451
+ * Returns the default selected tab key
452
+ */
453
+ private _getDefaultSelectedTabKey = (
430
454
props : IFilePickerProps ,
431
455
orgAssetsEnabled : boolean
432
456
) : 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" ;
457
+ const tabsConfig = [
458
+ { isTabVisible : ! props . hideRecentTab , tabKey : FilePickerTab . Recent } ,
459
+ { isTabVisible : ! props . hideStockImages , tabKey : FilePickerTab . StockImages } ,
460
+ { isTabVisible : props . bingAPIKey && ! props . hideWebSearchTab , tabKey : FilePickerTab . Web } ,
461
+ { isTabVisible : ! props . hideOrganisationalAssetTab && orgAssetsEnabled , tabKey : FilePickerTab . OrgAssets } ,
462
+ { isTabVisible : ! props . hideOneDriveTab , tabKey : FilePickerTab . OneDrive } ,
463
+ { isTabVisible : ! props . hideSiteFilesTab , tabKey : FilePickerTab . Site } ,
464
+ { isTabVisible : ! props . hideLocalUploadTab , tabKey : FilePickerTab . Upload } ,
465
+ { isTabVisible : ! props . hideLinkUploadTab , tabKey : FilePickerTab . Link } ,
466
+ { isTabVisible : ! props . hideLocalMultipleUploadTab , tabKey : FilePickerTab . MultipleUpload }
467
+ ] ;
468
+
469
+ const visibleTabs = tabsConfig . filter ( tab => tab . isTabVisible ) ;
470
+ const visibleTabKeys = visibleTabs . map ( tab => tab . tabKey ) ;
471
+
472
+ // If defaultSelectedTab is provided and is visible, then return tabKey
473
+ if ( this . props . defaultSelectedTab && visibleTabKeys . includes ( this . props . defaultSelectedTab ) ) {
474
+ return this . props . defaultSelectedTab ;
459
475
}
460
476
477
+ // If no valid default tab is provided, find the first visible tab in the order
478
+ if ( this . props . tabOrder ) {
479
+ const visibleTabSet = new Set ( visibleTabKeys ) ;
480
+ return this . props . tabOrder . find ( key => visibleTabSet . has ( key ) ) ;
481
+ } else {
482
+ return visibleTabKeys [ 0 ] ; // first visible tab from default order
483
+ }
461
484
}
462
485
}
0 commit comments