Skip to content

Commit f089f93

Browse files
refactor: [DI-26682] - Added a single type to all service type properties (linode#12646)
* refactor: [DI-26359] - Update the code to type safe for CloudPulseSerivceType for all service type properties * refactor: [DI-26359] - Updated types & constant * refactor: [DI-26359] - Updated typechecks * refactor: [DI-26359] - Updated placeholder condition * refactor: [DI-26359] - Updated test case * refactor: [DI-26359] - Updated typecheck failures * Updated failing tests * refactor: [DI-26359] - Updated type * Added changeset * Fixed failing test cases * Fixed lint issue
1 parent fdfd617 commit f089f93

File tree

56 files changed

+230
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+230
-185
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/api-v4": Added
3+
---
4+
5+
ACLP: `CloudPulseServiceType` type for type safety across cloudpulse ([#12646](https://github.com/linode/manager/pull/12646))

packages/api-v4/src/cloudpulse/alerts.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Request, {
1515
import type { Filter, Params, ResourcePage } from '../types';
1616
import type {
1717
Alert,
18-
AlertServiceType,
1918
CloudPulseAlertsPayload,
2019
CreateAlertDefinitionPayload,
2120
EditAlertDefinitionPayload,
@@ -24,7 +23,7 @@ import type {
2423

2524
export const createAlertDefinition = (
2625
data: CreateAlertDefinitionPayload,
27-
serviceType: AlertServiceType,
26+
serviceType: string,
2827
) =>
2928
Request<Alert>(
3029
setURL(

packages/api-v4/src/cloudpulse/types.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import type { AccountCapability } from 'src/account';
33
export type AlertSeverityType = 0 | 1 | 2 | 3;
44
export type MetricAggregationType = 'avg' | 'count' | 'max' | 'min' | 'sum';
55
export type MetricOperatorType = 'eq' | 'gt' | 'gte' | 'lt' | 'lte';
6-
export type AlertServiceType = 'dbaas' | 'firewall' | 'linode' | 'nodebalancer';
7-
export type MetricsServiceType =
6+
export type CloudPulseServiceType =
87
| 'dbaas'
98
| 'firewall'
109
| 'linode'
1110
| 'nodebalancer';
11+
1212
export type AlertClass = 'dedicated' | 'shared';
1313
export type DimensionFilterOperatorType =
1414
| 'endswith'
@@ -41,7 +41,7 @@ export interface Dashboard {
4141
created: string;
4242
id: number;
4343
label: string;
44-
service_type: string;
44+
service_type: CloudPulseServiceType;
4545
time_duration: TimeDuration;
4646
updated: string;
4747
widgets: Widgets[];
@@ -76,8 +76,8 @@ export interface Widgets {
7676
metric: string;
7777
namespace_id: number;
7878
region_id: number;
79-
service_type: string;
80-
serviceType: string;
79+
service_type: CloudPulseServiceType;
80+
serviceType: CloudPulseServiceType;
8181
size: number;
8282
time_duration: TimeDuration;
8383
time_granularity: TimeGranularity;
@@ -183,7 +183,7 @@ export interface Service {
183183
alert: ServiceAlert;
184184
label: string;
185185
regions: string;
186-
service_type: string;
186+
service_type: CloudPulseServiceType;
187187
}
188188

189189
export interface ServiceTypesList {
@@ -252,7 +252,7 @@ export interface Alert {
252252
rules: AlertDefinitionMetricCriteria[];
253253
};
254254
scope: AlertDefinitionScope;
255-
service_type: AlertServiceType;
255+
service_type: CloudPulseServiceType;
256256
severity: AlertSeverityType;
257257
status: AlertStatusType;
258258
tags: string[];
@@ -349,7 +349,7 @@ export interface EditAlertDefinitionPayload {
349349
export interface EditAlertPayloadWithService
350350
extends EditAlertDefinitionPayload {
351351
alertId: number;
352-
serviceType: string;
352+
serviceType: CloudPulseServiceType;
353353
}
354354

355355
export type AlertStatusUpdateType = 'Disable' | 'Enable';
@@ -361,11 +361,11 @@ export interface EntityAlertUpdatePayload {
361361

362362
export interface DeleteAlertPayload {
363363
alertId: number;
364-
serviceType: string;
364+
serviceType: CloudPulseServiceType;
365365
}
366366

367367
export const capabilityServiceTypeMapping: Record<
368-
AlertServiceType | MetricsServiceType | string,
368+
CloudPulseServiceType,
369369
AccountCapability
370370
> = {
371371
linode: 'Linodes',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Changed
3+
---
4+
5+
ACLP: all the instances of service type property has `CloudPulseServiceType` type ([#12646](https://github.com/linode/manager/pull/12646))

packages/manager/cypress/e2e/core/cloudpulse/alerts-listing-page.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import {
2828
} from 'src/features/CloudPulse/Alerts/constants';
2929
import { formatDate } from 'src/utilities/formatDate';
3030

31-
import type { Alert, AlertServiceType, AlertStatusType } from '@linode/api-v4';
31+
import type {
32+
Alert,
33+
AlertStatusType,
34+
CloudPulseServiceType,
35+
} from '@linode/api-v4';
3236
import type { Flags } from 'src/featureFlags';
3337
const alertDefinitionsUrl = '/alerts/definitions';
3438

@@ -111,7 +115,7 @@ const statusList: AlertStatusType[] = [
111115
'in progress',
112116
'failed',
113117
];
114-
const serviceTypes: AlertServiceType[] = ['linode', 'dbaas'];
118+
const serviceTypes: CloudPulseServiceType[] = ['linode', 'dbaas'];
115119

116120
/**
117121
* @description

packages/manager/cypress/e2e/core/cloudpulse/cloudpulse-dashboard-errors.spec.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,9 @@ const flags: Partial<Flags> = {
6363
},
6464
],
6565
};
66-
const {
67-
clusterName,
68-
dashboardName,
69-
engine,
70-
id,
71-
metrics,
72-
nodeType,
73-
serviceType,
74-
} = widgetDetails.dbaas;
75-
66+
const { clusterName, dashboardName, engine, id, metrics, nodeType } =
67+
widgetDetails.dbaas;
68+
const serviceType = 'dbaas';
7669
const dashboard = dashboardFactory.build({
7770
label: dashboardName,
7871
service_type: serviceType,

packages/manager/cypress/e2e/core/cloudpulse/create-user-alert.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ const mockRegions = [
6767
},
6868
}),
6969
];
70-
const { metrics, serviceType } = widgetDetails.dbaas;
70+
const { metrics } = widgetDetails.dbaas;
71+
const serviceType = 'dbaas';
7172
const databaseMock = databaseFactory.buildList(10, {
7273
cluster_size: 3,
7374
engine: 'mysql',

packages/manager/cypress/e2e/core/cloudpulse/dbaas-widgets-verification.spec.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,9 @@ const flags: Partial<Flags> = {
7272
],
7373
};
7474

75-
const {
76-
clusterName,
77-
dashboardName,
78-
engine,
79-
id,
80-
metrics,
81-
nodeType,
82-
serviceType,
83-
} = widgetDetails.dbaas;
84-
75+
const { clusterName, dashboardName, engine, id, metrics, nodeType } =
76+
widgetDetails.dbaas;
77+
const serviceType = 'dbaas';
8578
const dashboard = dashboardFactory.build({
8679
label: dashboardName,
8780
service_type: serviceType,

packages/manager/cypress/e2e/core/cloudpulse/groupby-tags.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import { ui } from 'support/ui';
1515

1616
import { accountFactory, alertFactory } from 'src/factories';
1717

18-
import type { Alert, AlertServiceType, AlertStatusType } from '@linode/api-v4';
18+
import type {
19+
Alert,
20+
AlertStatusType,
21+
CloudPulseServiceType,
22+
} from '@linode/api-v4';
1923
import type { Flags } from 'src/featureFlags';
2024

2125
const flags: Partial<Flags> = { aclp: { beta: true, enabled: true } };
@@ -27,7 +31,7 @@ const statusList: AlertStatusType[] = [
2731
'in progress',
2832
'failed',
2933
];
30-
const serviceTypes: AlertServiceType[] = ['linode', 'dbaas'];
34+
const serviceTypes: CloudPulseServiceType[] = ['linode', 'dbaas'];
3135
const tagSequence = ['LinodeTags', 'DBaaSTags', 'bothTags', 'No Tags'];
3236

3337
// Generate mock alerts with a mix of tags, statuses, and service types

packages/manager/cypress/e2e/core/cloudpulse/linode-widget-verification.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ const flags: Partial<Flags> = {
6161
},
6262
],
6363
};
64-
const { dashboardName, id, metrics, region, resource, serviceType } =
65-
widgetDetails.linode;
66-
64+
const { dashboardName, id, metrics, region, resource } = widgetDetails.linode;
65+
const serviceType = 'linode';
6766
const dashboard = dashboardFactory.build({
6867
label: dashboardName,
6968
service_type: serviceType,

0 commit comments

Comments
 (0)