Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update boundaryUtils.ts #1074

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions utilities/boundary-bulk-bff/src/server/utils/boundaryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,37 @@ function generateElementCode(sequence: any, parentElement: any, parentBoundaryCo
return code.trim();
}

function modifyElementCodesMap(elementCodesMap: any) {
const set = new Set<string>();
const specialCharsRegex = /[^\w\s]/g; // Regular expression to match any character that is not a word character or space

// Iterate over each [key, value] pair in elementCodesMap using forEach
elementCodesMap.forEach((value: any, key: any) => {
let modifiedValue = value.replace(specialCharsRegex, '_').trim(); // Replace special characters and spaces with underscore
let modifiedTempValue = modifiedValue; // Store the initial modified value
let count = 1;

// Generate a unique modified value
while (set.has(modifiedValue)) {
// If it exists, append _<count> to modifiedValue
modifiedValue = `${modifiedTempValue}_${count}`;
count++;
}

// Add the modified (or original) value to the set
set.add(modifiedValue);

// Update the map with the modified value
elementCodesMap.set(key, modifiedValue);
});

}






async function getAutoGeneratedBoundaryCodes(boundaryList: any, childParentMap: any, elementCodesMap: any, countMap: any, request: any) {
// Initialize an array to store column data
const columnsData: { key: string, value: string }[][] = [];
Expand Down Expand Up @@ -301,6 +332,7 @@ async function getAutoGeneratedBoundaryCodes(boundaryList: any, childParentMap:
}
}
}
modifyElementCodesMap(elementCodesMap)
return elementCodesMap; // Return the updated element codes map
}

Expand Down
Loading