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
Expand Up @@ -24,8 +24,8 @@ const messageTemplatesProps: {
templateStatus: 'SUBMITTED',
name: 'Template 2',
message: 'Message',
createdAt: '2021-02-01T00:00:00.000Z',
updatedAt: '2021-02-01T00:00:00.000Z',
createdAt: '2021-01-01T00:00:00.000Z',
updatedAt: '2021-03-01T00:00:00.000Z',
},
{
id: '3',
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('MessageTemplates component', () => {
).toBeInTheDocument();
expect(
screen.getByTestId('manage-template-table-header-template-date-created')
).toHaveTextContent(messageTemplatesContent.tableHeadings.dateCreated);
).toHaveTextContent(messageTemplatesContent.tableHeadings.lastEdited);
expect(
screen.getByTestId('manage-template-table-header-action')
).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1
data-testid="manage-template-table-header-template-date-created"
scope="col"
>
Date created
Last edited
</th>
<th
class="nhsuk-table__header"
Expand Down Expand Up @@ -139,7 +139,7 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Jan 2021
<br />
Expand Down Expand Up @@ -251,9 +251,9 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
1st Mar 2021
<br />
00:00
</td>
Expand Down Expand Up @@ -352,7 +352,7 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
<br />
Expand Down Expand Up @@ -440,7 +440,7 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
<br />
Expand Down Expand Up @@ -538,7 +538,7 @@ exports[`MessageTemplates component matches snapshot with pending proof request
data-testid="manage-template-table-header-template-date-created"
scope="col"
>
Date created
Last edited
</th>
<th
class="nhsuk-table__header"
Expand Down Expand Up @@ -619,7 +619,7 @@ exports[`MessageTemplates component matches snapshot with pending proof request
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Jan 2021
<br />
Expand Down Expand Up @@ -731,9 +731,9 @@ exports[`MessageTemplates component matches snapshot with pending proof request
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
1st Mar 2021
<br />
00:00
</td>
Expand Down Expand Up @@ -832,7 +832,7 @@ exports[`MessageTemplates component matches snapshot with pending proof request
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
<br />
Expand Down Expand Up @@ -920,7 +920,7 @@ exports[`MessageTemplates component matches snapshot with pending proof request
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
<br />
Expand Down Expand Up @@ -1018,7 +1018,7 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] =
data-testid="manage-template-table-header-template-date-created"
scope="col"
>
Date created
Last edited
</th>
<th
class="nhsuk-table__header"
Expand Down Expand Up @@ -1099,7 +1099,7 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] =
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Jan 2021
<br />
Expand Down Expand Up @@ -1200,9 +1200,9 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] =
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
1st Mar 2021
<br />
00:00
</td>
Expand Down Expand Up @@ -1301,7 +1301,7 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] =
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
<br />
Expand Down Expand Up @@ -1389,7 +1389,7 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] =
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
<br />
Expand Down Expand Up @@ -1487,7 +1487,7 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat
data-testid="manage-template-table-header-template-date-created"
scope="col"
>
Date created
Last edited
</th>
<th
class="nhsuk-table__header"
Expand Down Expand Up @@ -1568,7 +1568,7 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Jan 2021
<br />
Expand Down Expand Up @@ -1656,9 +1656,9 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
1st Mar 2021
<br />
00:00
</td>
Expand Down Expand Up @@ -1757,7 +1757,7 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
<br />
Expand Down Expand Up @@ -1845,7 +1845,7 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat
aria-hidden="true"
class="nhsuk-table-responsive__heading"
>
Date created
Last edited
</span>
1st Feb 2021
<br />
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/__tests__/utils/form-actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,23 +490,23 @@ describe('form-actions', () => {
await expect(getTemplates()).rejects.toThrow('Failed to get access token');
});

test('getTemplates - order by createdAt and then id', async () => {
test('getTemplates - order by updatedAt and then id', async () => {
const baseTemplate = {
templateType: 'SMS',
templateStatus: 'NOT_YET_SUBMITTED',
name: 'Template',
message: 'Message',
updatedAt: '2021-01-01T00:00:00.000Z',
createdAt: '2020-01-01T00:00:00.000Z',
} satisfies Partial<TemplateDto>;

const templates = [
{ ...baseTemplate, id: '06', createdAt: '2022-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '08', createdAt: '2020-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '05', createdAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '02', createdAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '01', createdAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '03', createdAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '04', createdAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '06', updatedAt: '2022-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '08', updatedAt: '2020-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '05', updatedAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '02', updatedAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '01', updatedAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '03', updatedAt: '2021-01-01T00:00:00.000Z' },
{ ...baseTemplate, id: '04', updatedAt: '2021-01-01T00:00:00.000Z' },
];

// 06 is the newest, 08 is the oldest.
Expand Down
20 changes: 10 additions & 10 deletions frontend/src/__tests__/utils/message-plans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Message plans actions', () => {
const fields = {
status: 'DRAFT',
name: 'Routing config',
updatedAt: '2021-01-01T00:00:00.000Z',
createdAt: '2020-01-01T00:00:00.000Z',
campaignId: 'campaignId',
clientId: 'clientId',
cascade: [
Expand All @@ -65,48 +65,48 @@ describe('Message plans actions', () => {
},
],
cascadeGroupOverrides: [{ name: 'standard' }],
} satisfies Omit<RoutingConfig, 'id' | 'createdAt'>;
} satisfies Omit<RoutingConfig, 'id' | 'updatedAt'>;

const routingConfigs = [
{
...fields,
id: 'a487ed49-e2f7-4871-ac8d-0c6c682c71f5',
createdAt: '2022-01-01T00:00:00.000Z',
updatedAt: '2022-01-01T00:00:00.000Z',
},
{
...fields,
id: '8f5157fe-72d7-4a9c-818f-77c128ec8197',
createdAt: '2020-01-01T00:00:00.000Z',
updatedAt: '2020-01-01T00:00:00.000Z',
},
{
...fields,
id: '9be9d25f-81d8-422a-a85c-2fa9019cde1e',
createdAt: '2021-01-01T00:00:00.000Z',
updatedAt: '2021-01-01T00:00:00.000Z',
},
{
...fields,
id: '1cfdd62d-9eca-4f15-9772-1937d4524c37',
createdAt: '2021-01-01T00:00:00.000Z',
updatedAt: '2021-01-01T00:00:00.000Z',
},
{
...fields,
id: '18da6158-07ef-455c-9c31-1a4d78a133cf',
createdAt: '2021-01-01T00:00:00.000Z',
updatedAt: '2021-01-01T00:00:00.000Z',
},
{
...fields,
id: '87fb5cbf-708d-49c3-9360-3e37efdc5278',
createdAt: '2021-01-01T00:00:00.000Z',
updatedAt: '2021-01-01T00:00:00.000Z',
},
{
...fields,
id: '0d6408fd-57ea-42f2-aae1-ed9614b67068',
createdAt: '2021-01-01T00:00:00.000Z',
updatedAt: '2021-01-01T00:00:00.000Z',
},
];

// a48... is the newest, 8f5... is the oldest.
// the others all have the same createdAt.
// the others all have the same updatedAt.
const expectedOrder = [
'a487ed49-e2f7-4871-ac8d-0c6c682c71f5',
'0d6408fd-57ea-42f2-aae1-ed9614b67068',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function MessageTemplates({
{messageTemplatesContent.tableHeadings.status}
</Table.Cell>
<Table.Cell data-testid='manage-template-table-header-template-date-created'>
{messageTemplatesContent.tableHeadings.dateCreated}
{messageTemplatesContent.tableHeadings.lastEdited}
</Table.Cell>
<Table.Cell data-testid='manage-template-table-header-action'>
{messageTemplatesContent.tableHeadings.action.text}
Expand All @@ -90,9 +90,9 @@ export function MessageTemplates({
</Tag>
</Table.Cell>
<Table.Cell>
{format(`${template.createdAt}`, 'do MMM yyyy')}
{format(`${template.updatedAt}`, 'do MMM yyyy')}
<br />
{format(`${template.createdAt}`, 'HH:mm')}
{format(`${template.updatedAt}`, 'HH:mm')}
</Table.Cell>
<Table.Cell>
<div className={style.actionLinksWrapper}>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ const messageTemplates = {
id: 'ID',
type: 'Type',
status: 'Status',
dateCreated: 'Date created',
lastEdited: 'Last edited',
action: { text: 'Action', copy: 'Copy', delete: 'Delete' },
},
createTemplateButton: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/form-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { logger } from 'nhs-notify-web-template-management-utils/logger';
import { templateApiClient } from 'nhs-notify-backend-client/src/template-api-client';
import { routingConfigurationApiClient } from 'nhs-notify-backend-client/src/routing-config-api-client';
import { sortAscByCreatedAt } from './sort';
import { sortAscByUpdatedAt } from './sort';

export async function createTemplate(
template: CreateUpdateTemplate
Expand Down Expand Up @@ -188,7 +188,7 @@ export async function getTemplates(): Promise<TemplateDto[]> {
(template): template is ValidatedTemplateDto => template !== undefined
);

return sortAscByCreatedAt(sortedData);
return sortAscByUpdatedAt(sortedData);
}

export async function createRoutingConfig(
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/message-plans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { routingConfigurationApiClient } from 'nhs-notify-backend-client/src/routing-config-api-client';
import { logger } from 'nhs-notify-web-template-management-utils/logger';
import { getSessionServer } from './amplify-utils';
import { sortAscByCreatedAt } from './sort';
import { sortAscByUpdatedAt } from './sort';

export async function getRoutingConfigs(): Promise<RoutingConfig[]> {
const { accessToken } = await getSessionServer();
Expand All @@ -32,7 +32,7 @@ export async function getRoutingConfigs(): Promise<RoutingConfig[]> {
return success;
});

return sortAscByCreatedAt(valid);
return sortAscByUpdatedAt(valid);
}

export async function countRoutingConfigs(
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/utils/sort.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const sortAscByCreatedAt = <T>(
items: T & { createdAt: string; id: string }[]
export const sortAscByUpdatedAt = <T>(
items: T & { updatedAt: string; id: string }[]
) =>
items.sort((a, b) => {
const aCreatedAt = a.createdAt;
const bCreatedAt = b.createdAt;
const aUpdatedAt = a.updatedAt;
const bUpdatedAt = b.updatedAt;

if (aCreatedAt === bCreatedAt) {
if (aUpdatedAt === bUpdatedAt) {
return a.id.localeCompare(b.id);
}
return aCreatedAt < bCreatedAt ? 1 : -1;
return aUpdatedAt < bUpdatedAt ? 1 : -1;
});
Loading
Loading