Skip to content

Commit 3fec3ec

Browse files
Upcoming: [DI-24748] - Show regions based on available resources and dependent filters in CloudPulse dashboards (linode#12078)
* upcoming: [DI-24748] - Initial changes for region selection in dashboard based on resources * DI-24748 - Update filter logic * DI-24748 - Cypress fixes and logic updates * DI-24748 - Changeset * DI-24748 - fix cypress * DI-24748 - fix cypress * DI-24748 - remove unwanted error message handling and show only regions * DI-24748 - fix region logic and resource selection CSS updates * DI-24748 - remove svg styles * DI-24748 - remove unused import and css fixes * DI-24748 - fix optional concept for disabled prop * DI-24748 - remove space between strings * DI-24748 - NIT typo fixes
1 parent 6ded2c9 commit 3fec3ec

11 files changed

+280
-111
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
Show regions based on available resources and dependent filters in CloudPulse dashboards `GlobalFilter` section ([#12078](https://github.com/linode/manager/pull/12078))

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

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const flags: Partial<Flags> = {
6161
dimensionKey: 'cluster_id',
6262
maxResourceSelections: 10,
6363
serviceType: 'dbaas',
64-
supportedRegionIds: 'us-ord',
64+
supportedRegionIds: 'us-ord, us-east',
6565
},
6666
],
6767
};
@@ -96,21 +96,39 @@ const metricDefinitions = metrics.map(({ name, title, unit }) =>
9696
})
9797
);
9898

99-
const mockRegion = regionFactory.build({
100-
capabilities: ['Managed Databases'],
101-
id: 'us-ord',
102-
label: 'Chicago, IL',
103-
});
99+
const mockRegions = [
100+
regionFactory.build({
101+
id: 'us-ord',
102+
label: 'Chicago, IL',
103+
capabilities: ['Managed Databases'],
104+
}),
105+
regionFactory.build({
106+
id: 'us-east',
107+
label: 'Newark, NJ',
108+
capabilities: ['Managed Databases'],
109+
}),
110+
];
111+
112+
const databaseMocks: Database[] = [
113+
databaseFactory.build({
114+
cluster_size: 3,
115+
engine: 'mysql',
116+
label: clusterName,
117+
region: mockRegions[0].id,
118+
status: 'provisioning',
119+
type: engine,
120+
version: '1',
121+
}),
122+
databaseFactory.build({
123+
cluster_size: 3,
124+
engine: 'mysql',
125+
region: mockRegions[1].id,
126+
status: 'provisioning',
127+
type: engine,
128+
version: '1',
129+
}),
130+
];
104131

105-
const databaseMock: Database = databaseFactory.build({
106-
cluster_size: 3,
107-
engine: 'mysql',
108-
label: clusterName,
109-
region: mockRegion.id,
110-
status: 'provisioning',
111-
type: engine,
112-
version: '1',
113-
});
114132
const mockAccount = accountFactory.build();
115133

