Files
Matt Aitken f90960fc13 Better display when there are lots of dev environment (#1093)
* Created an EnvironmentLabels component that puts extra dev environments behind a +

* Added new environment labels components to schedules pages
2024-05-09 10:32:38 +01:00

32 lines
781 B
TypeScript

import { RuntimeEnvironmentType } from "@trigger.dev/database";
const environmentSortOrder: RuntimeEnvironmentType[] = [
"DEVELOPMENT",
"PREVIEW",
"STAGING",
"PRODUCTION",
];
type SortType = {
type: RuntimeEnvironmentType;
userName?: string | null;
};
export function sortEnvironments<T extends SortType>(environments: T[]): T[] {
return environments.sort((a, b) => {
const aIndex = environmentSortOrder.indexOf(a.type);
const bIndex = environmentSortOrder.indexOf(b.type);
const difference = aIndex - bIndex;
if (difference === 0) {
//same environment so sort by name
const usernameA = a.userName || "";
const usernameB = b.userName || "";
return usernameA.localeCompare(usernameB);
}
return difference;
});
}