Skip to content

Commit

Permalink
Change mergeCategories
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasDov committed Sep 20, 2024
1 parent 9219ccb commit 1ca9aaa
Showing 1 changed file with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,19 @@ class MergingPropertyDataProviderImpl implements IMergingPropertyDataProvider {
}

private mergeCategories(dataArray: PropertyData[]): PropertyCategory[] {
const mergedCategories = new Array<PropertyCategory>();
dataArray.forEach((data) => {
for (const category of data.categories) {
const mergedCategoryIndex = mergedCategories.findIndex(
(mergedCat) => mergedCat.name === category.name
);
if (mergedCategoryIndex === -1) {
mergedCategories.push(category);
continue;
}
let mergedCategories: PropertyCategory[] | undefined;
if (dataArray.length > 0) {
mergedCategories = [...dataArray[0].categories];
}

const newChildCategories = this.mergeChildCategories(
mergedCategories[mergedCategoryIndex].childCategories,
category.childCategories
);
mergedCategories[mergedCategoryIndex] = {
...mergedCategories[mergedCategoryIndex],
...(newChildCategories
? { childCategories: [...newChildCategories] }
: {}),
};
}
});
for (let i = 1; i < dataArray.length; ++i) {
mergedCategories = this.mergeChildCategories(
mergedCategories,
dataArray[i].categories
);
}

return [...mergedCategories];
return mergedCategories ?? [];
}

private mergeChildCategories(
Expand Down Expand Up @@ -166,12 +154,10 @@ class MergingPropertyDataProviderImpl implements IMergingPropertyDataProvider {
);
mergedCategories[childCategoryIndex] = {
...mergedCategories[childCategoryIndex],
...(newChildCategories
? { childCategories: newChildCategories }
: {}),
...(newChildCategories ? { childCategories: newChildCategories } : {}),
};
}
return [...mergedCategories];
return mergedCategories;
}

private mergeRecords(dataArray: PropertyData[]): {
Expand Down

0 comments on commit 1ca9aaa

Please sign in to comment.