Skip to content

Commit

Permalink
Fix issue sorting overriden categories on grid (#725)
Browse files Browse the repository at this point in the history
Signed-off-by: Cintia Sánchez García <[email protected]>
  • Loading branch information
cynthia-sg authored Oct 15, 2024
1 parent ac348c9 commit bf6f2c0
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion ui/webapp/src/utils/itemsDataGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,42 @@ export class ItemsDataGetter {
}
});
}
return data;

return this.sortSubcategoriesInGridData(data);
}

private sortSubcategoriesInGridData = (data: GroupData): GroupData => {
const sortedData: GroupData = {};

Object.keys(data).forEach((group: string) => {
sortedData[group] = {};
Object.keys(data[group]).forEach((category: string) => {
const isOverriden =
!isUndefined(window.baseDS.categories_overridden) && window.baseDS.categories_overridden.includes(category);
if (!isOverriden) {
sortedData[group][category] = data[group][category];
} else {
const currentCategory = window.baseDS.categories.find((c: Category) => c.name === category);
if (currentCategory && currentCategory.subcategories) {
const subcategories = currentCategory.subcategories.map((s: Subcategory) => s.name);
const sortedSubcategories: { [key: string]: SubcategoryData } = {};
subcategories.forEach((subcat: string) => {
if (data[group][category][subcat]) {
sortedSubcategories[subcat] = data[group][category][subcat];
}
});
sortedData[group][category] = sortedSubcategories;
} else {
sortedData[group][category] = data[group][category];
}
}
});
});

console.log(sortedData);
return sortedData;
};

public getGridData(withAllOption: boolean): GroupData {
return this.prepareGridData(this.getGroupedData(), withAllOption);
}
Expand Down

0 comments on commit bf6f2c0

Please sign in to comment.