Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions ui/webapp/src/layout/explore/Content.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -28,7 +27,6 @@ const Content = (props: Props) => {
<div class={selectedViewMode() === ViewMode.Card ? 'd-block' : 'd-none'}>
<CardCategory
initialIsVisible={isSelected() && selectedViewMode() === ViewMode.Card}
group={props.group || ALL_OPTION}
data={props.cardData}
menu={props.menu}
classify={props.classify}
Expand Down
3 changes: 2 additions & 1 deletion ui/webapp/src/layout/explore/card/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const CardList = (props: ListProps) => {
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();
Expand Down Expand Up @@ -100,7 +101,7 @@ const Content = (props: Props) => {
<CardList items={data()} isVisible={props.isVisible} sorted={props.sorted} direction={props.direction} />
</Match>
<Match when={!Array.isArray(data())}>
<For each={sortMaturityStatusTitles(Object.keys(data()))}>
<For each={getTitles()}>
{(title: string) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const content = () => (data() as any)[title] as { [key: string]: unknown } | (BaseItem | Item)[];
Expand Down
1 change: 0 additions & 1 deletion ui/webapp/src/layout/explore/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Menu from './Menu';

interface Props {
initialIsVisible: boolean;
group: string;
classify: ClassifyOption;
sorted: SortOption;
direction: SortDirection;
Expand Down
1 change: 0 additions & 1 deletion ui/webapp/src/layout/explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down
3 changes: 2 additions & 1 deletion ui/webapp/src/utils/itemsDataGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
45 changes: 45 additions & 0 deletions ui/webapp/src/utils/sortCategoriesByGroupOrder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BaseData, Group } from '../types';
import sortCategoriesByGroupOrder from './sortCategoriesByGroupOrder';

const createGroup = (overrides: Partial<Group> = {}): Group => ({
name: 'AI Native',
normalized_name: 'ai-native',
categories: ['AI Agent', 'Inference', 'Training', 'Data', 'AI Native Infra'],
...overrides,
});

const createBaseData = (overrides: Partial<BaseData> = {}): 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',
]);
});
});
26 changes: 26 additions & 0 deletions ui/webapp/src/utils/sortCategoriesByGroupOrder.ts
Original file line number Diff line number Diff line change
@@ -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;