Skip to content

Commit e270a8c

Browse files
Group constants
1 parent 0e910e2 commit e270a8c

7 files changed

Lines changed: 115 additions & 161 deletions

File tree

src/cloud/commands/auth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from "vscode"
22
import { trackCloudSignOut } from "../../utils/telemetry"
33
import { AUTH_PROVIDER_ID } from "../auth"
4-
import { BTN_SIGN_OUT, MSG_SIGN_OUT_CONFIRM } from "../constants"
4+
import { Auth, Button } from "../constants"
55
import type { AuthProvider } from "../types"
66

77
export class AuthCommands {
@@ -18,12 +18,12 @@ export class AuthCommands {
1818

1919
async signOut(): Promise<boolean> {
2020
const confirm = await vscode.window.showWarningMessage(
21-
MSG_SIGN_OUT_CONFIRM,
21+
Auth.MSG_SIGN_OUT_CONFIRM,
2222
{ modal: true },
23-
BTN_SIGN_OUT,
23+
Button.SIGN_OUT,
2424
)
2525

26-
if (confirm === BTN_SIGN_OUT) {
26+
if (confirm === Button.SIGN_OUT) {
2727
await this.authProvider.signOut()
2828
trackCloudSignOut()
2929
this.onStateChanged()

src/cloud/commands/project.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import {
55
} from "../../utils/telemetry"
66
import type { ApiService } from "../api"
77
import type { ConfigService } from "../config"
8-
import {
9-
BTN_UNLINK,
10-
MSG_LINKED,
11-
MSG_NO_WORKSPACE,
12-
MSG_UNLINK_CONFIRM,
13-
PICKER_SELECT_WORKSPACE_LINK,
14-
PICKER_SELECT_WORKSPACE_UNLINK,
15-
} from "../constants"
8+
import { Button, Picker, Project } from "../constants"
169
import type { WorkspaceState } from "../types"
1710
import { createNewApp, pickExistingApp, pickTeam } from "../ui/pickers"
1811

@@ -23,7 +16,7 @@ async function pickWorkspaceFolder(
2316
const workspaceFolders = vscode.workspace.workspaceFolders
2417

2518
if (!workspaceFolders || workspaceFolders.length === 0) {
26-
vscode.window.showErrorMessage(MSG_NO_WORKSPACE)
19+
vscode.window.showErrorMessage(Project.MSG_NO_WORKSPACE)
2720
return null
2821
}
2922

@@ -61,7 +54,7 @@ export class LinkCommands {
6154

6255
async linkProject(workspaceRoot?: vscode.Uri): Promise<void> {
6356
const targetFolder =
64-
workspaceRoot ?? (await pickWorkspaceFolder(PICKER_SELECT_WORKSPACE_LINK))
57+
workspaceRoot ?? (await pickWorkspaceFolder(Picker.SELECT_WORKSPACE_LINK))
6558
if (!targetFolder) return
6659

6760
const team = await pickTeam(this.apiService)
@@ -75,13 +68,13 @@ export class LinkCommands {
7568
team_id: team.id,
7669
})
7770
trackCloudProjectLinked(app.slug)
78-
vscode.window.showInformationMessage(MSG_LINKED(app.slug))
71+
vscode.window.showInformationMessage(Project.MSG_LINKED(app.slug))
7972
await this.onProjectLinked(targetFolder)
8073
}
8174

8275
async createAndLinkProject(workspaceRoot?: vscode.Uri): Promise<void> {
8376
const targetFolder =
84-
workspaceRoot ?? (await pickWorkspaceFolder(PICKER_SELECT_WORKSPACE_LINK))
77+
workspaceRoot ?? (await pickWorkspaceFolder(Picker.SELECT_WORKSPACE_LINK))
8578
if (!targetFolder) return
8679

8780
const team = await pickTeam(this.apiService)
@@ -96,7 +89,7 @@ export class LinkCommands {
9689
team_id: team.id,
9790
})
9891
trackCloudProjectLinked(app.slug)
99-
vscode.window.showInformationMessage(MSG_LINKED(app.slug))
92+
vscode.window.showInformationMessage(Project.MSG_LINKED(app.slug))
10093
await this.onProjectLinked(targetFolder)
10194
}
10295

@@ -106,7 +99,7 @@ export class LinkCommands {
10699
): Promise<void> {
107100
const targetFolder =
108101
workspaceRoot ??
109-
(await pickWorkspaceFolder(PICKER_SELECT_WORKSPACE_UNLINK, (uri) => {
102+
(await pickWorkspaceFolder(Picker.SELECT_WORKSPACE_UNLINK, (uri) => {
110103
const state = getState(uri)
111104
// Only show folders that have a config (any state except not_configured)
112105
return state.status !== "not_configured"
@@ -117,12 +110,12 @@ export class LinkCommands {
117110

118111
const label = state.status === "linked" ? state.app.slug : "this app"
119112
const confirm = await vscode.window.showWarningMessage(
120-
MSG_UNLINK_CONFIRM(label),
113+
Project.MSG_UNLINK_CONFIRM(label),
121114
{ modal: true },
122-
BTN_UNLINK,
115+
Button.UNLINK,
123116
)
124117

125-
if (confirm === BTN_UNLINK) {
118+
if (confirm === Button.UNLINK) {
126119
await this.configService.deleteConfig(targetFolder)
127120
trackCloudProjectUnlinked(label)
128121
await this.onProjectUnlinked(targetFolder)

src/cloud/constants.ts

Lines changed: 58 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,61 @@ const LABEL_SIGN_OUT = "Sign Out"
33
const LABEL_UNLINK = "Unlink"
44
const LABEL_SETUP = "Set up FastAPI Cloud"
55

6-
// Status bar text constants
7-
export const STATUS_BAR_DEFAULT = "$(cloud) FastAPI Cloud"
8-
export const STATUS_BAR_SIGN_IN = "$(cloud) Sign into FastAPI Cloud"
9-
export const STATUS_BAR_SETUP = `$(cloud) ${LABEL_SETUP}`
10-
export const STATUS_BAR_WARNING = "$(warning) FastAPI Cloud"
11-
12-
// Button labels
13-
export const BTN_SIGN_OUT = LABEL_SIGN_OUT
14-
export const BTN_UNLINK = LABEL_UNLINK
15-
16-
// Auth command messages
17-
export const MSG_SIGN_OUT_CONFIRM = "Sign out of FastAPI Cloud?"
18-
19-
// Project command messages
20-
export const MSG_NO_WORKSPACE = "No workspace folder open"
21-
export const MSG_LINKED = (appSlug: string) => `Linked to ${appSlug}`
22-
export const MSG_UNLINK_CONFIRM = (label: string) =>
23-
`Unlink "${label}" from this project?`
24-
25-
// Picker placeholders
26-
export const PICKER_SELECT_WORKSPACE_LINK = "Select workspace folder to link"
27-
export const PICKER_SELECT_WORKSPACE_UNLINK =
28-
"Select workspace folder to unlink"
29-
export const PICKER_SELECT_TEAM = "Select a team"
30-
export const PICKER_SELECT_APP = "Select an app"
31-
32-
// Controller messages
33-
export const MSG_APP_NOT_FOUND =
34-
"This project is linked to a FastAPI Cloud app that could not be found. Unlink it, then link to the correct app."
35-
36-
// Menu messages and labels
37-
export const MENU_PLACEHOLDER_SETUP = LABEL_SETUP
38-
export const MENU_PLACEHOLDER_MORE = "More options"
39-
export const MENU_LINK_EXISTING = "$(link) Link Existing App"
40-
export const MENU_LINK_EXISTING_DESC = "Connect to an app on FastAPI Cloud"
41-
export const MENU_CREATE_NEW = "$(add) Create New App"
42-
export const MENU_CREATE_NEW_DESC = "Create a new app and link it"
43-
export const MENU_OPEN_APP = "$(globe) Open App"
44-
export const MENU_DASHBOARD = "$(link-external) Dashboard"
45-
export const MENU_MORE = "$(ellipsis) More"
46-
export const MENU_UNLINK_PROJECT = `$(trash) ${LABEL_UNLINK} Project`
47-
export const MENU_UNLINK_PROJECT_DESC = "Disconnect from FastAPI Cloud app"
48-
export const MENU_SIGN_OUT = `$(sign-out) ${LABEL_SIGN_OUT}`
49-
export const MENU_SIGN_OUT_DESC = "Sign out of FastAPI Cloud"
50-
51-
// Picker error messages
52-
export const ERR_NOT_AUTHENTICATED = "Please sign in to FastAPI Cloud first."
53-
export const ERR_FETCH_TEAMS =
54-
"Failed to fetch teams. Please check your connection."
55-
export const ERR_NO_TEAMS =
56-
"No teams found. Please create a team on FastAPI Cloud first."
57-
export const ERR_FETCH_APPS =
58-
"Failed to fetch apps. Please check your connection."
59-
export const ERR_NO_APPS =
60-
"No apps found for this team. Please create an app on FastAPI Cloud first."
61-
export const ERR_CREATE_APP = (error: string) =>
62-
`Failed to create app: ${error}`
63-
64-
// Picker input prompts and validation
65-
export const PROMPT_ENTER_APP_NAME = "Enter app name"
66-
export const ERR_NAME_TOO_SHORT = "Name must be at least 2 characters."
67-
export const ERR_NAME_INVALID =
68-
"Name can only contain lowercase letters, numbers, and hyphens."
69-
export const MSG_APP_CREATED = (appSlug: string) => `Created app: ${appSlug}`
6+
export const StatusBar = {
7+
DEFAULT: "$(cloud) FastAPI Cloud",
8+
SIGN_IN: "$(cloud) Sign into FastAPI Cloud",
9+
SETUP: `$(cloud) ${LABEL_SETUP}`,
10+
WARNING: "$(warning) FastAPI Cloud",
11+
} as const
12+
13+
export const Button = {
14+
SIGN_OUT: LABEL_SIGN_OUT,
15+
UNLINK: LABEL_UNLINK,
16+
} as const
17+
18+
export const Auth = {
19+
MSG_SIGN_OUT_CONFIRM: "Sign out of FastAPI Cloud?",
20+
} as const
21+
22+
export const Project = {
23+
MSG_NO_WORKSPACE: "No workspace folder open",
24+
MSG_LINKED: (appSlug: string) => `Linked to ${appSlug}`,
25+
MSG_UNLINK_CONFIRM: (label: string) => `Unlink "${label}" from this project?`,
26+
MSG_APP_NOT_FOUND:
27+
"This project is linked to a FastAPI Cloud app that could not be found. Unlink it, then link to the correct app.",
28+
} as const
29+
30+
export const Picker = {
31+
SELECT_WORKSPACE_LINK: "Select workspace folder to link",
32+
SELECT_WORKSPACE_UNLINK: "Select workspace folder to unlink",
33+
SELECT_TEAM: "Select a team",
34+
SELECT_APP: "Select an app",
35+
PROMPT_ENTER_APP_NAME: "Enter app name",
36+
ERR_NOT_AUTHENTICATED: "Please sign in to FastAPI Cloud first.",
37+
ERR_FETCH_TEAMS: "Failed to fetch teams. Please check your connection.",
38+
ERR_NO_TEAMS: "No teams found. Please create a team on FastAPI Cloud first.",
39+
ERR_FETCH_APPS: "Failed to fetch apps. Please check your connection.",
40+
ERR_NO_APPS:
41+
"No apps found for this team. Please create an app on FastAPI Cloud first.",
42+
ERR_CREATE_APP: (error: string) => `Failed to create app: ${error}`,
43+
ERR_NAME_TOO_SHORT: "Name must be at least 2 characters.",
44+
ERR_NAME_INVALID:
45+
"Name can only contain lowercase letters, numbers, and hyphens.",
46+
MSG_APP_CREATED: (appSlug: string) => `Created app: ${appSlug}`,
47+
} as const
48+
49+
export const Menu = {
50+
PLACEHOLDER_SETUP: LABEL_SETUP,
51+
PLACEHOLDER_MORE: "More options",
52+
LINK_EXISTING: "$(link) Link Existing App",
53+
LINK_EXISTING_DESC: "Connect to an app on FastAPI Cloud",
54+
CREATE_NEW: "$(add) Create New App",
55+
CREATE_NEW_DESC: "Create a new app and link it",
56+
OPEN_APP: "$(globe) Open App",
57+
DASHBOARD: "$(link-external) Dashboard",
58+
MORE: "$(ellipsis) More",
59+
UNLINK_PROJECT: `$(trash) ${LABEL_UNLINK} Project`,
60+
UNLINK_PROJECT_DESC: "Disconnect from FastAPI Cloud app",
61+
SIGN_OUT: `$(sign-out) ${LABEL_SIGN_OUT}`,
62+
SIGN_OUT_DESC: "Sign out of FastAPI Cloud",
63+
} as const

src/cloud/controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AUTH_PROVIDER_ID } from "./auth"
55
import { AuthCommands } from "./commands/auth"
66
import { LinkCommands } from "./commands/project"
77
import type { ConfigService } from "./config"
8-
import { BTN_UNLINK, MSG_APP_NOT_FOUND } from "./constants"
8+
import { Button, Project } from "./constants"
99
import type { AuthProvider, WorkspaceState } from "./types"
1010
import { MenuHandler } from "./ui/menus"
1111
import { StatusBarManager } from "./ui/statusBar"
@@ -206,9 +206,9 @@ export class CloudController {
206206

207207
if (shouldShowWarning) {
208208
vscode.window
209-
.showWarningMessage(MSG_APP_NOT_FOUND, BTN_UNLINK)
209+
.showWarningMessage(Project.MSG_APP_NOT_FOUND, Button.UNLINK)
210210
.then((selected) => {
211-
if (selected === BTN_UNLINK) {
211+
if (selected === Button.UNLINK) {
212212
// Fire-and-forget - user action triggered from warning
213213
void this.unlinkProject(workspaceRoot)
214214
}

src/cloud/ui/menus.ts

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,7 @@ import { ApiService } from "../api"
77
import { AUTH_PROVIDER_ID } from "../auth"
88
import type { AuthCommands } from "../commands/auth"
99
import type { LinkCommands } from "../commands/project"
10-
import {
11-
BTN_UNLINK,
12-
MENU_CREATE_NEW,
13-
MENU_CREATE_NEW_DESC,
14-
MENU_DASHBOARD,
15-
MENU_LINK_EXISTING,
16-
MENU_LINK_EXISTING_DESC,
17-
MENU_MORE,
18-
MENU_OPEN_APP,
19-
MENU_PLACEHOLDER_MORE,
20-
MENU_PLACEHOLDER_SETUP,
21-
MENU_SIGN_OUT,
22-
MENU_SIGN_OUT_DESC,
23-
MENU_UNLINK_PROJECT,
24-
MENU_UNLINK_PROJECT_DESC,
25-
MSG_APP_NOT_FOUND,
26-
MSG_NO_WORKSPACE,
27-
} from "../constants"
10+
import { Button, Menu, Project } from "../constants"
2811
import type { WorkspaceState } from "../types"
2912

3013
export class MenuHandler {
@@ -50,7 +33,7 @@ export class MenuHandler {
5033

5134
const activeFolder = this.getActiveWorkspaceFolder()
5235
if (!activeFolder) {
53-
vscode.window.showErrorMessage(MSG_NO_WORKSPACE)
36+
vscode.window.showErrorMessage(Project.MSG_NO_WORKSPACE)
5437
return
5538
}
5639

@@ -74,19 +57,19 @@ export class MenuHandler {
7457
private async showSetupMenu(workspaceRoot: vscode.Uri): Promise<void> {
7558
const items = [
7659
{
77-
label: MENU_LINK_EXISTING,
78-
description: MENU_LINK_EXISTING_DESC,
60+
label: Menu.LINK_EXISTING,
61+
description: Menu.LINK_EXISTING_DESC,
7962
id: "link",
8063
},
8164
{
82-
label: MENU_CREATE_NEW,
83-
description: MENU_CREATE_NEW_DESC,
65+
label: Menu.CREATE_NEW,
66+
description: Menu.CREATE_NEW_DESC,
8467
id: "create",
8568
},
8669
]
8770

8871
const selected = await vscode.window.showQuickPick(items, {
89-
placeHolder: MENU_PLACEHOLDER_SETUP,
72+
placeHolder: Menu.PLACEHOLDER_SETUP,
9073
})
9174

9275
if (selected?.id === "link") {
@@ -98,11 +81,11 @@ export class MenuHandler {
9881

9982
private async showBrokenLinkMenu(workspaceRoot: vscode.Uri): Promise<void> {
10083
const selected = await vscode.window.showWarningMessage(
101-
MSG_APP_NOT_FOUND,
102-
BTN_UNLINK,
84+
Project.MSG_APP_NOT_FOUND,
85+
Button.UNLINK,
10386
)
10487

105-
if (selected === BTN_UNLINK) {
88+
if (selected === Button.UNLINK) {
10689
await this.linkCommands.unlinkProject(workspaceRoot, this.getState)
10790
}
10891
}
@@ -115,16 +98,16 @@ export class MenuHandler {
11598
const dashboardUrl = ApiService.getDashboardUrl(team.slug, app.slug)
11699
const items = [
117100
{
118-
label: MENU_OPEN_APP,
101+
label: Menu.OPEN_APP,
119102
description: app.url,
120103
id: "open",
121104
},
122105
{
123-
label: MENU_DASHBOARD,
106+
label: Menu.DASHBOARD,
124107
description: dashboardUrl,
125108
id: "dashboard",
126109
},
127-
{ label: MENU_MORE, id: "more" },
110+
{ label: Menu.MORE, id: "more" },
128111
]
129112

130113
const selected = await vscode.window.showQuickPick(items, {
@@ -153,19 +136,19 @@ export class MenuHandler {
153136
private async showMoreMenu(workspaceRoot: vscode.Uri): Promise<void> {
154137
const items = [
155138
{
156-
label: MENU_UNLINK_PROJECT,
157-
description: MENU_UNLINK_PROJECT_DESC,
139+
label: Menu.UNLINK_PROJECT,
140+
description: Menu.UNLINK_PROJECT_DESC,
158141
id: "unlink",
159142
},
160143
{
161-
label: MENU_SIGN_OUT,
162-
description: MENU_SIGN_OUT_DESC,
144+
label: Menu.SIGN_OUT,
145+
description: Menu.SIGN_OUT_DESC,
163146
id: "signout",
164147
},
165148
]
166149

167150
const selected = await vscode.window.showQuickPick(items, {
168-
placeHolder: MENU_PLACEHOLDER_MORE,
151+
placeHolder: Menu.PLACEHOLDER_MORE,
169152
})
170153

171154
switch (selected?.id) {

0 commit comments

Comments
 (0)