Files
triggerdotdev--trigger.dev/apps/webapp/app/utils/environmentSort.ts
Matt Aitken bee59de3a0 Concurrency self serve (#2681)
* Don't use the organization max concurrency anymore

* Early draft of the concurrency page

* WIP adding a new stepper input component

* Move stepper to be alphabetical

* When max value is reached, disabled the + button

* Show placeholder if you delete all numbers

* Make all the html input values available to the component

* Adds size variants

* Move stepper into its own component

* Work on showing the extra concurrency

* The purchase form styling and functionality (minus actually purchasing)

* New style for outline input fields

* Concurrency purchasing working

* Purchasing concurrency and quota emails working

* Improvements to the modal

* Show cost breakdown in the modal

* Fix for allocated concurrency including DEV

* Improved types

* Allocating concurrency is working

* Live updates total env concurrency

* Implemented reset

* Fix for concurrency allocation editing across multiple projects

* Tabular numbers

* Added an error from allocating concurrency

* Fixes for allocating concurrency where it didn't calculate correctly

* "Increase limit" link to concurrency page

* Indent environments

* Added Preview limit when updating concurrency for an org

* Show error when changing plan fails

* Added maximumProjectCount column to Org

* Limit project count and display a rich error toast (with title and button now)

* Added title and button to toasts. Use it for new project error

* @trigger.dev/platform 1.0.20

* Allow submitting zero concurrency so you can downgrade back to nothing

* Use the server as the truth for omitted environments

* Updated the pricing panels

---------

Co-authored-by: James Ritchie <james@trigger.dev>
2025-11-19 11:22:23 +00:00

73 lines
1.8 KiB
TypeScript

import { type RuntimeEnvironmentType } from "@trigger.dev/database";
const environmentSortOrder: RuntimeEnvironmentType[] = [
"DEVELOPMENT",
"STAGING",
"PREVIEW",
"PRODUCTION",
];
type SortType = {
type: RuntimeEnvironmentType;
userName?: string | null;
};
export function sortEnvironments<T extends SortType>(
environments: T[],
sortOrder?: RuntimeEnvironmentType[]
): T[] {
const order = sortOrder ?? environmentSortOrder;
return environments.sort((a, b) => {
const aIndex = order.indexOf(a.type);
const bIndex = order.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;
});
}
type FilterableEnvironment =
| {
type: RuntimeEnvironmentType;
orgMemberId?: string;
}
| {
type: RuntimeEnvironmentType;
//intentionally vague so we can match anything
orgMember?: Record<string, any>;
};
export function filterOrphanedEnvironments<T extends FilterableEnvironment>(
environments: T[]
): T[] {
return environments.filter((environment) => {
if (environment.type !== "DEVELOPMENT") return true;
if ("orgMemberId" in environment) {
return !!environment.orgMemberId;
}
if ("orgMember" in environment) {
return !!environment.orgMember;
}
return false;
});
}
export function onlyDevEnvironments<T extends FilterableEnvironment>(environments: T[]): T[] {
return environments.filter((e) => e.type === "DEVELOPMENT");
}
export function exceptDevEnvironments<T extends FilterableEnvironment>(environments: T[]): T[] {
return environments.filter((e) => e.type !== "DEVELOPMENT");
}