Skip to content

Commit

Permalink
fix: handle "created" status
Browse files Browse the repository at this point in the history
  • Loading branch information
Trugamr committed Jan 13, 2024
1 parent 580ec3c commit a652a84
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/components/status-indicator.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { match } from 'ts-pattern'
import type { Stack } from '~/lib/stack.server'
import { cn } from '~/lib/utils'

type StackIndicatorProps = {
status: 'running' | 'stopped' | 'inactive'
status: Stack['status']
className?: string
}

Expand All @@ -12,6 +13,7 @@ export function StatusIndicator({ status, className }: StackIndicatorProps) {
className={cn(
'inline-block h-2.5 w-2.5 shrink-0 rounded-full',
match(status)
.with('created', () => 'bg-yellow-400')
.with('running', () => 'bg-green-400')
.with('stopped', () => 'bg-red-400')
.with('inactive', () => 'bg-gray-400')
Expand Down
8 changes: 5 additions & 3 deletions app/lib/stack.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ type ManagedStack = {
managed: true
}

export type Stack = Omit<z.infer<typeof StackDetailsSchema>, 'status'> & {
status: 'running' | 'stopped' | 'inactive'
type StackDetails = z.infer<typeof StackDetailsSchema>

export type Stack = Omit<StackDetails, 'status'> & {
status: StackDetails['status'] | 'inactive'
managed: boolean
}

Expand Down Expand Up @@ -103,7 +105,7 @@ const StackDetailsSchema = z
value => (typeof value === 'string' ? STACK_STATUS_REGEX.exec(value)?.groups : value),
z.object({
current: z
.enum(['running', 'exited'])
.enum(['created', 'running', 'exited'])
// Map `exited` to `stopped` for simplicity
.transform(value => (value === 'exited' ? 'stopped' : value)),
count: z.coerce.number(),
Expand Down
5 changes: 3 additions & 2 deletions app/routes/stacks.$name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default function StacksNameRoute() {
<StatusIndicator status={stack.status} />
<span>
{match(stack.status)
.with('created', () => 'Created')
.with('running', () => 'Running')
.with('stopped', () => 'Stopped')
.with('inactive', () => 'Inactive')
Expand Down Expand Up @@ -113,7 +114,7 @@ export default function StacksNameRoute() {
<span>Start</span>
</Button>
))
.with('running', () => (
.with(P.union('created', 'running'), () => (
<Button
className="gap-x-1.5"
name="intent"
Expand All @@ -127,7 +128,7 @@ export default function StacksNameRoute() {
))
.exhaustive()}
{match(stack.status)
.with(P.union('running', 'stopped'), () => (
.with(P.union('created', 'running', 'stopped'), () => (
<Button
className="gap-x-1.5"
name="intent"
Expand Down

0 comments on commit a652a84

Please sign in to comment.