Skip to content

Commit 49e83ad

Browse files
committed
add display mapping
1 parent 0d93d1f commit 49e83ad

File tree

6 files changed

+48
-21
lines changed

6 files changed

+48
-21
lines changed

frontend/src/__tests__/components/molecules/MessagePlans.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('MessagePlans', () => {
7474
{
7575
count: draft.count,
7676
plans: draft.plans,
77-
statusGroup: 'Draft',
77+
status: 'DRAFT',
7878
},
7979
undefined
8080
);
@@ -84,7 +84,7 @@ describe('MessagePlans', () => {
8484
{
8585
count: production.count,
8686
plans: production.plans,
87-
statusGroup: 'Production',
87+
status: 'COMPLETED',
8888
},
8989
undefined
9090
);

frontend/src/__tests__/components/molecules/MessagePlansList.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('MessagePlansList', () => {
1616

1717
const container = render(
1818
<MessagePlansList
19-
statusGroup='Draft'
19+
status='DRAFT'
2020
count={draft.count}
2121
plans={draft.plans}
2222
/>
@@ -27,7 +27,7 @@ describe('MessagePlansList', () => {
2727

2828
it('matches snapshot when no data is available', async () => {
2929
const container = render(
30-
<MessagePlansList statusGroup='Draft' count={0} plans={[]} />
30+
<MessagePlansList status='DRAFT' count={0} plans={[]} />
3131
);
3232

3333
expect(container.asFragment()).toMatchSnapshot();
@@ -47,7 +47,7 @@ describe('MessagePlansList', () => {
4747

4848
render(
4949
<MessagePlansList
50-
statusGroup='Draft'
50+
status='DRAFT'
5151
count={draft.count}
5252
plans={draft.plans}
5353
/>

frontend/src/components/molecules/MessagePlans/MessagePlans.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ export const MessagePlans = (props: MessagePlansProps) => {
5959
<Button id='create-message-plan-button'>{button.text}</Button>
6060
</Link>
6161
<MessagePlansList
62-
statusGroup='Draft'
62+
status='DRAFT'
6363
plans={props.draft.plans}
6464
count={props.draft.count}
6565
/>
6666
<MessagePlansList
67-
statusGroup='Production'
67+
status='COMPLETED'
6868
plans={props.production.plans}
6969
count={props.production.count}
7070
/>

frontend/src/components/molecules/MessagePlansList/MessagePlansList.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Details, Table } from 'nhsuk-react-components';
66
import { format } from 'date-fns/format';
77
import Link from 'next/link';
88
import { MarkdownContent } from '@molecules/MarkdownContent/MarkdownContent';
9+
import { RoutingConfigStatus } from 'nhs-notify-backend-client';
10+
import { messagePlanStatusToDisplayText } from 'nhs-notify-web-template-management-utils';
911

1012
export type MessagePlanListItem = {
1113
name: string;
@@ -14,7 +16,7 @@ export type MessagePlanListItem = {
1416
};
1517

1618
type MessagePlansListProps = {
17-
statusGroup: 'Draft' | 'Production';
19+
status: Exclude<RoutingConfigStatus, 'DELETED'>;
1820
count: number;
1921
plans: MessagePlanListItem[];
2022
};
@@ -24,7 +26,9 @@ const {
2426
} = content;
2527

2628
export const MessagePlansList = (props: MessagePlansListProps) => {
27-
const { statusGroup, count } = props;
29+
const { status, count } = props;
30+
const statusDisplayMapping = messagePlanStatusToDisplayText(status);
31+
const statusDisplayLower = statusDisplayMapping.toLowerCase();
2832

2933
const header = (
3034
<Table.Row>
@@ -55,11 +59,11 @@ export const MessagePlansList = (props: MessagePlansListProps) => {
5559
));
5660

5761
return (
58-
<Details expander id={`message-plans-list-${statusGroup.toLowerCase()}`}>
62+
<Details expander id={`message-plans-list-${statusDisplayLower}`}>
5963
<Details.Summary
6064
className={classNames('nhsuk-heading-s', 'nhsuk-u-margin-bottom-0')}
6165
>
62-
{statusGroup} ({count})
66+
{statusDisplayMapping} ({count})
6367
</Details.Summary>
6468
<Details.Text>
6569
{rows.length > 0 ? (
@@ -70,7 +74,7 @@ export const MessagePlansList = (props: MessagePlansListProps) => {
7074
) : (
7175
<MarkdownContent
7276
content={messagePlanComponent.noMessagePlansMessage}
73-
variables={{ status: statusGroup.toLowerCase() }}
77+
variables={{ status: statusDisplayLower }}
7478
/>
7579
)}
7680
</Details.Text>

utils/utils/src/__tests__/enum.test.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ import {
88
import {
99
alphabeticalLanguageList,
1010
alphabeticalLetterTypeList,
11+
isRightToLeft,
12+
languageMapping,
1113
letterTypeDisplayMappings,
12-
previewTemplatePages,
13-
templateTypeDisplayMappings,
14-
templateTypeToUrlTextMappings,
14+
messagePlanStatusToDisplayText,
1515
previewSubmittedTemplatePages,
16+
previewTemplatePages,
17+
statusToColourMapping,
18+
statusToDisplayMapping,
19+
templateCreationPages,
1620
templateDisplayCopyAction,
1721
templateDisplayDeleteAction,
18-
isRightToLeft,
19-
languageMapping,
20-
templateCreationPages,
21-
statusToDisplayMapping,
22-
statusToColourMapping,
22+
templateTypeDisplayMappings,
23+
templateTypeToUrlTextMappings,
2324
} from '../enum';
2425
import { TEMPLATE_STATUS_LIST } from 'nhs-notify-backend-client';
2526

@@ -335,3 +336,13 @@ describe('Right-to-left language indicator', () => {
335336
expect(result).toEqual(expectedRtlLanguages);
336337
});
337338
});
339+
340+
describe('messagePlanStatusToDisplayText', () => {
341+
test.each([
342+
['DRAFT', 'Draft'],
343+
['COMPLETED', 'Production'],
344+
['DELETED', ''],
345+
] as const)('should map %s to "%s"', (status, expected) => {
346+
expect(messagePlanStatusToDisplayText(status)).toBe(expected);
347+
});
348+
});

utils/utils/src/enum.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import {
1+
import type {
22
TemplateType,
33
TemplateStatus,
44
LetterType,
55
Language,
66
TemplateDto,
7+
RoutingConfigStatus,
78
} from 'nhs-notify-backend-client';
89

910
/**
@@ -258,3 +259,14 @@ export const templateDisplayDeleteAction = ({
258259
export function isRightToLeft(language: Language): boolean {
259260
return languageMap[language].rtl;
260261
}
262+
263+
const messagePlanStatusToDisplayMappings: Record<RoutingConfigStatus, string> =
264+
{
265+
DRAFT: 'Draft',
266+
COMPLETED: 'Production',
267+
DELETED: '',
268+
} as const;
269+
270+
export const messagePlanStatusToDisplayText = (
271+
status: RoutingConfigStatus
272+
): string => messagePlanStatusToDisplayMappings[status];

0 commit comments

Comments
 (0)