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

HLM 6210 #858

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ const useParallelSearch = async ({ parentArray, tenantId, boundaryType, hierarch

return cacheData?.filter((obj) => validParentCodes?.has(obj?.parentCode));
}

function checkremoveMissingParentCodes(cacheData, parentArray) {
const validParentCodes = new Set(parentArray);
return cacheData?.filter((obj) => !validParentCodes?.has(obj?.parentCode));
}

function checkParentCodePresence(data, array) {
return array.every((item) => data.some((entry) => entry.parentCode === item));
}
if (parentArray?.length > cacheData?.[targetedData]?.length) {
missingParent = findMissingCodes(parentArray, cacheData?.[targetedData]);
const requests = missingParent.map((parentCode) => {
Expand All @@ -50,7 +54,7 @@ const useParallelSearch = async ({ parentArray, tenantId, boundaryType, hierarch
const setcacheData = { ...cacheData, [targetedData]: cacheData?.[targetedData] ? [...cacheData?.[targetedData], ...newData] : [...newData] };
window.Digit.SessionStorage.set("HCM_CAMPAIGN_BOUNDARY_DATA", setcacheData);
return setcacheData?.[targetedData];
} else if (cacheData?.[targetedData]?.length > parentArray?.length) {
} else if (cacheData?.[targetedData]?.length > parentArray?.length && checkParentCodePresence(cacheData?.[targetedData], parentArray)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing unnecessary else clauses.

The else clause here can be omitted for cleaner code, as the previous branches return early. This would make the code more readable and reduce nesting.

-  } else if (cacheData?.[targetedData]?.length > parentArray?.length && checkParentCodePresence(cacheData?.[targetedData], parentArray)) {
+  if (cacheData?.[targetedData]?.length > parentArray?.length && checkParentCodePresence(cacheData?.[targetedData], parentArray)) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (cacheData?.[targetedData]?.length > parentArray?.length && checkParentCodePresence(cacheData?.[targetedData], parentArray)) {
if (cacheData?.[targetedData]?.length > parentArray?.length && checkParentCodePresence(cacheData?.[targetedData], parentArray)) {
Tools
Biome

[error] 57-85: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

removeData = removeMissingParentCodes(cacheData?.[targetedData], parentArray);
const setcacheData = { ...cacheData, [targetedData]: [...removeData] };
// window.Digit.SessionStorage.set("HCM_CAMPAIGN_BOUNDARY_DATA", setcacheData);
Expand Down
Loading