Skip to content

Commit 2f3b427

Browse files
jeanibarzclaude
andcommitted
refactor(web): convert enums to as-const in subscription-list
Convert 7 TypeScript enums in the plugin-detail-panel/subscription-list components to as-const objects with companion type aliases: - SubscriptionListMode (types.ts) - CreateButtonType (create/types.ts) - AuthorizationStatusEnum, ClientTypeEnum (create/hooks/use-oauth-client-state.ts) - ApiKeyStep (create/hooks/use-common-modal-state.ts) - LogTypeEnum (log-viewer.tsx, file-local) - EditStep (edit/apikey-edit-modal.tsx, file-local) All consumers use EnumName.MEMBER as values or EnumName as types; no runtime reflection, so the conversion preserves the public API. Drops 7 entries from web/eslint-suppressions.json for the erasable-syntax-only/enums rule and removes file entries that became empty. Partially addresses #27998. Co-authored-by: Claude <noreply@anthropic.com>
1 parent ee87289 commit 2f3b427

7 files changed

Lines changed: 37 additions & 56 deletions

File tree

web/app/components/plugins/plugin-detail-panel/subscription-list/create/hooks/use-common-modal-state.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import { useSubscriptionList } from '../../use-subscription-list'
2626
// Types
2727
// ============================================================================
2828

29-
export enum ApiKeyStep {
30-
Verify = 'verify',
31-
Configuration = 'configuration',
32-
}
29+
export const ApiKeyStep = {
30+
Verify: 'verify',
31+
Configuration: 'configuration',
32+
} as const
33+
export type ApiKeyStep = typeof ApiKeyStep[keyof typeof ApiKeyStep]
3334

3435
const CREDENTIAL_TYPE_MAP: Record<SupportedCreationMethods, TriggerCredentialTypeEnum> = {
3536
[SupportedCreationMethods.APIKEY]: TriggerCredentialTypeEnum.ApiKey,

web/app/components/plugins/plugin-detail-panel/subscription-list/create/hooks/use-oauth-client-state.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ import {
1313
useVerifyAndUpdateTriggerSubscriptionBuilder,
1414
} from '@/service/use-triggers'
1515

16-
export enum AuthorizationStatusEnum {
17-
Pending = 'pending',
18-
Success = 'success',
19-
Failed = 'failed',
20-
}
21-
22-
export enum ClientTypeEnum {
23-
Default = 'default',
24-
Custom = 'custom',
25-
}
16+
export const AuthorizationStatusEnum = {
17+
Pending: 'pending',
18+
Success: 'success',
19+
Failed: 'failed',
20+
} as const
21+
export type AuthorizationStatusEnum = typeof AuthorizationStatusEnum[keyof typeof AuthorizationStatusEnum]
22+
23+
export const ClientTypeEnum = {
24+
Default: 'default',
25+
Custom: 'custom',
26+
} as const
27+
export type ClientTypeEnum = typeof ClientTypeEnum[keyof typeof ClientTypeEnum]
2628

2729
const POLL_INTERVAL_MS = 3000
2830

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
export enum CreateButtonType {
2-
FULL_BUTTON = 'full-button',
3-
ICON_BUTTON = 'icon-button',
4-
}
1+
export const CreateButtonType = {
2+
FULL_BUTTON: 'full-button',
3+
ICON_BUTTON: 'icon-button',
4+
} as const
5+
export type CreateButtonType = typeof CreateButtonType[keyof typeof CreateButtonType]
56

67
export const DEFAULT_METHOD = 'default'

web/app/components/plugins/plugin-detail-panel/subscription-list/edit/apikey-edit-modal.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ type Props = {
2323
pluginDetail?: PluginDetail
2424
}
2525

26-
enum EditStep {
27-
EditCredentials = 'edit_credentials',
28-
EditConfiguration = 'edit_configuration',
29-
}
26+
const EditStep = {
27+
EditCredentials: 'edit_credentials',
28+
EditConfiguration: 'edit_configuration',
29+
} as const
30+
type EditStep = typeof EditStep[keyof typeof EditStep]
3031

3132
const normalizeFormType = (type: string): FormTypeEnum => {
3233
switch (type) {

web/app/components/plugins/plugin-detail-panel/subscription-list/log-viewer.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ type Props = {
2121
className?: string
2222
}
2323

24-
enum LogTypeEnum {
25-
REQUEST = 'request',
26-
RESPONSE = 'response',
27-
}
24+
const LogTypeEnum = {
25+
REQUEST: 'request',
26+
RESPONSE: 'response',
27+
} as const
28+
type LogTypeEnum = typeof LogTypeEnum[keyof typeof LogTypeEnum]
2829

2930
const LogViewer = ({ logs, className }: Props) => {
3031
const { t } = useTranslation()

web/app/components/plugins/plugin-detail-panel/subscription-list/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
export enum SubscriptionListMode {
2-
PANEL = 'panel',
3-
SELECTOR = 'selector',
4-
}
1+
export const SubscriptionListMode = {
2+
PANEL: 'panel',
3+
SELECTOR: 'selector',
4+
} as const
5+
export type SubscriptionListMode = typeof SubscriptionListMode[keyof typeof SubscriptionListMode]
56

67
export type SimpleSubscription = {
78
id: string

web/eslint-suppressions.json

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6984,16 +6984,6 @@
69846984
"count": 1
69856985
}
69866986
},
6987-
"app/components/plugins/plugin-detail-panel/subscription-list/create/hooks/use-common-modal-state.ts": {
6988-
"erasable-syntax-only/enums": {
6989-
"count": 1
6990-
}
6991-
},
6992-
"app/components/plugins/plugin-detail-panel/subscription-list/create/hooks/use-oauth-client-state.ts": {
6993-
"erasable-syntax-only/enums": {
6994-
"count": 2
6995-
}
6996-
},
69976987
"app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx": {
69986988
"no-barrel-files/no-barrel-files": {
69996989
"count": 3
@@ -7013,20 +7003,12 @@
70137003
"count": 3
70147004
}
70157005
},
7016-
"app/components/plugins/plugin-detail-panel/subscription-list/create/types.ts": {
7017-
"erasable-syntax-only/enums": {
7018-
"count": 1
7019-
}
7020-
},
70217006
"app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx": {
70227007
"tailwindcss/enforce-consistent-class-order": {
70237008
"count": 4
70247009
}
70257010
},
70267011
"app/components/plugins/plugin-detail-panel/subscription-list/edit/apikey-edit-modal.tsx": {
7027-
"erasable-syntax-only/enums": {
7028-
"count": 1
7029-
},
70307012
"no-restricted-imports": {
70317013
"count": 1
70327014
}
@@ -7052,9 +7034,6 @@
70527034
}
70537035
},
70547036
"app/components/plugins/plugin-detail-panel/subscription-list/log-viewer.tsx": {
7055-
"erasable-syntax-only/enums": {
7056-
"count": 1
7057-
},
70587037
"tailwindcss/enforce-consistent-class-order": {
70597038
"count": 4
70607039
},
@@ -7086,11 +7065,6 @@
70867065
"count": 2
70877066
}
70887067
},
7089-
"app/components/plugins/plugin-detail-panel/subscription-list/types.ts": {
7090-
"erasable-syntax-only/enums": {
7091-
"count": 1
7092-
}
7093-
},
70947068
"app/components/plugins/plugin-detail-panel/tool-selector/components/index.ts": {
70957069
"no-barrel-files/no-barrel-files": {
70967070
"count": 7

0 commit comments

Comments
 (0)