Skip to content

Commit

Permalink
Add no results message to paginated data
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgain committed Mar 4, 2024
1 parent af7c189 commit ce65437
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 49 deletions.
4 changes: 4 additions & 0 deletions src/client/components/Resource/Paginated.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ const PaginatedResource = multiInstance({
onPageClick,
currentPage,
result,
noResults = "You don't have any results",
}) => (
<Route>
{({ location }) => {
const qsParams = qs.parse(location.search.slice(1))
const routePage = parseInt(qsParams.page, 10) || 1
const totalPages = result ? Math.ceil(result.count / pageSize) : 0
const hasZeroResults = result?.count === 0

return (
<Task>
Expand Down Expand Up @@ -122,6 +124,7 @@ const PaginatedResource = multiInstance({
}}
/>
)}

{result ? (
<LoadingBox name={name} id={id}>
<CollectionHeader
Expand Down Expand Up @@ -152,6 +155,7 @@ const PaginatedResource = multiInstance({
) : (
<Task.Status name={name} id={id} />
)}
{hasZeroResults && <p data-test="no-results">{noResults}</p>}
</>
)
}}
Expand Down
1 change: 1 addition & 0 deletions src/client/modules/ExportWins/Status/WinsRejectedList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import urls from '../../../../lib/urls'
export default () => (
<ExportWinsResource.Paginated
id="export-wins-rejected"
noResults="You don't have any rejected export wins."
payload={{ confirmed: WIN_FILTERS.REJECTED }}
>
{(page) => (
Expand Down
1 change: 1 addition & 0 deletions src/client/modules/ExportWins/Status/WinsSentList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import urls from '../../../../lib/urls'
export default () => (
<ExportWinsResource.Paginated
id="export-wins-sent"
noResults="You don't have any sent export wins."
payload={{ confirmed: WIN_FILTERS.SENT }}
>
{(page) => (
Expand Down
101 changes: 52 additions & 49 deletions src/client/modules/ExportWins/Status/WinsWonTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,63 @@ const NoWrapCell = styled(Table.Cell)`
white-space: nowrap;
`

export const WinsWonTable = ({ exportWins }) => (
<Table
head={
<Table.Row>
<Table.CellHeader>UK Company</Table.CellHeader>
<Table.CellHeader>Destination</Table.CellHeader>
<Table.CellHeader>Export amount</Table.CellHeader>
<Table.CellHeader>Date won</Table.CellHeader>
<Table.CellHeader>Date responded</Table.CellHeader>
<Table.CellHeader>Details</Table.CellHeader>
</Table.Row>
}
>
{exportWins.map(
({
id,
company,
country,
date,
total_expected_export_value,
customer_response,
}) => (
<Table.Row key={id}>
<Table.Cell>
<Link
as={ReactRouterLink}
to={urls.companies.overview.index(company.id)}
>
{company.name}
</Link>
</Table.Cell>
<Table.Cell>{country.name}</Table.Cell>
<Table.Cell>{currencyGBP(total_expected_export_value)}</Table.Cell>
<NoWrapCell>{formatMediumDate(date)}</NoWrapCell>
<NoWrapCell>
{formatMediumDate(customer_response.responded_on)}
</NoWrapCell>
<NoWrapCell>
<Link
as={ReactRouterLink}
to={urls.companies.exportWins.details(id)}
>
View details
</Link>
</NoWrapCell>
export const WinsWonTable = ({ exportWins }) => {
return exportWins.length === 0 ? null : (
<Table
head={
<Table.Row>
<Table.CellHeader>UK Company</Table.CellHeader>
<Table.CellHeader>Destination</Table.CellHeader>
<Table.CellHeader>Export amount</Table.CellHeader>
<Table.CellHeader>Date won</Table.CellHeader>
<Table.CellHeader>Date responded</Table.CellHeader>
<Table.CellHeader>Details</Table.CellHeader>
</Table.Row>
)
)}
</Table>
)
}
>
{exportWins.map(
({
id,
company,
country,
date,
total_expected_export_value,
customer_response,
}) => (
<Table.Row key={id}>
<Table.Cell>
<Link
as={ReactRouterLink}
to={urls.companies.overview.index(company.id)}
>
{company.name}
</Link>
</Table.Cell>
<Table.Cell>{country.name}</Table.Cell>
<Table.Cell>{currencyGBP(total_expected_export_value)}</Table.Cell>
<NoWrapCell>{formatMediumDate(date)}</NoWrapCell>
<NoWrapCell>
{formatMediumDate(customer_response.responded_on)}
</NoWrapCell>
<NoWrapCell>
<Link
as={ReactRouterLink}
to={urls.companies.exportWins.details(id)}
>
View details
</Link>
</NoWrapCell>
</Table.Row>
)
)}
</Table>
)
}

export default () => (
<ExportWinsResource.Paginated
id="export-wins-won"
noResults="You don't have any won export wins."
payload={{ confirmed: WIN_FILTERS.WON }}
>
{(page) => <WinsWonTable exportWins={page} />}
Expand Down
53 changes: 53 additions & 0 deletions test/component/cypress/specs/Resource/Paginated.cy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('Resource/Paginated', () => {
</DataHubProvider>
)

cy.get('[data-test="no-results"]').should('not.exist')

cy.get('pre').as('page').should('have.text', JSON.stringify(PAGES[0]))

cy.get('[data-test="pagination-summary"]')
Expand Down Expand Up @@ -108,4 +110,55 @@ describe('Resource/Paginated', () => {
cy.contains('Loading')
cy.get('pre').as('page').should('have.text', JSON.stringify(PAGES[0]))
})

it('Should render the default no results message', () => {
cy.mount(
<DataHubProvider
resetTasks={true}
tasks={{
foo: () => ({
count: 0,
results: [],
}),
}}
>
<PaginatedResource name="foo" id="whatever" pageSize={PAGE_SIZE}>
{(page) => <pre>{JSON.stringify(page)}</pre>}
</PaginatedResource>
</DataHubProvider>
)
cy.get('[data-test="pagination-summary"]').should('not.exist')
cy.get('[data-test="pagination"]').should('not.exist')
cy.get('[data-test="no-results"]').should(
'have.text',
"You don't have any results"
)
})

it('Should override the default results message"', () => {
cy.mount(
<DataHubProvider
resetTasks={true}
tasks={{
foo: () => ({
count: 0,
results: [],
}),
}}
>
<PaginatedResource
name="foo"
id="whatever"
pageSize={PAGE_SIZE}
noResults="You don't have any sent export wins."
>
{(page) => <pre>{JSON.stringify(page)}</pre>}
</PaginatedResource>
</DataHubProvider>
)
cy.get('[data-test="no-results"]').should(
'have.text',
"You don't have any sent export wins."
)
})
})

0 comments on commit ce65437

Please sign in to comment.