Skip to content

Commit c92c889

Browse files
Fix DMARC Summary Report Pagination (canada-ca#2061)
* Refactor to move pagination controls out of DmarcReportTable * Switch Dmarc Summary query to use findMyDmarcSummaries * Fix formatting code for new query * Add cache type policy for findMyDmarcSummaries * Make page size options more consistent * Update dmarcReportSummaryTable fixture, tests pass
1 parent 4e45bd0 commit c92c889

7 files changed

Lines changed: 79 additions & 114 deletions

File tree

frontend/src/DmarcByDomainPage.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ErrorBoundary } from 'react-error-boundary'
1010
import { ErrorFallbackMessage } from './ErrorFallbackMessage'
1111
import { LoadingMessage } from './LoadingMessage'
1212
import { usePaginatedCollection } from './usePaginatedCollection'
13+
import { RelayPaginationControls } from './RelayPaginationControls'
1314

1415
export default function DmarcByDomainPage() {
1516
const { currentUser } = useUserState()
@@ -23,6 +24,7 @@ export default function DmarcByDomainPage() {
2324
`LAST30DAYS, ${currentDate.getFullYear()}`,
2425
)
2526
const [selectedTableDisplayLimit, setSelectedTableDisplayLimit] = useState(10)
27+
const displayLimitOptions = [5, 10, 20, 50, 100]
2628

2729
const {
2830
loading,
@@ -31,6 +33,7 @@ export default function DmarcByDomainPage() {
3133
nodes,
3234
next,
3335
previous,
36+
resetToFirstPage,
3437
hasNextPage,
3538
hasPreviousPage,
3639
} = usePaginatedCollection({
@@ -41,7 +44,7 @@ export default function DmarcByDomainPage() {
4144
month: selectedPeriod,
4245
year: selectedYear,
4346
},
44-
relayRoot: 'findMyDomains',
47+
relayRoot: 'findMyDmarcSummaries',
4548
})
4649

4750
if (error) return <ErrorFallbackMessage error={error} />
@@ -61,8 +64,8 @@ export default function DmarcByDomainPage() {
6164
else if (nodes.length > 0) {
6265
const formattedData = []
6366
nodes.forEach((node) => {
64-
const domain = node.domain
65-
const percentages = { ...node.dmarcSummaryByPeriod.categoryPercentages }
67+
const domain = node.domain.domain
68+
const percentages = { ...node.categoryPercentages }
6669
Object.entries(percentages).forEach(([key, value]) => {
6770
if (typeof value === 'number') percentages[key] = Math.round(value)
6871
})
@@ -131,16 +134,6 @@ export default function DmarcByDomainPage() {
131134
},
132135
]
133136

134-
const displayLimitOptions = [5, 10, 20, 50, 100]
135-
const paginationConfig = {
136-
previous: previous,
137-
hasPreviousPage: hasPreviousPage,
138-
next: next,
139-
hasNextPage: hasNextPage,
140-
displayLimitOptions: displayLimitOptions,
141-
isLoadingMore: isLoadingMore,
142-
}
143-
144137
tableDisplay = (
145138
<DmarcReportTable
146139
data={formattedData}
@@ -153,9 +146,7 @@ export default function DmarcByDomainPage() {
153146
prependLink="domains/"
154147
appendLink={`/dmarc-report/${selectedPeriod}/${selectedYear}`}
155148
frontendPagination={false}
156-
paginationConfig={paginationConfig}
157149
selectedDisplayLimit={selectedTableDisplayLimit}
158-
setSelectedDisplayLimit={setSelectedTableDisplayLimit}
159150
/>
160151
)
161152
}
@@ -241,6 +232,18 @@ export default function DmarcByDomainPage() {
241232
<ErrorBoundary FallbackComponent={ErrorFallbackMessage}>
242233
{tableDisplay}
243234
</ErrorBoundary>
235+
<RelayPaginationControls
236+
onlyPagination={false}
237+
selectedDisplayLimit={selectedTableDisplayLimit}
238+
setSelectedDisplayLimit={setSelectedTableDisplayLimit}
239+
displayLimitOptions={displayLimitOptions}
240+
resetToFirstPage={resetToFirstPage}
241+
hasNextPage={hasNextPage}
242+
hasPreviousPage={hasPreviousPage}
243+
next={next}
244+
previous={previous}
245+
isLoadingMore={isLoadingMore}
246+
/>
244247
</Box>
245248
)
246249
}

frontend/src/DmarcReportTable.js

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
useSortBy,
88
useTable,
99
} from 'react-table'
10-
import { array, bool, func, number, shape, string } from 'prop-types'
10+
import { array, bool, number, string } from 'prop-types'
1111
import {
1212
Box,
1313
Button,
@@ -24,7 +24,6 @@ import { Link as RouteLink } from 'react-router-dom'
2424
import { t, Trans } from '@lingui/macro'
2525
import WithPseudoBox from './withPseudoBox'
2626
import ReactTableGlobalFilter from './ReactTableGlobalFilter'
27-
import { RelayPaginationControls } from './RelayPaginationControls'
2827

2928
const Table = styled.table`
3029
width: calc(100% - 2px);
@@ -128,14 +127,10 @@ function DmarcReportTable({ ...props }) {
128127
prependLink,
129128
appendLink,
130129
frontendPagination,
131-
paginationConfig,
132130
selectedDisplayLimit = window.matchMedia('screen and (max-width: 760px)')
133131
.matches
134132
? 5
135133
: 10,
136-
setSelectedDisplayLimit,
137-
currentPage,
138-
setCurrentPage,
139134
} = props
140135
const [show, setShow] = React.useState(true)
141136
const [firstRender, setFirstRender] = React.useState(true)
@@ -320,28 +315,7 @@ function DmarcReportTable({ ...props }) {
320315
</Stack>
321316
</Stack>
322317
</Box>
323-
) : (
324-
<RelayPaginationControls
325-
previous={() => {
326-
paginationConfig.previous()
327-
}}
328-
hasPreviousPage={paginationConfig.hasPreviousPage}
329-
next={() => {
330-
if (paginationConfig.hasNextPage && !canNextPage)
331-
paginationConfig.next()
332-
else {
333-
setCurrentPage(currentPage + 1)
334-
}
335-
}}
336-
hasNextPage={paginationConfig.hasNextPage}
337-
selectedDisplayLimit={selectedDisplayLimit}
338-
setSelectedDisplayLimit={setSelectedDisplayLimit}
339-
displayLimitOptions={paginationConfig.displayLimitOptions}
340-
gotoPage={gotoPage}
341-
isLoadingMore={paginationConfig.isLoadingMore}
342-
mt="10px"
343-
/>
344-
)
318+
) : ("")
345319

346320
return (
347321
<Box ref={wrapperRef}>
@@ -430,18 +404,7 @@ DmarcReportTable.propTypes = {
430404
prependLink: string,
431405
appendLink: string,
432406
frontendPagination: bool,
433-
paginationConfig: shape({
434-
previous: func,
435-
hasPreviousPage: bool,
436-
next: func,
437-
hasNextPage: bool,
438-
displayLimitOptions: array,
439-
isLoadingMore: bool,
440-
}),
441407
selectedDisplayLimit: number,
442-
setSelectedDisplayLimit: func,
443-
currentPage: number,
444-
setCurrentPage: func,
445408
}
446409

447410
DmarcReportTable.defaultProps = {

frontend/src/DomainsPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export default function DomainsPage() {
166166
onlyPagination={false}
167167
selectedDisplayLimit={domainsPerPage}
168168
setSelectedDisplayLimit={setDomainsPerPage}
169-
displayLimitOptions={[10, 20, 40, 80]}
169+
displayLimitOptions={[5, 10, 20, 50, 100]}
170170
resetToFirstPage={resetToFirstPage}
171171
hasNextPage={hasNextPage}
172172
hasPreviousPage={hasPreviousPage}

frontend/src/Organizations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export default function Organisations() {
165165
onlyPagination={false}
166166
selectedDisplayLimit={orgsPerPage}
167167
setSelectedDisplayLimit={setOrgsPerPage}
168-
displayLimitOptions={[10, 20, 40, 80]}
168+
displayLimitOptions={[5, 10, 20, 50, 100]}
169169
resetToFirstPage={resetToFirstPage}
170170
hasNextPage={hasNextPage}
171171
hasPreviousPage={hasPreviousPage}

frontend/src/client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function createCache() {
88
Query: {
99
fields: {
1010
findMyDomains: relayStylePagination(['first', 'orderBy', 'search']),
11+
findMyDmarcSummaries: relayStylePagination(['first']),
1112
findMyOrganizations: relayStylePagination(['first', 'orderBy', 'search']),
1213
},
1314
},
Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,48 @@
11
export const rawDmarcReportSummaryTableData = {
22
data: {
3-
findMyDomains: {
3+
findMyDmarcSummaries: {
44
edges: [
55
{
66
node: {
77
id: 'testid1=',
8-
domain: 'domain1.ca',
9-
dmarcSummaryByPeriod: {
10-
month: 'LAST30DAYS',
11-
year: '2021',
12-
domain: { domain: 'domain1.ca' },
13-
categoryPercentages: {
14-
failPercentage: 31.5,
15-
fullPassPercentage: 1.88,
16-
passDkimOnlyPercentage: 4.51,
17-
passSpfOnlyPercentage: 4.12,
18-
totalMessages: 7803,
19-
__typename: 'CategoryPercentages',
20-
},
21-
__typename: 'Period',
8+
domain: {
9+
domain: 'domain1.ca',
10+
__typename: 'Domain',
2211
},
23-
__typename: 'Domain',
12+
month: 'LAST30DAYS',
13+
year: '2021',
14+
categoryPercentages: {
15+
failPercentage: 31.5,
16+
fullPassPercentage: 1.88,
17+
passDkimOnlyPercentage: 4.51,
18+
passSpfOnlyPercentage: 4.12,
19+
totalMessages: 7803,
20+
__typename: 'CategoryPercentages',
21+
},
22+
__typename: 'DmarcSummary',
2423
},
25-
26-
__typename: 'DomainEdge',
24+
__typename: 'DmarcSummaryEdge',
2725
},
2826
{
2927
node: {
3028
id: 'testid2=',
31-
domain: 'domain2.ca',
32-
dmarcSummaryByPeriod: {
33-
month: 'LAST30DAYS',
34-
year: '2021',
35-
domain: { domain: 'domain2.ca' },
36-
categoryPercentages: {
37-
failPercentage: 31.5,
38-
fullPassPercentage: 1.88,
39-
passDkimOnlyPercentage: 4.51,
40-
passSpfOnlyPercentage: 4.12,
41-
totalMessages: 7803,
42-
__typename: 'CategoryPercentages',
43-
},
44-
__typename: 'Period',
29+
domain: {
30+
domain: 'domain2.ca',
31+
__typename: 'Domain',
32+
},
33+
month: 'LAST30DAYS',
34+
year: '2021',
35+
categoryPercentages: {
36+
failPercentage: 31.5,
37+
fullPassPercentage: 1.88,
38+
passDkimOnlyPercentage: 4.51,
39+
passSpfOnlyPercentage: 4.12,
40+
totalMessages: 7803,
41+
__typename: 'CategoryPercentages',
4542
},
46-
__typename: 'Domain',
43+
__typename: 'DmarcSummary',
4744
},
48-
49-
__typename: 'DomainEdge',
45+
__typename: 'DmarcSummaryEdge',
5046
},
5147
],
5248
pageInfo: {
@@ -56,7 +52,7 @@ export const rawDmarcReportSummaryTableData = {
5652
startCursor: 'startcursor=',
5753
__typename: 'PageInfo',
5854
},
59-
__typename: 'DomainConnection',
55+
__typename: 'DmarcSummaryConnection',
6056
},
6157
},
6258
}

frontend/src/graphql/queries.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,36 +1276,38 @@ export const PAGINATED_DMARC_REPORT_SUMMARY_TABLE = gql`
12761276
query PaginatedDmarcReportSummaryTable(
12771277
$month: PeriodEnums!
12781278
$year: Year!
1279-
$after: String
12801279
$first: Int
1280+
$after: String
12811281
) {
1282-
findMyDomains(after: $after, first: $first, ownership: true) {
1282+
findMyDmarcSummaries(
1283+
month: $month
1284+
year: $year
1285+
first: $first
1286+
after: $after
1287+
) {
1288+
pageInfo {
1289+
hasNextPage
1290+
hasPreviousPage
1291+
startCursor
1292+
endCursor
1293+
}
12831294
edges {
12841295
node {
12851296
id
1286-
domain
1287-
dmarcSummaryByPeriod(month: $month, year: $year) {
1288-
month
1289-
year
1290-
domain {
1291-
domain
1292-
}
1293-
categoryPercentages {
1294-
failPercentage
1295-
fullPassPercentage
1296-
passDkimOnlyPercentage
1297-
passSpfOnlyPercentage
1298-
totalMessages
1299-
}
1297+
month
1298+
year
1299+
domain {
1300+
domain
1301+
}
1302+
categoryPercentages {
1303+
failPercentage
1304+
fullPassPercentage
1305+
passDkimOnlyPercentage
1306+
passSpfOnlyPercentage
1307+
totalMessages
13001308
}
13011309
}
13021310
}
1303-
pageInfo {
1304-
hasNextPage
1305-
endCursor
1306-
hasPreviousPage
1307-
startCursor
1308-
}
13091311
}
13101312
}
13111313
`

0 commit comments

Comments
 (0)