116134
describe('Tests for API error handling', () => {
@@ -122,9 +140,9 @@ describe('Tests for API error handling', () => {
122140
mockGetCloudPulseServices([serviceType]).as('fetchServices');
123141
mockCreateCloudPulseJWEToken(serviceType);
124142
mockGetCloudPulseDashboard(id, dashboard);
125-
mockGetRegions([mockRegion]);
143+
mockGetRegions(mockRegions);
126144
mockGetUserPreferences({});
127-
mockGetDatabases([databaseMock]).as('getDatabases');
145+
mockGetDatabases(databaseMocks).as('getDatabases');
128146
});
129147

130148
it('displays error message when metric definitions API fails', () => {
@@ -161,7 +179,7 @@ describe('Tests for API error handling', () => {
161179
// Select a region from the dropdown.
162180
ui.regionSelect.find().click();
163181
ui.regionSelect
164-
.findItemByRegionId(mockRegion.id, [mockRegion])
182+
.findItemByRegionId(mockRegions[0].id, mockRegions)
165183
.should('be.visible')
166184
.click();
167185

@@ -238,7 +256,7 @@ describe('Tests for API error handling', () => {
238256
ui.regionSelect.find().click();
239257

240258
ui.regionSelect
241-
.findItemByRegionId(mockRegion.id, [mockRegion])
259+
.findItemByRegionId(mockRegions[0].id, mockRegions)
242260
.should('be.visible')
243261
.click();
244262

@@ -321,7 +339,7 @@ describe('Tests for API error handling', () => {
321339
// Select a region from the dropdown.
322340
ui.regionSelect.find().click();
323341
ui.regionSelect
324-
.findItemByRegionId(mockRegion.id, [mockRegion])
342+
.findItemByRegionId(mockRegions[0].id, mockRegions)
325343
.should('be.visible')
326344
.click();
327345

@@ -383,11 +401,6 @@ describe('Tests for API error handling', () => {
383401
});
384402

385403
it('displays error message when instance API fails', () => {
386-
// Mocking an error response for the 'CloudPulseDatabaseInstances' API request.
387-
mockGetDatabasesError('Internal Server Error').as(
388-
'getDatabaseInstancesError'
389-
);
390-
391404
cy.visitWithLogin('/metrics');
392405

393406
// Wait for the API calls .
@@ -404,14 +417,6 @@ describe('Tests for API error handling', () => {
404417
.should('be.visible')
405418
.click();
406419

407-
// Select a region from the dropdown.
408-
ui.regionSelect.find().click();
409-
410-
ui.regionSelect
411-
.findItemByRegionId(mockRegion.id, [mockRegion])
412-
.should('be.visible')
413-
.click();
414-
415420
// Select a Database Engine from the autocomplete input.
416421
ui.autocomplete
417422
.findByLabel('Database Engine')
@@ -420,6 +425,25 @@ describe('Tests for API error handling', () => {
420425

421426
ui.autocompletePopper.findByTitle(engine).should('be.visible').click();
422427

428+
// Select a region from the dropdown.
429+
ui.regionSelect.find().click();
430+
ui.regionSelect
431+
.findItemByRegionId(mockRegions[0].id, mockRegions)
432+
.should('be.visible')
433+
.click();
434+
435+
// simulate an error on instances call before changing the region again
436+
mockGetDatabasesError('Internal Server Error').as(
437+
'getDatabaseInstancesError'
438+
);
439+
440+
// Select a region from the dropdown.
441+
ui.regionSelect.find().click();
442+
ui.regionSelect
443+
.findItemByRegionId(mockRegions[1].id, mockRegions)
444+
.should('be.visible')
445+
.click();
446+
423447
// Wait for the intercepted request to complete
424448
cy.wait('@getDatabaseInstancesError');
425449

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const databaseMock: Database = databaseFactory.build({
173173
secondary: undefined,
174174
},
175175
label: clusterName,
176-
region: mockRegion.label,
176+
region: mockRegion.id,
177177
status: 'provisioning',
178178
type: engine,
179179
version: '1',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const metricDefinitions = metrics.map(({ name, title, unit }) =>
9696
const mockLinode = linodeFactory.build({
9797
id: kubeLinodeFactory.build().instance_id ?? undefined,
9898
label: resource,
99+
region: 'us-ord',
99100
});
100101

101102
const mockAccount = accountFactory.build();

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const metricsAPIResponsePayload = cloudPulseMetricsResponseFactory.build({
102102
});
103103

104104
const databaseMock: Database = databaseFactory.build({
105-
region: mockRegion.label,
105+
region: mockRegion.id,
106106
type: engine,
107107
});
108108
const mockProfile = profileFactory.build({
@@ -237,10 +237,15 @@ describe('Integration tests for verifying Cloudpulse custom and preset configura
237237
resources: ['1'],
238238
},
239239
}).as('fetchPreferences');
240-
mockGetDatabases([databaseMock]);
240+
mockGetDatabases([databaseMock]).as('fetchDatabases');
241241

242242
cy.visitWithLogin('/metrics');
243-
cy.wait(['@fetchServices', '@fetchDashboard', '@fetchPreferences']);
243+
cy.wait([
244+
'@fetchServices',
245+
'@fetchDashboard',
246+
'@fetchPreferences',
247+
'@fetchDatabases',
248+
]);
244249
});
245250

246251
it('Implement and validate the functionality of the custom date and time picker for selecting a specific date and time range', () => {

packages/manager/src/features/CloudPulse/Utils/FilterBuilder.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,27 @@ export const getRegionProperties = (
107107
savePref?: boolean
108108
) => void
109109
): CloudPulseRegionSelectProps => {
110-
const { name: label, placeholder } = props.config.configuration;
111-
const { dashboard, isServiceAnalyticsIntegration, preferences } = props;
110+
const { name: label, placeholder, filterKey } = props.config.configuration;
111+
const {
112+
dashboard,
113+
isServiceAnalyticsIntegration,
114+
preferences,
115+
dependentFilters,
116+
config,
117+
} = props;
112118
return {
113119
defaultValue: preferences?.[REGION],
114120
handleRegionChange,
115121
label,
116122
placeholder,
117123
savePreferences: !isServiceAnalyticsIntegration,
118124
selectedDashboard: dashboard,
125+
disabled: shouldDisableFilterByFilterKey(
126+
filterKey,
127+
dependentFilters ?? {},
128+
dashboard
129+
),
130+
xFilter: buildXFilter(config, dependentFilters ?? {}),
119131
};
120132
};
121133

packages/manager/src/features/CloudPulse/Utils/FilterConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export const DBAAS_CONFIG: Readonly<CloudPulseServiceTypeFilterMap> = {
101101
},
102102
{
103103
configuration: {
104+
dependency: ['engine'],
104105
filterKey: 'region',
105106
filterType: 'string',
106107
isFilterable: false,

packages/manager/src/features/CloudPulse/shared/CloudPulseDashboardFilterBuilder.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export const CloudPulseDashboardFilterBuilder = React.memo(
245245
dashboard,
246246
isServiceAnalyticsIntegration,
247247
preferences,
248+
dependentFilters: dependentFilterReference.current,
248249
},
249250
handleRegionChange
250251
);

0 commit comments

Comments
 (0)