Skip to content

Commit 3ef26ec

Browse files
authored
Feature/add search box to org users tab (canada-ca#5158)
* init SearchBox in OrganizationAffiliations * prevent reload error on search * add search and orderBy options to query * change AffiliationUserOrder to UserOrder * add orderBy options to org affiliations * add role priority to orderBy permission * update tests * default orderBy permission * update faker schema * fix adminpage test * add translations * conditionally render glossary toggle button
1 parent dbb13de commit 3ef26ec

20 files changed

Lines changed: 533 additions & 317 deletions

api/src/affiliation/loaders/__tests__/load-affiliation-connections-by-org-id.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ describe('given the load affiliations by org id function', () => {
530530
permission: 'user',
531531
})
532532
})
533-
describe('ordering by USER_USERNAME', () => {
533+
describe('ordering by USERNAME', () => {
534534
describe('direction is set to ASC', () => {
535535
it('returns affiliation', async () => {
536536
const expectedAffiliation = await loadAffiliationByKey({
@@ -552,7 +552,7 @@ describe('given the load affiliations by org id function', () => {
552552
after: toGlobalId('affiliation', affOne._key),
553553
before: toGlobalId('affiliation', affThree._key),
554554
orderBy: {
555-
field: 'user-username',
555+
field: 'username',
556556
direction: 'ASC',
557557
},
558558
}
@@ -601,7 +601,7 @@ describe('given the load affiliations by org id function', () => {
601601
after: toGlobalId('affiliation', affThree._key),
602602
before: toGlobalId('affiliation', affOne._key),
603603
orderBy: {
604-
field: 'user-username',
604+
field: 'username',
605605
direction: 'DESC',
606606
},
607607
}

api/src/affiliation/loaders/load-affiliation-connections-by-org-id.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ export const loadAffiliationConnectionsByOrgId =
2020

2121
let affiliationField, documentField
2222
/* istanbul ignore else */
23-
if (orderBy.field === 'user-username') {
23+
if (orderBy.field === 'username') {
2424
affiliationField = aql`DOCUMENT(users, PARSE_IDENTIFIER(affiliation._to).key).userName`
2525
documentField = aql`DOCUMENT(users, PARSE_IDENTIFIER(DOCUMENT(affiliations, ${afterId})._to).key).userName`
26+
} else if (orderBy.field === 'display_name') {
27+
affiliationField = aql`DOCUMENT(users, PARSE_IDENTIFIER(affiliation._to).key).displayName`
28+
documentField = aql`DOCUMENT(users, PARSE_IDENTIFIER(DOCUMENT(affiliations, ${afterId})._to).key).displayName`
29+
} else if (orderBy.field === 'permission') {
30+
affiliationField = aql`rolePriority[affiliation.permission]`
31+
documentField = aql`rolePriority[DOCUMENT(affiliations, ${afterId}).permission]`
2632
}
2733

2834
afterTemplate = aql`
@@ -48,9 +54,15 @@ export const loadAffiliationConnectionsByOrgId =
4854

4955
let affiliationField, documentField
5056
/* istanbul ignore else */
51-
if (orderBy.field === 'user-username') {
57+
if (orderBy.field === 'username') {
5258
affiliationField = aql`DOCUMENT(users, PARSE_IDENTIFIER(affiliation._to).key).userName`
5359
documentField = aql`DOCUMENT(users, PARSE_IDENTIFIER(DOCUMENT(affiliations, ${beforeId})._to).key).userName`
60+
} else if (orderBy.field === 'display_name') {
61+
affiliationField = aql`DOCUMENT(users, PARSE_IDENTIFIER(affiliation._to).key).displayName`
62+
documentField = aql`DOCUMENT(users, PARSE_IDENTIFIER(DOCUMENT(affiliations, ${beforeId})._to).key).displayName`
63+
} else if (orderBy.field === 'permission') {
64+
affiliationField = aql`rolePriority[affiliation.permission]`
65+
documentField = aql`rolePriority[DOCUMENT(affiliations, ${beforeId}).permission]`
5466
}
5567

5668
beforeTemplate = aql`
@@ -124,10 +136,18 @@ export const loadAffiliationConnectionsByOrgId =
124136

125137
let affField, hasNextPageDocument, hasPreviousPageDocument
126138
/* istanbul ignore else */
127-
if (orderBy.field === 'user-username') {
139+
if (orderBy.field === 'username') {
128140
affField = aql`DOCUMENT(users, PARSE_IDENTIFIER(affiliation._to).key).userName`
129141
hasNextPageDocument = aql`DOCUMENT(users, PARSE_IDENTIFIER(LAST(retrievedAffiliations)._to).key).userName`
130142
hasPreviousPageDocument = aql`DOCUMENT(users, PARSE_IDENTIFIER(FIRST(retrievedAffiliations)._to).key).userName`
143+
} else if (orderBy.field === 'display_name') {
144+
affField = aql`DOCUMENT(users, PARSE_IDENTIFIER(affiliation._to).key).displayName`
145+
hasNextPageDocument = aql`DOCUMENT(users, PARSE_IDENTIFIER(LAST(retrievedAffiliations)._to).key).displayName`
146+
hasPreviousPageDocument = aql`DOCUMENT(users, PARSE_IDENTIFIER(FIRST(retrievedAffiliations)._to).key).displayName`
147+
} else if (orderBy.field === 'permission') {
148+
affField = aql`rolePriority[affiliation.permission]`
149+
hasNextPageDocument = aql`rolePriority[LAST(retrievedAffiliations).permission]`
150+
hasPreviousPageDocument = aql`FIRST(retrievedAffiliations).permission`
131151
}
132152

133153
hasNextPageFilter = aql`
@@ -146,8 +166,12 @@ export const loadAffiliationConnectionsByOrgId =
146166
let sortByField = aql``
147167
if (typeof orderBy !== 'undefined') {
148168
/* istanbul ignore else */
149-
if (orderBy.field === 'user-username') {
169+
if (orderBy.field === 'username') {
150170
sortByField = aql`DOCUMENT(users, PARSE_IDENTIFIER(affiliation._to).key).userName ${orderBy.direction},`
171+
} else if (orderBy.field === 'display_name') {
172+
sortByField = aql`DOCUMENT(users, PARSE_IDENTIFIER(affiliation._to).key).displayName ${orderBy.direction},`
173+
} else if (orderBy.field === 'permission') {
174+
sortByField = aql`rolePriority[affiliation.permission] ${orderBy.direction},`
151175
}
152176
}
153177

@@ -196,6 +220,14 @@ export const loadAffiliationConnectionsByOrgId =
196220
RETURN e._key
197221
)
198222
223+
LET rolePriority = {
224+
"pending": 0,
225+
"owner": 1,
226+
"super_admin": 2,
227+
"admin": 3,
228+
"user": 4
229+
}
230+
199231
LET retrievedAffiliations = (
200232
FOR affiliation IN affiliations
201233
FILTER affiliation._key IN affiliationKeys
Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
import {GraphQLEnumType} from 'graphql'
1+
import { GraphQLEnumType } from 'graphql'
22

33
export const AffiliationUserOrderField = new GraphQLEnumType({
44
name: 'AffiliationUserOrderField',
55
description: 'Properties by which affiliation connections can be ordered.',
66
values: {
7-
USER_USERNAME: {
8-
value: 'user-username',
9-
description: 'Order affiliation edges by username.',
7+
USERNAME: {
8+
value: 'username',
9+
description: 'Order affiliations by username.',
1010
},
11-
USER_DISPLAYNAME: {
12-
value: 'user-displayName',
13-
description: 'Order affiliation edges by displayName.',
11+
DISPLAY_NAME: {
12+
value: 'display_name',
13+
description: 'Order affiliations by display name.',
1414
},
15-
USER_EMAIL_VALIDATED: {
16-
value: 'user-emailValidated',
17-
description: 'Order affiliation edges by user verification status.',
18-
},
19-
USER_INSIDER: {
20-
value: 'user-insider',
21-
description: 'Order affiliation edges by user insider status.',
22-
},
23-
USER_AFFILIATIONS_COUNT: {
24-
value: 'user-affiliations-totalCount',
25-
description: 'Order affiliation edges by amount of total affiliations.',
15+
PERMISSION: {
16+
value: 'permission',
17+
description: 'Order affiliations by permission.',
2618
},
2719
},
2820
})

api/src/enums/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './affiliation-org-order-field'
22
export * from './affiliation-user-order-field'
3+
export * from './user-order-field'
34
export * from './dkim-order-field'
45
export * from './dkim-result-order-field'
56
export * from './dmarc-order-field'

api/src/enums/user-order-field.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { GraphQLEnumType } from 'graphql'
2+
3+
export const UserOrderField = new GraphQLEnumType({
4+
name: 'UserOrderField',
5+
description: 'Properties by which affiliation connections can be ordered.',
6+
values: {
7+
USER_USERNAME: {
8+
value: 'user-username',
9+
description: 'Order affiliation edges by username.',
10+
},
11+
USER_DISPLAYNAME: {
12+
value: 'user-displayName',
13+
description: 'Order affiliation edges by displayName.',
14+
},
15+
USER_EMAIL_VALIDATED: {
16+
value: 'user-emailValidated',
17+
description: 'Order affiliation edges by user verification status.',
18+
},
19+
USER_INSIDER: {
20+
value: 'user-insider',
21+
description: 'Order affiliation edges by user insider status.',
22+
},
23+
USER_AFFILIATIONS_COUNT: {
24+
value: 'user-affiliations-totalCount',
25+
description: 'Order affiliation edges by amount of total affiliations.',
26+
},
27+
},
28+
})

api/src/user/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './mutations'
33
export * from './objects'
44
export * from './queries'
55
export * from './unions'
6+
export * from './inputs'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { GraphQLNonNull } from 'graphql'
2+
3+
import { userOrder } from '../user-order'
4+
import { OrderDirection, UserOrderField } from '../../../enums'
5+
6+
describe('given the affiliationOrder input object', () => {
7+
describe('testing fields', () => {
8+
it('has a direction field', () => {
9+
const demoType = userOrder.getFields()
10+
11+
expect(demoType).toHaveProperty('direction')
12+
expect(demoType.direction.type).toMatchObject(new GraphQLNonNull(OrderDirection))
13+
})
14+
it('has a field field', () => {
15+
const demoType = userOrder.getFields()
16+
17+
expect(demoType).toHaveProperty('field')
18+
expect(demoType.field.type).toMatchObject(new GraphQLNonNull(UserOrderField))
19+
})
20+
})
21+
})

api/src/user/inputs/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './user-order'

api/src/user/inputs/user-order.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { GraphQLInputObjectType, GraphQLNonNull } from 'graphql'
2+
3+
import { OrderDirection, UserOrderField } from '../../enums'
4+
5+
export const userOrder = new GraphQLInputObjectType({
6+
name: 'UserOrder',
7+
description: 'Ordering options for affiliation connections.',
8+
fields: () => ({
9+
field: {
10+
type: new GraphQLNonNull(UserOrderField),
11+
description: 'The field to order affiliations by.',
12+
},
13+
direction: {
14+
type: new GraphQLNonNull(OrderDirection),
15+
description: 'The ordering direction.',
16+
},
17+
}),
18+
})

api/src/user/queries/find-my-users.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {GraphQLString} from 'graphql'
2-
import {connectionArgs} from 'graphql-relay'
1+
import { GraphQLString } from 'graphql'
2+
import { connectionArgs } from 'graphql-relay'
33

4-
import {affiliationUserOrder} from '../../affiliation/inputs'
5-
import {userConnection} from '../objects/user-connection'
4+
import { userOrder } from '../../user/inputs'
5+
import { userConnection } from '../objects/user-connection'
66

77
export const findMyUsers = {
88
type: userConnection.connectionType,
99
description: 'Select users an admin has access to.',
1010
args: {
1111
orderBy: {
12-
type: affiliationUserOrder,
12+
type: userOrder,
1313
description: 'Ordering options for user affiliation',
1414
},
1515
search: {
@@ -23,20 +23,15 @@ export const findMyUsers = {
2323
args,
2424
{
2525
userKey,
26-
auth: {
27-
checkSuperAdmin,
28-
userRequired,
29-
verifiedRequired,
30-
superAdminRequired,
31-
},
32-
loaders: {loadUserConnectionsByUserId},
26+
auth: { checkSuperAdmin, userRequired, verifiedRequired, superAdminRequired },
27+
loaders: { loadUserConnectionsByUserId },
3328
},
3429
) => {
3530
const user = await userRequired()
36-
verifiedRequired({user})
31+
verifiedRequired({ user })
3732

3833
const isSuperAdmin = await checkSuperAdmin()
39-
superAdminRequired({user, isSuperAdmin})
34+
superAdminRequired({ user, isSuperAdmin })
4035

4136
const userConnections = await loadUserConnectionsByUserId({
4237
isSuperAdmin,

0 commit comments

Comments
 (0)