Skip to content

Commit

Permalink
upcoming: [M3-7213] - DC Get Well endpoints, queries, and mock data (#…
Browse files Browse the repository at this point in the history
…9860)

* endpoints and endpoint types for dc get well

* dc get well react query

* mock data

* update endpoint oops

* changesets

* fix mock data

* update to region capabilities

* Update packages/manager/.changeset/pr-9860-upcoming-features-1698852576816.md

Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com>

* Update packages/api-v4/.changeset/pr-9860-upcoming-features-1698852464578.md

Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com>

---------

Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com>
  • Loading branch information
coliu-akamai and dwiley-akamai authored Nov 1, 2023
1 parent edbb12f commit e9e4aef
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Upcoming Features
---

Add `getAccountAvailabilities` and `getAccountAvailability` methods for DC Get Well initiative ([#9860](https://github.com/linode/manager/pull/9860))
38 changes: 37 additions & 1 deletion packages/api-v4/src/account/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ import {
UpdateAccountSettingsSchema,
} from '@linode/validation/lib/account.schema';
import { API_ROOT, BETA_API_ROOT } from '../constants';
import Request, { setData, setMethod, setURL } from '../request';
import Request, {
setData,
setMethod,
setURL,
setParams,
setXFilter,
} from '../request';
import {
Account,
AccountAvailability,
AccountSettings,
CancelAccount,
CancelAccountPayload,
Agreements,
RegionalNetworkUtilization,
} from './types';
import { Filter, ResourcePage as Page, Params } from '../types';

/**
* getAccountInfo
Expand Down Expand Up @@ -99,6 +107,34 @@ export const getAccountAgreements = () =>
setMethod('GET')
);

/**
* getAccountAvailabilities
*
* Gets the account's entity availability for each region. Specifically
* tells which entities the account does not have capability for in each region.
*
*/
export const getAccountAvailabilities = (params?: Params, filter?: Filter) =>
Request<Page<AccountAvailability>>(
setURL(`${API_ROOT}/account/availability`),
setMethod('GET'),
setParams(params),
setXFilter(filter)
);

/**
* getAccountAvailability
*
* Gets the account's entity availability for given region. Specifically
* tells which entities the account does not have capability for in given region.
*
*/
export const getAccountAvailability = (regionId: string) =>
Request<AccountAvailability>(
setURL(`${API_ROOT}/account/availability/${encodeURIComponent(regionId)}`),
setMethod('GET')
);

/**
* signAgreement
*
Expand Down
7 changes: 6 additions & 1 deletion packages/api-v4/src/account/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIWarning } from '../types';
import type { Region } from '../regions';
import type { Capabilities, Region } from '../regions';

export interface User {
username: string;
Expand Down Expand Up @@ -69,6 +69,11 @@ export type AccountCapability =
| 'Vlans'
| 'VPCs';

export interface AccountAvailability {
id: string; // will be ID of region
unavailable: Capabilities[];
}

export interface AccountSettings {
managed: boolean;
longview_subscription: string | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Add RQ queries and mock data for DC Get Well ([#9860](https://github.com/linode/manager/pull/9860))
14 changes: 14 additions & 0 deletions packages/manager/src/factories/accountAvailability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AccountAvailability } from '@linode/api-v4';
import * as Factory from 'factory.ts';

import { pickRandom } from 'src/utilities/random';

export const accountAvailabilityFactory = Factory.Sync.makeFactory<AccountAvailability>(
{
id: pickRandom(['us-mia', 'ap-south', 'ap-northeast']),
unavailable: pickRandom([
['Block Storage'],
['Linodes', 'Block Storage', 'Kubernetes', 'NodeBalancers'],
]),
}
);
1 change: 1 addition & 0 deletions packages/manager/src/factories/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './account';
export * from './accountAvailability';
export * from './accountSettings';
export * from './accountMaintenance';
export * from './accountOAuth';
Expand Down
19 changes: 19 additions & 0 deletions packages/manager/src/mocks/serverHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MockData } from 'src/dev-tools/mockDataController';
import {
VLANFactory,
abuseTicketNotificationFactory,
accountAvailabilityFactory,
accountBetaFactory,
accountFactory,
accountMaintenanceFactory,
Expand Down Expand Up @@ -1007,6 +1008,24 @@ export const handlers = [
});
return res(ctx.json(account));
}),
rest.get('*/account/availability', (req, res, ctx) => {
const florida = accountAvailabilityFactory.build({
id: 'us-mia',
unavailable: ['Block Storage'],
});
const singapore = accountAvailabilityFactory.build({
id: 'ap-south',
unavailable: ['Linodes', 'Block Storage', 'Kubernetes', 'NodeBalancers'],
});
const tokyo = accountAvailabilityFactory.build({
id: 'ap-northeast',
unavailable: ['Linodes', 'Block Storage', 'Kubernetes', 'NodeBalancers'],
});
return res(ctx.json(makeResourcePage([florida, singapore, tokyo])));
}),
rest.get('*/account/availability/:regionId', (req, res, ctx) => {
return res(ctx.json(accountAvailabilityFactory.build()));
}),
rest.put('*/account', (req, res, ctx) => {
return res(ctx.json({ ...accountFactory.build(), ...(req.body as any) }));
}),
Expand Down
42 changes: 42 additions & 0 deletions packages/manager/src/queries/accountAvailability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
AccountAvailability,
getAccountAvailabilities,
getAccountAvailability,
} from '@linode/api-v4/lib/account';
import {
APIError,
Filter,
Params,
ResourcePage,
} from '@linode/api-v4/lib/types';
import { useQuery } from 'react-query';

const queryKey = 'account-availability';

export const useAccountAvailabilitiesQuery = (
params: Params,
filter: Filter,
enabled: boolean = true
) => {
return useQuery<ResourcePage<AccountAvailability>, APIError[]>(
[queryKey, 'paginated', params, filter],
() => getAccountAvailabilities(params, filter),
{
enabled,
keepPreviousData: true,
}
);
};

export const useAccountAvailabilityQuery = (
id: string,
enabled: boolean = true
) => {
return useQuery<AccountAvailability, APIError[]>(
[queryKey, 'accountAvailability', id],
() => getAccountAvailability(id),
{
enabled,
}
);
};

0 comments on commit e9e4aef

Please sign in to comment.