Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tech-story: [M3-9017] - Add MSW crud domains #11428

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
49 changes: 12 additions & 37 deletions packages/manager/src/dev-tools/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function loadDevTools(
seedContext[key] = seeds[key];
};

const seeds = await populateSeeds(emptyStore);
const seeds = await populateSeeds(seedContext);

const seedPromises = (Object.keys(
seedContext
Expand All @@ -84,44 +84,19 @@ export async function loadDevTools(

await mswDB.saveStore(seedContext ?? emptyStore, 'seedState');

// Merge the contexts
const stateKeys: (keyof MockState)[] = Object.keys(
emptyStore
) as (keyof MockState)[];

const mergedContext: MockState = {
...initialContext,
eventQueue: [
...initialContext.eventQueue,
...(seedContext?.eventQueue || []),
],
firewalls: [
...initialContext.firewalls,
...(seedContext?.firewalls || []),
],
linodeConfigs: [
...initialContext.linodeConfigs,
...(seedContext?.linodeConfigs || []),
],
linodes: [...initialContext.linodes, ...(seedContext?.linodes || [])],
notificationQueue: [
...initialContext.notificationQueue,
...(seedContext?.notificationQueue || []),
],
placementGroups: [
...initialContext.placementGroups,
...(seedContext?.placementGroups || []),
],
regionAvailability: [
...initialContext.regionAvailability,
...(seedContext?.regionAvailability || []),
],
regions: [...initialContext.regions, ...(seedContext?.regions || [])],
supportReplies: [
...initialContext.supportReplies,
...(seedContext?.supportReplies || []),
],
supportTickets: [
...initialContext.supportTickets,
...(seedContext?.supportTickets || []),
],
volumes: [...initialContext.volumes, ...(seedContext?.volumes || [])],
...stateKeys.reduce(
(acc, key) => ({
...acc,
[key]: [...initialContext[key], ...(seedContext?.[key] || [])],
}),
{}
),
};

const extraHandlers = extraMswPresets.reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react';
import { SupportLink } from 'src/components/SupportLink';

interface MessageLinkEntity {
fallback?: string;
message: null | string;
}

Expand All @@ -15,10 +16,10 @@ interface MessageLinkEntity {
* - render "contact support" strings as <Link>.
*/
export const FormattedEventMessage = (props: MessageLinkEntity) => {
const { message } = props;
const { fallback, message } = props;

if (!message) {
return null;
return fallback ? fallback : null;
}

return formatMessage(message);
Expand Down
14 changes: 8 additions & 6 deletions packages/manager/src/features/Events/factories/domain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ export const domain: PartialEventMap<'domain'> = {
),
},
domain_record_create: {
notification: (e) => (
<>
<FormattedEventMessage message={e.message} /> has been{' '}
<strong>added</strong> to <EventLink event={e} to="entity" />.
</>
),
notification: (e) => {
return (
<>
<FormattedEventMessage fallback="A record" message={e.message} /> has
been <strong>added</strong> to <EventLink event={e} to="entity" />.
</>
);
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the case where there is no message associated with a DomainRecord added via importing a zone (most likely an APIv4 omission)

Screenshot 2024-12-16 at 16 01 31

},
domain_record_delete: {
notification: (e) => (
Expand Down
2 changes: 2 additions & 0 deletions packages/manager/src/mocks/mockState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const getStateSeederGroups = (
};

export const emptyStore: MockState = {
domainRecords: [],
domains: [],
eventQueue: [],
firewalls: [],
linodeConfigs: [],
Expand Down
2 changes: 2 additions & 0 deletions packages/manager/src/mocks/presets/baseline/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from 'src/mocks/presets/crud/handlers/events';
import { linodeCrudPreset } from 'src/mocks/presets/crud/linodes';

import { domainCrudPreset } from '../crud/domains';
import { placementGroupsCrudPreset } from '../crud/placementGroups';
import { supportTicketCrudPreset } from '../crud/supportTickets';
import { volumeCrudPreset } from '../crud/volumes';
Expand All @@ -17,6 +18,7 @@ export const baselineCrudPreset: MockPresetBaseline = {
...placementGroupsCrudPreset.handlers,
...supportTicketCrudPreset.handlers,
...volumeCrudPreset.handlers,
...domainCrudPreset.handlers,

// Events.
getEvents,
Expand Down
24 changes: 24 additions & 0 deletions packages/manager/src/mocks/presets/crud/domains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
cloneDomain,
createDomain,
deleteDomains,
getDomains,
importDomain,
updateDomain,
} from 'src/mocks/presets/crud/handlers/domains';

import type { MockPresetCrud } from 'src/mocks/types';

export const domainCrudPreset: MockPresetCrud = {
group: { id: 'Domains' },
handlers: [
createDomain,
deleteDomains,
updateDomain,
getDomains,
cloneDomain,
importDomain,
],
id: 'domains:crud',
label: 'Domains CRUD',
};
Loading
Loading