-
-
Notifications
You must be signed in to change notification settings - Fork 889
Concurrency self serve #2681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matt-aitken
wants to merge
33
commits into
main
Choose a base branch
from
concurrency-self-serve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Concurrency self serve #2681
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
2e783a9
Don't use the organization max concurrency anymore
matt-aitken 8a0806b
Early draft of the concurrency page
matt-aitken 97a2166
WIP adding a new stepper input component
samejr 2493178
Move stepper to be alphabetical
samejr 67ce871
When max value is reached, disabled the + button
samejr fc1bb53
Show placeholder if you delete all numbers
samejr c7bab5a
Make all the html input values available to the component
samejr 10dd95e
Adds size variants
samejr c1ed3ad
Move stepper into its own component
samejr 0a7b7bb
Work on showing the extra concurrency
matt-aitken 5316b80
The purchase form styling and functionality (minus actually purchasing)
matt-aitken f3598d3
New style for outline input fields
samejr de4d809
Concurrency purchasing working
matt-aitken 98ecc09
Purchasing concurrency and quota emails working
matt-aitken 306a45d
Improvements to the modal
matt-aitken c906825
Show cost breakdown in the modal
matt-aitken b53c919
Fix for allocated concurrency including DEV
matt-aitken 8ebb59c
Improved types
matt-aitken 941dd37
Allocating concurrency is working
matt-aitken cdfb94c
Live updates total env concurrency
matt-aitken 27a9325
Implemented reset
matt-aitken 847a00f
Fix for concurrency allocation editing across multiple projects
matt-aitken 0f201fe
Tabular numbers
matt-aitken e9c1130
Added an error from allocating concurrency
matt-aitken 785814d
Fixes for allocating concurrency where it didn't calculate correctly
matt-aitken ef86239
"Increase limit" link to concurrency page
matt-aitken 0244c3c
Indent environments
matt-aitken d95dc53
Added Preview limit when updating concurrency for an org
matt-aitken aa63a33
Show error when changing plan fails
matt-aitken d0f3682
Added maximumProjectCount column to Org
matt-aitken bef88f6
Limit project count and display a rich error toast (with title and bu…
matt-aitken f54b3df
Added title and button to toasts. Use it for new project error
matt-aitken 8d2dbbc
@trigger.dev/platform 1.0.20
matt-aitken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export function ConcurrencyIcon({ className }: { className?: string }) { | ||
| return ( | ||
| <svg className={className} viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
| <circle cx="3.75" cy="3.75" r="2.25" fill="currentColor" /> | ||
| <circle cx="9" cy="3.75" r="2.25" fill="currentColor" /> | ||
| <circle cx="14.25" cy="3.75" r="2.25" fill="currentColor" /> | ||
| <circle cx="3.75" cy="9" r="2.25" fill="currentColor" /> | ||
| <circle cx="9" cy="9" r="2.25" fill="currentColor" /> | ||
| <circle cx="9" cy="14.25" r="1.75" stroke="currentColor" /> | ||
| <circle cx="14.25" cy="9" r="2.25" fill="currentColor" /> | ||
| </svg> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
220 changes: 220 additions & 0 deletions
220
apps/webapp/app/components/primitives/InputNumberStepper.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| import { MinusIcon, PlusIcon } from "@heroicons/react/20/solid"; | ||
| import { type ChangeEvent, useRef } from "react"; | ||
| import { cn } from "~/utils/cn"; | ||
|
|
||
| type InputNumberStepperProps = Omit<JSX.IntrinsicElements["input"], "min" | "max" | "step"> & { | ||
| step?: number; | ||
| min?: number; | ||
| max?: number; | ||
| round?: boolean; | ||
| controlSize?: "base" | "large"; | ||
| }; | ||
|
|
||
| export function InputNumberStepper({ | ||
| value, | ||
| onChange, | ||
| step = 50, | ||
| min, | ||
| max, | ||
| round = true, | ||
| controlSize = "base", | ||
| name, | ||
| id, | ||
| disabled = false, | ||
| readOnly = false, | ||
| className, | ||
| placeholder = "Type a number", | ||
| ...props | ||
| }: InputNumberStepperProps) { | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| const handleStepUp = () => { | ||
| if (!inputRef.current || disabled) return; | ||
|
|
||
| // If rounding is enabled, ensure we start from a rounded base before stepping | ||
| if (round) { | ||
| // If field is empty, treat as 0 (or min if provided) before stepping up | ||
| if (inputRef.current.value === "") { | ||
| inputRef.current.value = String(min ?? 0); | ||
| } else { | ||
| commitRoundedFromInput(); | ||
| } | ||
| } | ||
| inputRef.current.stepUp(); | ||
| const event = new Event("change", { bubbles: true }); | ||
| inputRef.current.dispatchEvent(event); | ||
| }; | ||
|
|
||
| const handleStepDown = () => { | ||
| if (!inputRef.current || disabled) return; | ||
|
|
||
| // If rounding is enabled, ensure we start from a rounded base before stepping | ||
| if (round) { | ||
| // If field is empty, treat as 0 (or min if provided) before stepping down | ||
| if (inputRef.current.value === "") { | ||
| inputRef.current.value = String(min ?? 0); | ||
| } else { | ||
| commitRoundedFromInput(); | ||
| } | ||
| } | ||
| inputRef.current.stepDown(); | ||
| const event = new Event("change", { bubbles: true }); | ||
| inputRef.current.dispatchEvent(event); | ||
| }; | ||
matt-aitken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const numericValue = value === "" ? NaN : (value as number); | ||
| const isMinDisabled = min !== undefined && !Number.isNaN(numericValue) && numericValue <= min; | ||
| const isMaxDisabled = max !== undefined && !Number.isNaN(numericValue) && numericValue >= max; | ||
|
|
||
| function clamp(val: number): number { | ||
| if (Number.isNaN(val)) return typeof value === "number" ? value : min ?? 0; | ||
| let next = val; | ||
| if (min !== undefined) next = Math.max(min, next); | ||
| if (max !== undefined) next = Math.min(max, next); | ||
| return next; | ||
| } | ||
|
|
||
| function roundToStep(val: number): number { | ||
| if (step <= 0) return val; | ||
| const base = min ?? 0; | ||
| const shifted = val - base; | ||
| const quotient = shifted / step; | ||
| const floored = Math.floor(quotient); | ||
| const ceiled = Math.ceil(quotient); | ||
| const down = base + floored * step; | ||
| const up = base + ceiled * step; | ||
| const distDown = Math.abs(val - down); | ||
| const distUp = Math.abs(up - val); | ||
| return distUp < distDown ? up : down; | ||
| } | ||
|
|
||
| function commitRoundedFromInput() { | ||
| if (!inputRef.current || disabled || readOnly) return; | ||
| const el = inputRef.current; | ||
| const raw = el.value; | ||
| if (raw === "") return; // do not coerce empty to 0; keep placeholder visible | ||
| const numeric = Number(raw); | ||
| if (Number.isNaN(numeric)) return; // ignore non-numeric | ||
| const rounded = clamp(roundToStep(numeric)); | ||
| if (String(rounded) === String(value)) return; | ||
| // Update the real input's value for immediate UI feedback | ||
| el.value = String(rounded); | ||
| // Invoke consumer onChange with the real element as target/currentTarget | ||
| onChange?.({ | ||
| target: el, | ||
| currentTarget: el, | ||
| } as unknown as ChangeEvent<HTMLInputElement>); | ||
| } | ||
|
|
||
| const sizeStyles = { | ||
| base: { | ||
| container: "h-9", | ||
| input: "text-sm px-3", | ||
| button: "size-6", | ||
| icon: "size-3.5", | ||
| gap: "gap-1 pr-1.5", | ||
| }, | ||
| large: { | ||
| container: "h-11 rounded-md", | ||
| input: "text-base px-3.5", | ||
| button: "size-8", | ||
| icon: "size-5", | ||
| gap: "gap-[0.3125rem] pr-[0.3125rem]", | ||
| }, | ||
| } as const; | ||
|
|
||
| const size = sizeStyles[controlSize]; | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| "flex items-center rounded border border-charcoal-600 bg-tertiary transition hover:border-charcoal-550/80 hover:bg-charcoal-600/80", | ||
| size.container, | ||
| "has-[:focus-visible]:outline has-[:focus-visible]:outline-1 has-[:focus-visible]:outline-offset-0 has-[:focus-visible]:outline-text-link", | ||
| disabled && "cursor-not-allowed opacity-50", | ||
| className | ||
| )} | ||
| > | ||
| <input | ||
| ref={inputRef} | ||
| type="number" | ||
| id={id} | ||
| name={name} | ||
| value={value} | ||
| placeholder={placeholder} | ||
| onChange={(e) => { | ||
| // Allow empty string to pass through so user can clear the field | ||
| if (e.currentTarget.value === "") { | ||
| // reflect emptiness in the input and notify consumer as empty | ||
| if (inputRef.current) inputRef.current.value = ""; | ||
| onChange?.({ | ||
| target: e.currentTarget, | ||
| currentTarget: e.currentTarget, | ||
| } as ChangeEvent<HTMLInputElement>); | ||
| return; | ||
| } | ||
| onChange?.(e); | ||
| }} | ||
| onBlur={(e) => { | ||
| // If blur is caused by clicking our step buttons, we prevent pointerdown | ||
| // so blur shouldn't fire. This is for safety in case of keyboard focus move. | ||
| if (round) commitRoundedFromInput(); | ||
| }} | ||
| onKeyDown={(e) => { | ||
| if (e.key === "Enter" && round) { | ||
| e.preventDefault(); | ||
| commitRoundedFromInput(); | ||
| } | ||
matt-aitken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }} | ||
| step={step} | ||
| min={min} | ||
| max={max} | ||
| disabled={disabled} | ||
| readOnly={readOnly} | ||
| className={cn( | ||
| "placeholder:text-muted-foreground h-full grow border-0 bg-transparent text-left text-text-bright outline-none ring-0 focus:border-0 focus:outline-none focus:ring-0 disabled:cursor-not-allowed", | ||
| size.input, | ||
| // Hide number input arrows | ||
| "[type=number]:border-0 [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" | ||
| )} | ||
| {...props} | ||
| /> | ||
|
|
||
| <div className={cn("flex items-center", size.gap)}> | ||
| <button | ||
| type="button" | ||
| onClick={handleStepDown} | ||
| onPointerDown={(e) => e.preventDefault()} | ||
| disabled={disabled || isMinDisabled} | ||
| aria-label={`Decrease by ${step}`} | ||
| className={cn( | ||
| "flex items-center justify-center rounded border border-error/30 bg-error/20 transition", | ||
| size.button, | ||
| "hover:border-error/50 hover:bg-error/30", | ||
| "disabled:cursor-not-allowed disabled:opacity-40", | ||
| "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-text-link" | ||
| )} | ||
| > | ||
| <MinusIcon className={cn("text-error", size.icon)} /> | ||
| </button> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={handleStepUp} | ||
| onPointerDown={(e) => e.preventDefault()} | ||
| disabled={disabled || isMaxDisabled} | ||
| aria-label={`Increase by ${step}`} | ||
| className={cn( | ||
| "flex items-center justify-center rounded border border-success/30 bg-success/10 transition", | ||
| size.button, | ||
| "hover:border-success/40 hover:bg-success/20", | ||
| "disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent", | ||
| "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-text-link" | ||
| )} | ||
| > | ||
| <PlusIcon className={cn("text-success", size.icon)} /> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.