Sort workspace routines by name (#8666)
Reviewed by CTO for PAP-12039. Client-side ordering change only, with focused helper coverage; CI, security scans, and Greptile are green. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
32ef854771
commit
574543d7d3
|
|
@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
|
|||
import {
|
||||
getWorkspaceSpecificRoutineVariableNames,
|
||||
routineHasWorkspaceSpecificVariables,
|
||||
sortWorkspaceRoutinesByName,
|
||||
} from "./workspace-routines";
|
||||
|
||||
function createRoutine(overrides: Partial<RoutineListItem> = {}): RoutineListItem {
|
||||
|
|
@ -68,4 +69,31 @@ describe("workspace routine helpers", () => {
|
|||
|
||||
expect(routineHasWorkspaceSpecificVariables(routine)).toBe(false);
|
||||
});
|
||||
|
||||
it("sorts workspace routines by name regardless of update order", () => {
|
||||
const routines = [
|
||||
createRoutine({
|
||||
id: "routine-2",
|
||||
title: "zeta review",
|
||||
updatedAt: new Date("2026-05-02T00:00:00.000Z"),
|
||||
}),
|
||||
createRoutine({
|
||||
id: "routine-3",
|
||||
title: "Alpha review",
|
||||
updatedAt: new Date("2026-04-30T00:00:00.000Z"),
|
||||
}),
|
||||
createRoutine({
|
||||
id: "routine-1",
|
||||
title: "alpha review",
|
||||
updatedAt: new Date("2026-05-03T00:00:00.000Z"),
|
||||
}),
|
||||
];
|
||||
|
||||
expect(sortWorkspaceRoutinesByName(routines).map((routine) => routine.id)).toEqual([
|
||||
"routine-1",
|
||||
"routine-3",
|
||||
"routine-2",
|
||||
]);
|
||||
expect(routines.map((routine) => routine.id)).toEqual(["routine-2", "routine-3", "routine-1"]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -29,3 +29,11 @@ export function getWorkspaceSpecificRoutineVariableNames(routine: RoutineListIte
|
|||
export function routineHasWorkspaceSpecificVariables(routine: RoutineListItem): boolean {
|
||||
return getWorkspaceSpecificRoutineVariableNames(routine).length > 0;
|
||||
}
|
||||
|
||||
export function sortWorkspaceRoutinesByName(routines: RoutineListItem[]): RoutineListItem[] {
|
||||
return [...routines].sort((left, right) => {
|
||||
const titleOrder = left.title.localeCompare(right.title, undefined, { sensitivity: "base" });
|
||||
if (titleOrder !== 0) return titleOrder;
|
||||
return left.id.localeCompare(right.id);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import { cn, formatDateTime, issueUrl, projectRouteRef, projectWorkspaceUrl } fr
|
|||
import {
|
||||
getWorkspaceSpecificRoutineVariableNames,
|
||||
routineHasWorkspaceSpecificVariables,
|
||||
sortWorkspaceRoutinesByName,
|
||||
} from "../lib/workspace-routines";
|
||||
|
||||
type WorkspaceFormState = {
|
||||
|
|
@ -445,7 +446,7 @@ function ExecutionWorkspaceRoutinesList({
|
|||
});
|
||||
|
||||
const workspaceRoutines = useMemo(
|
||||
() => (routines ?? []).filter(routineHasWorkspaceSpecificVariables),
|
||||
() => sortWorkspaceRoutinesByName((routines ?? []).filter(routineHasWorkspaceSpecificVariables)),
|
||||
[routines],
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue