Skip to content

Commit

Permalink
Implemented bulk endpoint, SWRHook implementation ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
IR96334 committed Dec 13, 2024
1 parent 0873985 commit 4a2e023
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 17 deletions.
3 changes: 3 additions & 0 deletions backend/src/connectors/authentication/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export abstract class BaseAuthenticationConnector {
abstract getEntities(user: UserInterface): Promise<Array<string>>
abstract getUserInformation(userEntity: string): Promise<UserInformation>
abstract getEntityMembers(entity: string): Promise<Array<string>>
async getMultipleUsersInformation(entities: string[]): Promise<UserInformation[]> {
return Promise.all(entities.map(async (entity) => await this.getUserInformation(entity)))
}

async getUserInformationList(entity: string): Promise<UserInformation[]> {
const entities = await this.getEntityMembers(entity)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,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/:dnList/lookup', ...getEntitiesLookup)

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

Expand Down
8 changes: 6 additions & 2 deletions backend/src/routes/v2/entities/getEntitiesLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ export const getEntitiesLookup = [
const {
params: { dnList },
} = parse(req, getEntitiesLookupSchema)

const informationList = await authentication.getUserInformationList(toEntity('user', dnList)) //TODO WORK OUT HOW THIS WORKS? WHAT IS THIS ACTUALLY RETURNING?
//TODO check that contains []
const dnListArray = dnList
.slice(1, -1)
.split(',')
.map((dnListMember) => toEntity('user', dnListMember))
const informationList = await authentication.getMultipleUsersInformation(dnListArray)

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

interface MultipleUserInformationResponse {
userInformationList: UserInformation[]
}

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

return {
mutateUserInformation: mutate,
userInformation: data?.userInformationList || undefined,
isUserInformationLoading: isLoading,
isUserInformationError: error,
}
}

interface GetUserTokensResponse {
tokens: TokenInterface[]
}
Expand Down
43 changes: 29 additions & 14 deletions frontend/src/reviews/ReactionDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Button, Tooltip } from '@mui/material'
import { useGetMultipleUserInformation } from 'actions/user'
import { ReactNode, useMemo } from 'react'
import Loading from 'src/common/Loading'
import { ReactionKindKeys } from 'types/types'
import { plural } from 'utils/stringUtils'

Expand All @@ -11,21 +13,36 @@ type ReactionDisplayProps = {
}

export default function ReactionDisplay({ kind, icon, users, onReactionClick }: ReactionDisplayProps) {
const { userInformation, isUserInformationLoading } = useGetMultipleUserInformation(users)
const title = useMemo(() => {
let text = ''
if (users.length > 3) {
text = `${users[0]}, ${users[1]}, ${users[2]} + ${users.length - 3} more`
} else {
users.forEach((user, index) => {
text += `${user}`
if (index !== users.length - 1) {
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 (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
}, [users])

}, [userInformation, users.length])
if (isUserInformationLoading) {
return <Loading />
}
return (
<Tooltip title={title}>
<Button
Expand All @@ -34,9 +51,7 @@ export default function ReactionDisplay({ kind, icon, users, onReactionClick }:
onClick={() => onReactionClick(kind)}
variant='outlined'
startIcon={icon}
>
<Button>{'test'}</Button>
</Button>
></Button>
</Tooltip>
)
}

0 comments on commit 4a2e023

Please sign in to comment.