Skip to content

Commit

Permalink
finished implementation of multi user entity look up and reaction dis…
Browse files Browse the repository at this point in the history
…play
  • Loading branch information
ARADDCC002 committed Dec 16, 2024
1 parent 89c02a6 commit dbcabde
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 39 deletions.
2 changes: 1 addition & 1 deletion backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ server.get('/api/v2/model/:modelId/permissions/mine', ...getModelCurrentUserPerm
server.get('/api/v2/entities', ...getEntities)
server.get('/api/v2/entities/me', ...getCurrentUser)
server.get('/api/v2/entity/:dn/lookup', ...getEntityLookup)
server.get('/api/v2/entities/:dnList/lookup', ...getEntitiesLookup)
server.get('/api/v2/entities/lookup', ...getEntitiesLookup)

server.get('/api/v2/config/ui', ...getUiConfig)

Expand Down
16 changes: 6 additions & 10 deletions backend/src/routes/v2/entities/getEntitiesLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { UserInformation } from '../../../connectors/authentication/Base.js'
import authentication from '../../../connectors/authentication/index.js'
import { registerPath, UserInformationSchemaList } from '../../../services/specification.js'
import { toEntity } from '../../../utils/entity.js'
import { parse } from '../../../utils/validate.js'
import { coerceArray, parse } from '../../../utils/validate.js'

export const getEntitiesLookupSchema = z.object({
params: z.object({
dnList: z.string(),
query: z.object({
dnList: coerceArray(z.array(z.string())),
}),
})

registerPath({
method: 'get',
path: '/api/v2/entities/{dnList}/lookup',
path: '/api/v2/entities/lookup',
tags: ['user'],
description: 'Get information about a list of entities',
schema: getEntitiesLookupSchema,
Expand All @@ -40,13 +40,9 @@ export const getEntitiesLookup = [
bodyParser.json(),
async (req: Request, res: Response<GetEntitiesLookup>) => {
const {
params: { dnList },
query: { dnList },
} = parse(req, getEntitiesLookupSchema)
//TODO check that contains []
const dnListArray = dnList
.slice(1, -1)
.split(',')
.map((dnListMember) => toEntity('user', dnListMember))
const dnListArray = dnList.map((dnListMember) => toEntity('user', dnListMember))
const informationList = await authentication.getMultipleUsersInformation(dnListArray)

return res.json({ entities: informationList })
Expand Down
10 changes: 6 additions & 4 deletions frontend/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,21 @@ export function useGetUserInformation(dn: string) {
}

interface MultipleUserInformationResponse {
userInformationList: UserInformation[]
entities: UserInformation[]
}

export function useGetMultipleUserInformation(dnList: string[]) {
const dnListAsString = '[' + dnList.join(',') + ']'
const queryParams = {
...(dnList.length > 0 && { dnList }),
}
const { data, isLoading, error, mutate } = useSWR<MultipleUserInformationResponse, ErrorInfo>(
`/api/v2/entities/${dnListAsString}/lookup`,
`/api/v2/entities/lookup?${qs.stringify(queryParams)}`,
fetcher,
)

return {
mutateUserInformation: mutate,
userInformation: data?.userInformationList || undefined,
userInformation: data?.entities || [],
isUserInformationLoading: isLoading,
isUserInformationError: error,
}
Expand Down
35 changes: 11 additions & 24 deletions frontend/src/reviews/ReactionDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,16 @@ export default function ReactionDisplay({ kind, icon, users, onReactionClick }:
const { userInformation, isUserInformationLoading } = useGetMultipleUserInformation(users)
const title = useMemo(() => {
let text = ''
if (userInformation) {
if (userInformation.length > 3) {
text = `${userInformation[0]}, ${userInformation[1]}, ${userInformation[2]} + ${userInformation.length - 3} more`
} else {
userInformation.forEach((user, index) => {
text += `${user}`
if (index !== users.length - 1) {
text += ', '
}
})
}
if (userInformation && userInformation.length > 3) {
text = `${userInformation
.slice(0, 3)
.map((user) => user.name)
.join(', ')}, and ${userInformation.length - 3} others`
} else {
text = `${userInformation.map((user) => user.name).join(', ')}`
}
// // if (userList.length > 3) {
// // text = `${userList[0]}, ${userList[1]}, ${userList[2]} + ${userList.length - 3} more`
// // } else {
// // userList.forEach((user, index) => {
// // text += `${user}`
// // if (index !== users.length - 1) {
// // text += ', '
// // }
// // })
// // }
return text
}, [userInformation, users.length])
}, [userInformation])
if (isUserInformationLoading) {
return <Loading />
}
Expand All @@ -49,9 +35,10 @@ export default function ReactionDisplay({ kind, icon, users, onReactionClick }:
size='small'
aria-label={plural(users.length, kind)}
onClick={() => onReactionClick(kind)}
variant='outlined'
startIcon={icon}
></Button>
>
{userInformation.length}
</Button>
</Tooltip>
)
}

0 comments on commit dbcabde

Please sign in to comment.