2f82381Update benchmark results from 2025-07-24 16:44:35 [skip ci]GitHub Actions Bot 1export type TabAction =
2 | { type: "ADD_TAB"; payload: { id: string; label: string; route: string } }
3 | { type: "SET_ACTIVE_TAB"; payload: string }
4 | { type: "CLOSE_TAB"; payload: string }
5 | { type: "REORDER_TABS"; payload: { fromIndex: number; toIndex: number } };
7export interface TabItem {
8 id: string;
9 label: string;
10 route: string;
11}
13export interface TabsState {
14 tabs: TabItem[];
15 activeTabId: string;
16}
18const initialState: TabsState = {
19 tabs: [
20 { id: "datasets", label: "Datasets", route: "/datasets" },
21 { id: "algorithms", label: "Algorithms", route: "/algorithms" },
22 ],
23 activeTabId: "datasets",
24};
26export function tabsReducer(
27 state: TabsState = initialState,
28 action: TabAction,
29): TabsState {
30 switch (action.type) {
31 case "ADD_TAB": {
32 // If tab already exists, just set it as active
33 if (state.tabs.some((tab) => tab.id === action.payload.id)) {
34 return {
35 ...state,
36 activeTabId: action.payload.id,
37 };
38 }
40 // Otherwise add new tab
41 return {
42 ...state,
43 tabs: [...state.tabs, action.payload],
44 activeTabId: action.payload.id,
45 };
46 }
47 case "SET_ACTIVE_TAB":
48 return {
49 ...state,
50 activeTabId: action.payload,
51 };
52 case "REORDER_TABS": {
53 const newTabs = [...state.tabs];
54 const [movedTab] = newTabs.splice(action.payload.fromIndex, 1);
55 newTabs.splice(action.payload.toIndex, 0, movedTab);
56 return {
57 ...state,
58 tabs: newTabs,
59 };
60 }
61 case "CLOSE_TAB": {
62 // Don't allow closing of datasets or algorithms tabs
63 if (action.payload === "datasets" || action.payload === "algorithms") {
64 return state;
65 }
67 const newTabs = state.tabs.filter((tab) => tab.id !== action.payload);
69 // If we're closing the active tab, activate the last tab in the list
70 if (state.activeTabId === action.payload) {
71 return {
72 tabs: newTabs,
73 activeTabId: newTabs[newTabs.length - 1].id,
74 };
75 }
77 return {
78 ...state,
79 tabs: newTabs,
80 };
81 }
82 default:
83 return state;
84 }
85}