@@ -35,7 +35,7 @@ import { IAttributePath, IFileInfo } from "../common/interfaces";
35
35
import { portal_schema_V2 } from "../schema/portalSchema" ;
36
36
import { ERROR_CONSTANTS } from "../../../common/ErrorConstants" ;
37
37
import { showErrorDialog } from "../../../common/utilities/errorHandlerUtil" ;
38
- import { EnableServerLogicChanges } from "../../../common/ecs-features/ecsFeatureGates" ;
38
+ import { EnableServerLogicChanges , EnableDuplicateFileHandling } from "../../../common/ecs-features/ecsFeatureGates" ;
39
39
import { ECSFeaturesClient } from "../../../common/ecs-features/ecsFeatureClient" ;
40
40
41
41
export async function fetchDataFromDataverseAndUpdateVFS (
@@ -345,44 +345,52 @@ async function processDataAndCreateFile(
345
345
// Handle webpage folder organization by root webpage ID
346
346
let actualFolderName = originalFolderName || fileName ;
347
347
if ( entityName === schemaEntityName . WEBPAGES ) {
348
- const webpageNames = WebExtensionContext . getWebpageNames ( ) ;
348
+ const { enableDuplicateFileHandling , disallowedDuplicateFileHandlingOrgs } = ECSFeaturesClient . getConfig ( EnableDuplicateFileHandling ) ;
349
349
350
- const effectiveRootWebPageId = rootWebPageId || WEBPAGE_FOLDER_CONSTANTS . NO_ROOT_PLACEHOLDER ;
351
- const rootWebPageIdKey = `${ fileName } ${ WEBPAGE_FOLDER_CONSTANTS . DELIMITER } ${ effectiveRootWebPageId } ` ;
350
+ // Check if feature is enabled and current org is not in the disable list
351
+ const isOrgDisabled = disallowedDuplicateFileHandlingOrgs &&
352
+ disallowedDuplicateFileHandlingOrgs . split ( ',' ) . map ( org => org . trim ( ) ) . includes ( WebExtensionContext . organizationId ) ;
352
353
353
- if ( ! webpageNames . has ( rootWebPageIdKey ) ) {
354
- // This is a new filename+rootWebPageId combination
355
- const existingEntriesForFileName = Array . from ( webpageNames ) . filter ( key => key . startsWith ( `${ fileName } ${ WEBPAGE_FOLDER_CONSTANTS . DELIMITER } ` ) ) ;
354
+ if ( enableDuplicateFileHandling && ! isOrgDisabled ) {
355
+ const webpageNames = WebExtensionContext . getWebpageNames ( ) ;
356
356
357
- if ( existingEntriesForFileName . length > 0 ) {
358
- // This filename already exists with a different root webpage ID
359
- // Create a suffixed folder name for this NEW root webpage ID group
360
- WebExtensionContext . telemetry . sendInfoTelemetry (
361
- webExtensionTelemetryEventNames . WEB_EXTENSION_DUPLICATE_FOLDER_NAME_CREATED ,
362
- { entityName : entityName , fileName : fileName , entityId : entityId , orgId : WebExtensionContext . organizationId , envId : WebExtensionContext . environmentId }
363
- ) ;
364
- // Use effective rootWebPageId for consistent naming
365
- actualFolderName = getDuplicateFileName ( fileName , effectiveRootWebPageId ) ;
366
- } else {
367
- // First occurrence of this filename - use original name
368
- }
357
+ const effectiveRootWebPageId = rootWebPageId || WEBPAGE_FOLDER_CONSTANTS . NO_ROOT_PLACEHOLDER ;
358
+ const rootWebPageIdKey = `${ fileName } ${ WEBPAGE_FOLDER_CONSTANTS . DELIMITER } ${ effectiveRootWebPageId } ` ;
369
359
370
- webpageNames . add ( rootWebPageIdKey ) ;
371
- } else {
372
- // We've seen this exact filename+rootWebPageId combination before
373
- // Determine which folder name was used for this specific root webpage ID group
374
- const existingEntriesForFileName = Array . from ( webpageNames ) . filter ( key => key . startsWith ( `${ fileName } ${ WEBPAGE_FOLDER_CONSTANTS . DELIMITER } ` ) ) ;
360
+ if ( ! webpageNames . has ( rootWebPageIdKey ) ) {
361
+ // This is a new filename+rootWebPageId combination
362
+ const existingEntriesForFileName = Array . from ( webpageNames ) . filter ( key => key . startsWith ( `${ fileName } ${ WEBPAGE_FOLDER_CONSTANTS . DELIMITER } ` ) ) ;
375
363
376
- // Extract and sort root webpage IDs to ensure consistent ordering
377
- const rootWebPageIds = existingEntriesForFileName . map ( key => key . split ( WEBPAGE_FOLDER_CONSTANTS . DELIMITER ) [ 1 ] ) . sort ( ) ;
378
- const currentEntryIndex = rootWebPageIds . indexOf ( effectiveRootWebPageId ) ;
364
+ if ( existingEntriesForFileName . length > 0 ) {
365
+ // This filename already exists with a different root webpage ID
366
+ // Create a suffixed folder name for this NEW root webpage ID group
367
+ WebExtensionContext . telemetry . sendInfoTelemetry (
368
+ webExtensionTelemetryEventNames . WEB_EXTENSION_DUPLICATE_FOLDER_NAME_CREATED ,
369
+ { entityName : entityName , fileName : fileName , entityId : entityId , orgId : WebExtensionContext . organizationId , envId : WebExtensionContext . environmentId }
370
+ ) ;
371
+ // Use effective rootWebPageId for consistent naming
372
+ actualFolderName = getDuplicateFileName ( fileName , effectiveRootWebPageId ) ;
373
+ } else {
374
+ // First occurrence of this filename - use original name
375
+ }
379
376
380
- if ( currentEntryIndex === 0 ) {
381
- // This is the first root webpage ID that was encountered for this filename
382
- actualFolderName = fileName ;
377
+ webpageNames . add ( rootWebPageIdKey ) ;
383
378
} else {
384
- // This is a subsequent root webpage ID - use suffixed folder name
385
- actualFolderName = getDuplicateFileName ( fileName , effectiveRootWebPageId ) ;
379
+ // We've seen this exact filename+rootWebPageId combination before
380
+ // Determine which folder name was used for this specific root webpage ID group
381
+ const existingEntriesForFileName = Array . from ( webpageNames ) . filter ( key => key . startsWith ( `${ fileName } ${ WEBPAGE_FOLDER_CONSTANTS . DELIMITER } ` ) ) ;
382
+
383
+ // Extract root webpage IDs preserving insertion order to maintain first folder logic
384
+ const rootWebPageIds = existingEntriesForFileName . map ( key => key . split ( WEBPAGE_FOLDER_CONSTANTS . DELIMITER ) [ 1 ] ) ;
385
+ const currentEntryIndex = rootWebPageIds . indexOf ( effectiveRootWebPageId ) ;
386
+
387
+ if ( currentEntryIndex === 0 ) {
388
+ // This is the first root webpage ID that was encountered for this filename
389
+ actualFolderName = fileName ;
390
+ } else {
391
+ // This is a subsequent root webpage ID - use suffixed folder name
392
+ actualFolderName = getDuplicateFileName ( fileName , effectiveRootWebPageId ) ;
393
+ }
386
394
}
387
395
}
388
396
} // Create folder directory if needed
0 commit comments