Skip to content

Commit 83ca276

Browse files
cpathipamjac0bsharsh-akamai
authored
refactor: [M3-9388 ] - Move Status Page queries queries (#12468)
* Add statuspage query * update paths * Added changeset: Move Status Page queries and dependencies to shared `queries` package * Added changeset: Added `statusPage/` directory and migrated relevant query keys and hooks * remove status page queries * Update constants.ts * Update packages/queries/.changeset/pr-12468-added-1751563776473.md Co-authored-by: Mariah Jacobs <114685994+mjac0bs@users.noreply.github.com> * Update requests.ts * update the keys and statusPage * pass the LINODE_STATUS_PAGE_URL as param * Update packages/manager/.changeset/pr-12468-removed-1751563731187.md Co-authored-by: Harsh Shankar Rao <hrao@akamai.com> * PR - feedback - @mjac0bs --------- Co-authored-by: Mariah Jacobs <114685994+mjac0bs@users.noreply.github.com> Co-authored-by: Harsh Shankar Rao <hrao@akamai.com>
1 parent 276a09a commit 83ca276

File tree

11 files changed

+63
-34
lines changed

11 files changed

+63
-34
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Removed
3+
---
4+
5+
Move Status Page queries and dependencies to shared `queries` package ([#12468](https://github.com/linode/manager/pull/12468))

packages/manager/src/factories/statusPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
IncidentUpdate,
88
Maintenance,
99
MaintenanceResponse,
10-
} from 'src/queries/statusPage';
10+
} from '@linode/queries';
1111

1212
const DATE = '2021-01-12T00:00:00.394Z';
1313

packages/manager/src/features/GlobalNotifications/APIMaintenanceBanner.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { queryPresets } from '@linode/queries';
1+
import { queryPresets, useMaintenanceQuery } from '@linode/queries';
22
import { Stack, Typography } from '@linode/ui';
33
import * as React from 'react';
44

55
import { DismissibleBanner } from 'src/components/DismissibleBanner/DismissibleBanner';
66
import { Link } from 'src/components/Link';
7-
import { useMaintenanceQuery } from 'src/queries/statusPage';
7+
import { LINODE_STATUS_PAGE_URL } from 'src/constants';
88
import { sanitizeHTML } from 'src/utilities/sanitizeHTML';
99

10+
import type { Maintenance } from '@linode/queries';
1011
import type { SuppliedMaintenanceData } from 'src/featureFlags';
11-
import type { Maintenance } from 'src/queries/statusPage';
1212

1313
interface Props {
1414
suppliedMaintenances: SuppliedMaintenanceData[] | undefined;
@@ -17,9 +17,12 @@ interface Props {
1717
export const APIMaintenanceBanner = React.memo((props: Props) => {
1818
const { suppliedMaintenances } = props;
1919

20-
const { data: maintenancesData } = useMaintenanceQuery({
21-
...queryPresets.oneTimeFetch,
22-
});
20+
const { data: maintenancesData } = useMaintenanceQuery(
21+
LINODE_STATUS_PAGE_URL,
22+
{
23+
...queryPresets.oneTimeFetch,
24+
}
25+
);
2326
const maintenances = maintenancesData?.scheduled_maintenances ?? [];
2427

2528
if (

packages/manager/src/features/Help/StatusBanners.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useIncidentQuery } from '@linode/queries';
12
import { Box, Typography } from '@linode/ui';
23
import { capitalize, truncateEnd } from '@linode/utilities';
34
import { useTheme } from '@mui/material/styles';
@@ -6,13 +7,13 @@ import * as React from 'react';
67

78
import { DismissibleBanner } from 'src/components/DismissibleBanner/DismissibleBanner';
89
import { Link } from 'src/components/Link';
9-
import { useIncidentQuery } from 'src/queries/statusPage';
10+
import { LINODE_STATUS_PAGE_URL } from 'src/constants';
1011
import { sanitizeHTML } from 'src/utilities/sanitizeHTML';
1112

12-
import type { IncidentImpact, IncidentStatus } from 'src/queries/statusPage';
13+
import type { IncidentImpact, IncidentStatus } from '@linode/queries';
1314

1415
export const StatusBanners = () => {
15-
const { data: incidentsData } = useIncidentQuery();
16+
const { data: incidentsData } = useIncidentQuery(LINODE_STATUS_PAGE_URL);
1617
const incidents = incidentsData?.incidents ?? [];
1718

1819
if (incidents.length === 0) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/queries": Added
3+
---
4+
5+
`statusPage/` directory and migrated relevant query keys and hooks ([#12468](https://github.com/linode/manager/pull/12468))

packages/queries/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './profile';
1818
export * from './quotas';
1919
export * from './regions';
2020
export * from './stackscripts';
21+
export * from './statusPage';
2122
export * from './support';
2223
export * from './tags';
2324
export * from './types';

packages/manager/src/queries/statusPage/index.ts renamed to packages/queries/src/statusPage/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
* used through this query, all of this is contained within src/queries.
55
*/
66

7+
export * from './keys';
8+
export * from './requests';
79
export * from './statusPage';
810
export * from './types';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createQueryKeys } from '@lukemorales/query-key-factory';
2+
3+
import { getAllMaintenance, getIncidents } from './requests';
4+
5+
export const statusPageQueries = createQueryKeys('statusPage', {
6+
incidents: (statusPageUrl?: string) => ({
7+
queryKey: [statusPageUrl],
8+
queryFn: () => getIncidents(statusPageUrl),
9+
}),
10+
maintenance: (statusPageUrl?: string) => ({
11+
queryKey: [statusPageUrl],
12+
queryFn: () => getAllMaintenance(statusPageUrl),
13+
}),
14+
});

packages/manager/src/queries/statusPage/requests.ts renamed to packages/queries/src/statusPage/requests.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { LINODE_STATUS_PAGE_URL } from 'src/constants';
2-
31
import type { IncidentResponse, MaintenanceResponse } from './types';
42
import type { APIError } from '@linode/api-v4';
53

@@ -18,10 +16,13 @@ const handleError = (error: APIError, defaultMessage: string) => {
1816
/**
1917
* Return a list of incidents with a status of "unresolved."
2018
*/
21-
export const getIncidents = async (): Promise<IncidentResponse> => {
19+
export const getIncidents = async (
20+
statusPageUrl?: string,
21+
): Promise<IncidentResponse> => {
22+
const STATUS_PAGE_URL = statusPageUrl ?? 'https://status.linode.com/api/v2';
2223
try {
2324
const response = await fetch(
24-
`${LINODE_STATUS_PAGE_URL}/incidents/unresolved.json`
25+
`${STATUS_PAGE_URL}/incidents/unresolved.json`,
2526
);
2627

2728
if (!response.ok) {
@@ -38,10 +39,14 @@ export const getIncidents = async (): Promise<IncidentResponse> => {
3839
* There are several endpoints for maintenance events; this method will return
3940
* a list of the most recent 50 maintenance, inclusive of all statuses.
4041
*/
41-
export const getAllMaintenance = async (): Promise<MaintenanceResponse> => {
42+
export const getAllMaintenance = async (
43+
statusPageUrl?: string,
44+
): Promise<MaintenanceResponse> => {
45+
const STATUS_PAGE_URL = statusPageUrl ?? 'https://status.linode.com/api/v2';
46+
4247
try {
4348
const response = await fetch(
44-
`${LINODE_STATUS_PAGE_URL}/scheduled-maintenances.json`
49+
`${STATUS_PAGE_URL}/scheduled-maintenances.json`,
4550
);
4651

4752
if (!response.ok) {
@@ -52,7 +57,7 @@ export const getAllMaintenance = async (): Promise<MaintenanceResponse> => {
5257
} catch (error) {
5358
return handleError(
5459
error as APIError,
55-
'Error retrieving maintenance events.'
60+
'Error retrieving maintenance events.',
5661
);
5762
}
5863
};
Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
11
import { queryPresets } from '@linode/queries';
2-
import { createQueryKeys } from '@lukemorales/query-key-factory';
32
import { useQuery } from '@tanstack/react-query';
43

5-
import { getAllMaintenance, getIncidents } from './requests';
4+
import { statusPageQueries } from './keys';
65

76
import type { IncidentResponse, MaintenanceResponse } from './types';
87
import type { APIError } from '@linode/api-v4/lib/types';
98
import type { UseQueryOptions } from '@tanstack/react-query';
109

11-
export const statusPageQueries = createQueryKeys('statusPage', {
12-
incidents: {
13-
queryFn: getIncidents,
14-
queryKey: null,
15-
},
16-
maintenance: {
17-
queryFn: getAllMaintenance,
18-
queryKey: null,
19-
},
20-
});
21-
22-
export const useIncidentQuery = () =>
10+
export const useIncidentQuery = (
11+
statusPageUrl?: string,
12+
options?: Partial<UseQueryOptions<IncidentResponse, APIError[]>>,
13+
) =>
2314
useQuery<IncidentResponse, APIError[]>({
24-
...statusPageQueries.incidents,
15+
...statusPageQueries.incidents(statusPageUrl),
2516
...queryPresets.shortLived,
17+
...(options ?? {}),
2618
});
2719

2820
export const useMaintenanceQuery = (
29-
options?: Partial<UseQueryOptions<MaintenanceResponse, APIError[]>>
21+
statusPageUrl?: string,
22+
options?: Partial<UseQueryOptions<MaintenanceResponse, APIError[]>>,
3023
) =>
3124
useQuery<MaintenanceResponse, APIError[]>({
32-
...statusPageQueries.maintenance,
25+
...statusPageQueries.maintenance(statusPageUrl),
3326
...queryPresets.shortLived,
3427
...(options ?? {}),
3528
});

0 commit comments

Comments
 (0)