Skip to content

Commit 82057f4

Browse files
authored
Refactor: Extract getStatusColor utility to shared module (#32)
1 parent 9462510 commit 82057f4

File tree

5 files changed

+17
-60
lines changed

5 files changed

+17
-60
lines changed

packages/tui/apps/status/app.tsx

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Box, Text, useApp, useInput } from "ink"
22
import { useState } from "react"
33
import { ErrorStep } from "../../src/components/error-step.js"
4+
import { getStatusColor } from "../../src/utils/index.js"
45

56
type ExpertChoice = {
67
name: string
@@ -120,18 +121,6 @@ function VersionSelector({
120121
exit()
121122
}
122123
})
123-
const getStatusColor = (status: string) => {
124-
switch (status) {
125-
case "available":
126-
return "green"
127-
case "deprecated":
128-
return "yellow"
129-
case "disabled":
130-
return "red"
131-
default:
132-
return undefined
133-
}
134-
}
135124
return (
136125
<Box flexDirection="column">
137126
<Text bold>Select a version of {expertName}:</Text>
@@ -184,18 +173,6 @@ function StatusSelector({
184173
exit()
185174
}
186175
})
187-
const getStatusColor = (status: string) => {
188-
switch (status) {
189-
case "available":
190-
return "green"
191-
case "deprecated":
192-
return "yellow"
193-
case "disabled":
194-
return "red"
195-
default:
196-
return undefined
197-
}
198-
}
199176
return (
200177
<Box flexDirection="column">
201178
<Text bold>Select status for {expertKey}:</Text>
@@ -255,18 +232,6 @@ function ConfirmStep({
255232
}
256233
})
257234
const statusChanged = status !== currentStatus
258-
const getStatusColor = (s: string) => {
259-
switch (s) {
260-
case "available":
261-
return "green"
262-
case "deprecated":
263-
return "yellow"
264-
case "disabled":
265-
return "red"
266-
default:
267-
return undefined
268-
}
269-
}
270235
return (
271236
<Box flexDirection="column">
272237
<Text bold>Confirm status change for {expertKey}:</Text>

packages/tui/apps/tag/app.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Box, Text, useApp, useInput } from "ink"
22
import { useState } from "react"
33
import { ErrorStep } from "../../src/components/error-step.js"
4+
import { getStatusColor } from "../../src/utils/index.js"
45

56
type ExpertChoice = {
67
name: string
@@ -107,18 +108,6 @@ function VersionSelector({
107108
exit()
108109
}
109110
})
110-
const getStatusColor = (status: string) => {
111-
switch (status) {
112-
case "available":
113-
return "green"
114-
case "deprecated":
115-
return "yellow"
116-
case "disabled":
117-
return "red"
118-
default:
119-
return undefined
120-
}
121-
}
122111
return (
123112
<Box flexDirection="column">
124113
<Text bold>Select a version of {expertName}:</Text>

packages/tui/apps/unpublish/app.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Box, Text, useApp, useInput } from "ink"
22
import { useState } from "react"
33
import { ErrorStep } from "../../src/components/error-step.js"
4+
import { getStatusColor } from "../../src/utils/index.js"
45

56
type ExpertChoice = {
67
name: string
@@ -99,18 +100,6 @@ function VersionSelector({
99100
exit()
100101
}
101102
})
102-
const getStatusColor = (status: string) => {
103-
switch (status) {
104-
case "available":
105-
return "green"
106-
case "deprecated":
107-
return "yellow"
108-
case "disabled":
109-
return "red"
110-
default:
111-
return undefined
112-
}
113-
}
114103
return (
115104
<Box flexDirection="column">
116105
<Text bold>Select a version of {expertName} to unpublish:</Text>

packages/tui/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { createErrorHandler } from "./error-handling.js"
22
export { EventQueue } from "./event-queue.js"
3+
export { getStatusColor } from "./status-color.js"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type StatusColor = "green" | "yellow" | "red"
2+
export const getStatusColor = (status: string): StatusColor | undefined => {
3+
switch (status) {
4+
case "available":
5+
return "green"
6+
case "deprecated":
7+
return "yellow"
8+
case "disabled":
9+
return "red"
10+
default:
11+
return undefined
12+
}
13+
}

0 commit comments

Comments
 (0)