Skip to content

Commit 24b32db

Browse files
amitjoshi438Amit Joshi
andauthored
Preserve insertion order and add duplicate file handling feature flag (#1310)
* Preserve insertion order of root webpage IDs in processDataAndCreateFile function * Add feature flag for duplicate file handling in webpage folders --------- Co-authored-by: Amit Joshi <[email protected]>
1 parent 79a2ee8 commit 24b32db

File tree

2 files changed

+51
-32
lines changed

2 files changed

+51
-32
lines changed

src/common/ecs-features/ecsFeatureGates.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,14 @@ export const {
109109
enableOpenInDesktop: false,
110110
}
111111
});
112+
113+
export const {
114+
feature: EnableDuplicateFileHandling
115+
} = getFeatureConfigs({
116+
teamName: PowerPagesClientName,
117+
description: 'Enable duplicate file handling for webpage folders',
118+
fallback: {
119+
enableDuplicateFileHandling: true,
120+
disallowedDuplicateFileHandlingOrgs: "",
121+
}
122+
});

src/web/client/dal/remoteFetchProvider.ts

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { IAttributePath, IFileInfo } from "../common/interfaces";
3535
import { portal_schema_V2 } from "../schema/portalSchema";
3636
import { ERROR_CONSTANTS } from "../../../common/ErrorConstants";
3737
import { showErrorDialog } from "../../../common/utilities/errorHandlerUtil";
38-
import { EnableServerLogicChanges } from "../../../common/ecs-features/ecsFeatureGates";
38+
import { EnableServerLogicChanges, EnableDuplicateFileHandling } from "../../../common/ecs-features/ecsFeatureGates";
3939
import { ECSFeaturesClient } from "../../../common/ecs-features/ecsFeatureClient";
4040

4141
export async function fetchDataFromDataverseAndUpdateVFS(
@@ -345,44 +345,52 @@ async function processDataAndCreateFile(
345345
// Handle webpage folder organization by root webpage ID
346346
let actualFolderName = originalFolderName || fileName;
347347
if (entityName === schemaEntityName.WEBPAGES) {
348-
const webpageNames = WebExtensionContext.getWebpageNames();
348+
const { enableDuplicateFileHandling, disallowedDuplicateFileHandlingOrgs } = ECSFeaturesClient.getConfig(EnableDuplicateFileHandling);
349349

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);
352353

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();
356356

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}`;
369359

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}`));
375363

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+
}
379376

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);
383378
} 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+
}
386394
}
387395
}
388396
} // Create folder directory if needed

0 commit comments

Comments
 (0)