Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Removed
---

Move Status Page queries and dependencies to shared `queries` package ([#12468](https://github.com/linode/manager/pull/12468))
2 changes: 1 addition & 1 deletion packages/manager/src/factories/statusPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
IncidentUpdate,
Maintenance,
MaintenanceResponse,
} from 'src/queries/statusPage';
} from '@linode/queries';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { queryPresets } from '@linode/queries';
import { queryPresets, useMaintenanceQuery } from '@linode/queries';
import { Stack, Typography } from '@linode/ui';
import * as React from 'react';

import { DismissibleBanner } from 'src/components/DismissibleBanner/DismissibleBanner';
import { Link } from 'src/components/Link';
import { useMaintenanceQuery } from 'src/queries/statusPage';
import { LINODE_STATUS_PAGE_URL } from 'src/constants';
import { sanitizeHTML } from 'src/utilities/sanitizeHTML';

import type { Maintenance } from '@linode/queries';
import type { SuppliedMaintenanceData } from 'src/featureFlags';
import type { Maintenance } from 'src/queries/statusPage';

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

const { data: maintenancesData } = useMaintenanceQuery({
...queryPresets.oneTimeFetch,
});
const { data: maintenancesData } = useMaintenanceQuery(
LINODE_STATUS_PAGE_URL,
{
...queryPresets.oneTimeFetch,
}
);
const maintenances = maintenancesData?.scheduled_maintenances ?? [];

if (
Expand Down
7 changes: 4 additions & 3 deletions packages/manager/src/features/Help/StatusBanners.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useIncidentQuery } from '@linode/queries';
import { Box, Typography } from '@linode/ui';
import { capitalize, truncateEnd } from '@linode/utilities';
import { useTheme } from '@mui/material/styles';
Expand All @@ -6,13 +7,13 @@ import * as React from 'react';

import { DismissibleBanner } from 'src/components/DismissibleBanner/DismissibleBanner';
import { Link } from 'src/components/Link';
import { useIncidentQuery } from 'src/queries/statusPage';
import { LINODE_STATUS_PAGE_URL } from 'src/constants';
import { sanitizeHTML } from 'src/utilities/sanitizeHTML';

import type { IncidentImpact, IncidentStatus } from 'src/queries/statusPage';
import type { IncidentImpact, IncidentStatus } from '@linode/queries';

export const StatusBanners = () => {
const { data: incidentsData } = useIncidentQuery();
const { data: incidentsData } = useIncidentQuery(LINODE_STATUS_PAGE_URL);
const incidents = incidentsData?.incidents ?? [];

if (incidents.length === 0) {
Expand Down
5 changes: 5 additions & 0 deletions packages/queries/.changeset/pr-12468-added-1751563776473.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/queries": Added
---

`statusPage/` directory and migrated relevant query keys and hooks ([#12468](https://github.com/linode/manager/pull/12468))
1 change: 1 addition & 0 deletions packages/queries/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './profile';
export * from './quotas';
export * from './regions';
export * from './stackscripts';
export * from './statusPage';
export * from './support';
export * from './tags';
export * from './types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
* used through this query, all of this is contained within src/queries.
*/

export * from './keys';
export * from './requests';
export * from './statusPage';
export * from './types';
14 changes: 14 additions & 0 deletions packages/queries/src/statusPage/keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createQueryKeys } from '@lukemorales/query-key-factory';

import { getAllMaintenance, getIncidents } from './requests';

export const statusPageQueries = createQueryKeys('statusPage', {
incidents: (statusPageUrl?: string) => ({
queryKey: [statusPageUrl],
queryFn: () => getIncidents(statusPageUrl),
}),
maintenance: (statusPageUrl?: string) => ({
queryKey: [statusPageUrl],
queryFn: () => getAllMaintenance(statusPageUrl),
}),
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { LINODE_STATUS_PAGE_URL } from 'src/constants';

import type { IncidentResponse, MaintenanceResponse } from './types';
import type { APIError } from '@linode/api-v4';

Expand All @@ -18,10 +16,13 @@ const handleError = (error: APIError, defaultMessage: string) => {
/**
* Return a list of incidents with a status of "unresolved."
*/
export const getIncidents = async (): Promise<IncidentResponse> => {
export const getIncidents = async (
statusPageUrl?: string,
): Promise<IncidentResponse> => {
const STATUS_PAGE_URL = statusPageUrl ?? 'https://status.linode.com/api/v2';
try {
const response = await fetch(
`${LINODE_STATUS_PAGE_URL}/incidents/unresolved.json`
`${STATUS_PAGE_URL}/incidents/unresolved.json`,
);

if (!response.ok) {
Expand All @@ -38,10 +39,14 @@ export const getIncidents = async (): Promise<IncidentResponse> => {
* There are several endpoints for maintenance events; this method will return
* a list of the most recent 50 maintenance, inclusive of all statuses.
*/
export const getAllMaintenance = async (): Promise<MaintenanceResponse> => {
export const getAllMaintenance = async (
statusPageUrl?: string,
): Promise<MaintenanceResponse> => {
const STATUS_PAGE_URL = statusPageUrl ?? 'https://status.linode.com/api/v2';

try {
const response = await fetch(
`${LINODE_STATUS_PAGE_URL}/scheduled-maintenances.json`
`${STATUS_PAGE_URL}/scheduled-maintenances.json`,
);

if (!response.ok) {
Expand All @@ -52,7 +57,7 @@ export const getAllMaintenance = async (): Promise<MaintenanceResponse> => {
} catch (error) {
return handleError(
error as APIError,
'Error retrieving maintenance events.'
'Error retrieving maintenance events.',
);
}
};
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
import { queryPresets } from '@linode/queries';
import { createQueryKeys } from '@lukemorales/query-key-factory';
import { useQuery } from '@tanstack/react-query';

import { getAllMaintenance, getIncidents } from './requests';
import { statusPageQueries } from './keys';

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

export const statusPageQueries = createQueryKeys('statusPage', {
incidents: {
queryFn: getIncidents,
queryKey: null,
},
maintenance: {
queryFn: getAllMaintenance,
queryKey: null,
},
});

export const useIncidentQuery = () =>
export const useIncidentQuery = (
statusPageUrl?: string,
options?: Partial<UseQueryOptions<IncidentResponse, APIError[]>>,
) =>
useQuery<IncidentResponse, APIError[]>({
...statusPageQueries.incidents,
...statusPageQueries.incidents(statusPageUrl),
...queryPresets.shortLived,
...(options ?? {}),
});

export const useMaintenanceQuery = (
options?: Partial<UseQueryOptions<MaintenanceResponse, APIError[]>>
statusPageUrl?: string,
options?: Partial<UseQueryOptions<MaintenanceResponse, APIError[]>>,
) =>
useQuery<MaintenanceResponse, APIError[]>({
...statusPageQueries.maintenance,
...statusPageQueries.maintenance(statusPageUrl),
...queryPresets.shortLived,
...(options ?? {}),
});