From 94cac01b964cf85ee46446ead7506c82e8d042ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cintia=20S=C3=A1nchez=20Garc=C3=ADa?= Date: Wed, 22 Apr 2026 21:16:58 +0200 Subject: [PATCH] Fix grid category sorting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cintia Sánchez García --- ui/webapp/src/layout/explore/Content.tsx | 2 - ui/webapp/src/layout/explore/card/Content.tsx | 3 +- ui/webapp/src/layout/explore/card/index.tsx | 1 - ui/webapp/src/layout/explore/index.tsx | 1 - ui/webapp/src/utils/itemsDataGetter.ts | 3 +- .../utils/sortCategoriesByGroupOrder.test.ts | 45 +++++++++++++++++++ .../src/utils/sortCategoriesByGroupOrder.ts | 26 +++++++++++ 7 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 ui/webapp/src/utils/sortCategoriesByGroupOrder.test.ts create mode 100644 ui/webapp/src/utils/sortCategoriesByGroupOrder.ts diff --git a/ui/webapp/src/layout/explore/Content.tsx b/ui/webapp/src/layout/explore/Content.tsx index 52da70e7..c7fb3d21 100644 --- a/ui/webapp/src/layout/explore/Content.tsx +++ b/ui/webapp/src/layout/explore/Content.tsx @@ -1,6 +1,5 @@ import isUndefined from 'lodash/isUndefined'; -import { ALL_OPTION } from '../../data'; import { CardMenu, ClassifyOption, SortDirection, SortOption, ViewMode } from '../../types'; import { CategoriesData } from '../../utils/itemsDataGetter'; import { useViewMode } from '../stores/viewMode'; @@ -28,7 +27,6 @@ const Content = (props: Props) => {
{ const Content = (props: Props) => { const bgColor = COLORS[0]; const data = () => props.data(); + const getTitles = (): string[] => sortMaturityStatusTitles(Object.keys(data())); const getSubtitles = (content: { [key: string]: unknown }, title: string): string[] => { let subtitles = Object.keys(content).sort(); @@ -100,7 +101,7 @@ const Content = (props: Props) => { - + {(title: string) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const content = () => (data() as any)[title] as { [key: string]: unknown } | (BaseItem | Item)[]; diff --git a/ui/webapp/src/layout/explore/card/index.tsx b/ui/webapp/src/layout/explore/card/index.tsx index 02a1b383..3624e7f5 100644 --- a/ui/webapp/src/layout/explore/card/index.tsx +++ b/ui/webapp/src/layout/explore/card/index.tsx @@ -17,7 +17,6 @@ import Menu from './Menu'; interface Props { initialIsVisible: boolean; - group: string; classify: ClassifyOption; sorted: SortOption; direction: SortDirection; diff --git a/ui/webapp/src/layout/explore/index.tsx b/ui/webapp/src/layout/explore/index.tsx index 6cd0d5c3..bb8950a1 100644 --- a/ui/webapp/src/layout/explore/index.tsx +++ b/ui/webapp/src/layout/explore/index.tsx @@ -999,7 +999,6 @@ const Explore = (props: Props) => { initialIsVisible={viewMode() === ViewMode.Card && selectedGroup() === ALL_OPTION} data={!isUndefined(cardData()) ? cardData()![ALL_OPTION] : undefined} menu={!isUndefined(cardMenu()) ? cardMenu()![ALL_OPTION] : undefined} - group={ALL_OPTION} classify={classify()} sorted={sorted()} direction={sortDirection()} diff --git a/ui/webapp/src/utils/itemsDataGetter.ts b/ui/webapp/src/utils/itemsDataGetter.ts index 5bdb1a1f..3d788316 100644 --- a/ui/webapp/src/utils/itemsDataGetter.ts +++ b/ui/webapp/src/utils/itemsDataGetter.ts @@ -33,6 +33,7 @@ import { import checkIfCategoryInGroup from './checkIfCategoryInGroup'; import filterData from './filterData'; import search from './search'; +import sortCategoriesByGroupOrder from './sortCategoriesByGroupOrder'; import sortMenuOptions from './sortMenuOptions'; export interface ItemsDataStatus { @@ -532,7 +533,7 @@ export class ItemsDataGetter { Object.keys(data).forEach((group: string) => { sortedData[group] = {}; - Object.keys(data[group]).forEach((category: string) => { + sortCategoriesByGroupOrder(Object.keys(data[group]), group).forEach((category: string) => { const isOverriden = !isUndefined(window.baseDS.categories_overridden) && window.baseDS.categories_overridden.includes(category); if (!isOverriden) { diff --git a/ui/webapp/src/utils/sortCategoriesByGroupOrder.test.ts b/ui/webapp/src/utils/sortCategoriesByGroupOrder.test.ts new file mode 100644 index 00000000..93833569 --- /dev/null +++ b/ui/webapp/src/utils/sortCategoriesByGroupOrder.test.ts @@ -0,0 +1,45 @@ +import { BaseData, Group } from '../types'; +import sortCategoriesByGroupOrder from './sortCategoriesByGroupOrder'; + +const createGroup = (overrides: Partial = {}): Group => ({ + name: 'AI Native', + normalized_name: 'ai-native', + categories: ['AI Agent', 'Inference', 'Training', 'Data', 'AI Native Infra'], + ...overrides, +}); + +const createBaseData = (overrides: Partial = {}): BaseData => ({ + finances_available: false, + foundation: '', + categories: [], + items: [], + ...overrides, +}); + +describe('sortCategoriesByGroupOrder', () => { + it('should follow the configured group category order', () => { + window.baseDS = createBaseData({ + groups: [createGroup()], + }); + + expect(sortCategoriesByGroupOrder(['AI Agent', 'Training', 'Data', 'Inference'], 'ai-native')).toEqual([ + 'AI Agent', + 'Inference', + 'Training', + 'Data', + ]); + }); + + it('should keep categories unchanged for the all group option', () => { + window.baseDS = createBaseData({ + groups: [createGroup()], + }); + + expect(sortCategoriesByGroupOrder(['AI Agent', 'Training', 'Data', 'Inference'], 'all')).toEqual([ + 'AI Agent', + 'Training', + 'Data', + 'Inference', + ]); + }); +}); diff --git a/ui/webapp/src/utils/sortCategoriesByGroupOrder.ts b/ui/webapp/src/utils/sortCategoriesByGroupOrder.ts new file mode 100644 index 00000000..0adc8213 --- /dev/null +++ b/ui/webapp/src/utils/sortCategoriesByGroupOrder.ts @@ -0,0 +1,26 @@ +import intersection from 'lodash/intersection'; + +import { Group } from '../types'; + +const ALL_GROUP = 'all'; + +/** + * Sort category names using the order configured for the selected group. + */ +const sortCategoriesByGroupOrder = (categories: string[], group: string): string[] => { + if (group === ALL_GROUP || !window.baseDS.groups) { + return categories; + } + + const selectedGroup = window.baseDS.groups.find((item: Group) => item.normalized_name === group); + if (!selectedGroup) { + return categories; + } + + const orderedCategories = intersection(selectedGroup.categories, categories); + const remainingCategories = categories.filter((category: string) => !orderedCategories.includes(category)); + + return [...orderedCategories, ...remainingCategories]; +}; + +export default sortCategoriesByGroupOrder;