forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganizations.js
More file actions
258 lines (244 loc) · 7.72 KB
/
Organizations.js
File metadata and controls
258 lines (244 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import React, { useCallback, useState } from 'react'
import { t, Trans } from '@lingui/macro'
import { ListOf } from '../components/ListOf'
import {
Box,
Divider,
Flex,
Heading,
IconButton,
Input,
InputGroup,
InputLeftElement,
Select,
Stack,
Text,
} from '@chakra-ui/react'
import { SearchIcon, ArrowDownIcon, ArrowUpIcon } from '@chakra-ui/icons'
import { ErrorBoundary } from 'react-error-boundary'
import { OrganizationCard } from './OrganizationCard'
import { ErrorFallbackMessage } from '../components/ErrorFallbackMessage'
import { LoadingMessage } from '../components/LoadingMessage'
import { RelayPaginationControls } from '../components/RelayPaginationControls'
import { InfoButton, InfoBox, InfoPanel } from '../components/InfoPanel'
import { usePaginatedCollection } from '../utilities/usePaginatedCollection'
import { useDebouncedFunction } from '../utilities/useDebouncedFunction'
import { PAGINATED_ORGANIZATIONS as FORWARD } from '../graphql/queries'
export default function Organizations() {
const [orderDirection, setOrderDirection] = useState('ASC')
const [orderField, setOrderField] = useState('NAME')
const [searchTerm, setSearchTerm] = useState('')
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState('')
const [orgsPerPage, setOrgsPerPage] = useState(10)
const memoizedSetDebouncedSearchTermCallback = useCallback(() => {
setDebouncedSearchTerm(searchTerm)
}, [searchTerm])
useDebouncedFunction(memoizedSetDebouncedSearchTermCallback, 500)
const orderIconName =
orderDirection === 'ASC' ? <ArrowUpIcon /> : <ArrowDownIcon />
const [infoState, changeInfoState] = useState({
isVisible: false,
})
const {
loading,
isLoadingMore,
error,
nodes,
next,
previous,
resetToFirstPage,
hasNextPage,
hasPreviousPage,
} = usePaginatedCollection({
fetchForward: FORWARD,
variables: {
field: orderField,
direction: orderDirection,
search: debouncedSearchTerm,
includeSuperAdminOrg: false,
},
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first',
recordsPerPage: orgsPerPage,
relayRoot: 'findMyOrganizations',
})
if (error) return <ErrorFallbackMessage error={error} />
// Set the list contents only to loading message when loading
// Prevents select active option from resetting when loading
let orgList
if (loading) {
orgList = (
<LoadingMessage>
<Trans>Organizations</Trans>
</LoadingMessage>
)
} else {
orgList = (
<ListOf
elements={nodes}
ifEmpty={() => (
<Text layerStyle="loadingMessage">
<Trans>No Organizations</Trans>
</Text>
)}
mb="4"
>
{({ name, slug, acronym, domainCount, verified, summaries }, index) => (
<ErrorBoundary
key={`${slug}:${index}`}
FallbackComponent={ErrorFallbackMessage}
>
<Box>
<OrganizationCard
slug={slug}
name={name}
acronym={acronym}
domainCount={domainCount}
verified={verified}
summaries={summaries}
/>
<Divider borderColor="gray.900" />
</Box>
</ErrorBoundary>
)}
</ListOf>
)
}
return (
<Box w="100%" px={4}>
<Stack direction="row" justify="space-between" mb="4">
<Heading as="h1" textAlign="left">
<Trans>Organizations</Trans>
</Heading>
<InfoButton
label={t`Glossary`}
state={infoState}
changeState={changeInfoState}
/>
</Stack>
<InfoPanel state={infoState}>
<InfoBox
title={t`Organization Name`}
info={t`Displays the Name of the organization, its acronym, and a blue check mark if it is a verified organization.`}
/>
<InfoBox
title={t`Services`}
info={t`Shows the number of domains that the organization is in control of.`}
/>
<InfoBox
title={t`Web Configuration`}
info={t`Shows the percentage of Domains that have passed both HTTPS and SSL requiremnts.`}
/>
<InfoBox
title={t`Email Configuration`}
info={t`Shows the percentage of Domains that have passed the requirements for SPF, DKIM, and DMARC.`}
/>
<Divider borderColor="gray.500" mb={4} />
<Trans>
Further details for each organization can be found by clicking on its
row.
</Trans>
</InfoPanel>
<ErrorBoundary FallbackComponent={ErrorFallbackMessage}>
<Flex
direction={{ base: 'column', md: 'row' }}
alignItems={{ base: 'stretch', md: 'center' }}
mb={{ base: '4', md: '8' }}
>
<Flex
direction="row"
minW={{ base: '100%', md: '50%' }}
alignItems="center"
flexGrow={1}
mb={2}
>
<Text
as="label"
htmlFor="Search-for-field"
fontSize="md"
fontWeight="bold"
textAlign="center"
mr={2}
>
<Trans>Search: </Trans>
</Text>
<InputGroup flexGrow={1}>
<InputLeftElement aria-hidden="true">
<SearchIcon color="gray.300" />
</InputLeftElement>
<Input
id="Search-for-field"
type="text"
placeholder={t`Search for an organization`}
onChange={(e) => {
setSearchTerm(e.target.value)
resetToFirstPage()
}}
aria-label="Organization Search Bar"
/>
</InputGroup>
</Flex>
<Stack isInline align="center" ml={{ md: '5%' }}>
<Text
as="label"
htmlFor="Sort-by-field"
fontSize="md"
fontWeight="bold"
textAlign="center"
>
<Trans>Sort by: </Trans>
</Text>
<Select
id="Sort-by-field"
aria-label="Sort by field"
w="fit-content"
size="md"
variant="filled"
onChange={(e) => {
setOrderField(e.target.value)
resetToFirstPage()
}}
>
<option key="NAME" value="NAME">
{t`Name`}
</option>
<option key="ACRONYM" value="ACRONYM">
{t`Acronym`}
</option>
<option key="DOMAIN_COUNT" value="DOMAIN_COUNT">
{t`Services`}
</option>
<option key="VERIFIED" value="VERIFIED">
{t`Verified`}
</option>
</Select>
<IconButton
aria-label="Toggle sort direction"
icon={orderIconName}
color="primary"
onClick={() => {
const newOrderDirection =
orderDirection === 'ASC' ? 'DESC' : 'ASC'
setOrderDirection(newOrderDirection)
resetToFirstPage()
}}
/>
</Stack>
</Flex>
{orgList}
<RelayPaginationControls
onlyPagination={false}
selectedDisplayLimit={orgsPerPage}
setSelectedDisplayLimit={setOrgsPerPage}
displayLimitOptions={[5, 10, 20, 50, 100]}
resetToFirstPage={resetToFirstPage}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
next={next}
previous={previous}
isLoadingMore={isLoadingMore}
/>
</ErrorBoundary>
</Box>
)
}