Skip to content

Commit

Permalink
removed getEntitiesLookup code and replaced reaction display to use s…
Browse files Browse the repository at this point in the history
…ingle end point
  • Loading branch information
ARADDCC002 committed Dec 17, 2024
1 parent 2494734 commit 80618f5
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 198 deletions.
3 changes: 0 additions & 3 deletions backend/src/connectors/authentication/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ 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: 0 additions & 2 deletions backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { requestId } from './routes/middleware/requestId.js'
import { getDockerRegistryAuth } from './routes/v1/registryAuth.js'
import { getCurrentUser } from './routes/v2/entities/getCurrentUser.js'
import { getEntities } from './routes/v2/entities/getEntities.js'
import { getEntitiesLookup } from './routes/v2/entities/getEntitiesLookup.js'
import { getEntityLookup } from './routes/v2/entities/getEntityLookup.js'
import { getFilescanningInfo } from './routes/v2/filescanning/getFilescanningInfo.js'
import { putFileScan } from './routes/v2/filescanning/putFileScan.js'
Expand Down Expand Up @@ -181,7 +180,6 @@ 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/lookup', ...getEntitiesLookup)

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

Expand Down
50 changes: 0 additions & 50 deletions backend/src/routes/v2/entities/getEntitiesLookup.ts

This file was deleted.

8 changes: 0 additions & 8 deletions backend/src/services/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,3 @@ export const UserInformationSchema = z.object({
name: z.string().optional().openapi({ example: 'Joe Bloggs' }),
organisation: z.string().optional().openapi({ example: 'Acme Corp' }),
})

export const UserInformationSchemaList = z
.object({
email: z.string().optional().openapi({ example: '[email protected]' }),
name: z.string().optional().openapi({ example: 'Joe Bloggs' }),
organisation: z.string().optional().openapi({ example: 'Acme Corp' }),
})
.array()

This file was deleted.

38 changes: 0 additions & 38 deletions backend/test/routes/entities/getEntitiesLookup.spec.ts

This file was deleted.

21 changes: 2 additions & 19 deletions frontend/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,8 @@ export function useGetUserInformation(dn: string) {
}
}

interface MultipleUserInformationResponse {
entities: UserInformation[]
}

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

return {
mutateUserInformation: mutate,
userInformation: data?.entities || [],
isUserInformationLoading: isLoading,
isUserInformationError: error,
}
export function getUserInformation(dn: string) {
return fetch(`/api/v2/entity/${dn}/lookup`, { method: 'get' })
}

interface GetUserTokensResponse {
Expand Down
45 changes: 24 additions & 21 deletions frontend/src/reviews/ReactionDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Button, Tooltip } from '@mui/material'
import { useGetMultipleUserInformation } from 'actions/user'
import { ReactNode, useMemo } from 'react'
import Loading from 'src/common/Loading'
import MessageAlert from 'src/MessageAlert'
import { getUserInformation } from 'actions/user'
import { ReactNode, useEffect, useState } from 'react'
import { ReactionKindKeys } from 'types/types'
import { plural } from 'utils/stringUtils'

Expand All @@ -14,32 +12,37 @@ type ReactionDisplayProps = {
}

export default function ReactionDisplay({ kind, icon, users, onReactionClick }: ReactionDisplayProps) {
const { userInformation, isUserInformationLoading, isUserInformationError } = useGetMultipleUserInformation(users)
const title = useMemo(() => {
return userInformation && userInformation.length > 3
? `${userInformation
.slice(0, 3)
.map((user) => user.name)
.join(', ')}, and ${userInformation.length - 3} others`
: `${userInformation.map((user) => user.name).join(', ')}`
}, [userInformation])
const [usersToDisplay, setUsersToDisplay] = useState('')

if (isUserInformationError) {
return <MessageAlert message={isUserInformationError.info.message} severity='error' />
}
useEffect(() => {
async function fetchData() {
if (!usersToDisplay) {
setUsersToDisplay(
`${users
.slice(0, 3)
.map(async (user) => {
const response = await getUserInformation(user)
if (response.ok) {
const responseBody = await response.json()
return responseBody.entity.name
}
})
.join(', ')} ${users.length > 3 ? ` and ${users.length - 3} others` : ''}`,
)
}
}
fetchData()
}, [users, usersToDisplay])

if (isUserInformationLoading) {
return <Loading />
}
return (
<Tooltip title={title}>
<Tooltip title={usersToDisplay}>
<Button
size='small'
aria-label={plural(users.length, kind)}
onClick={() => onReactionClick(kind)}
startIcon={icon}
>
{userInformation.length}
{users.length}
</Button>
</Tooltip>
)
Expand Down

0 comments on commit 80618f5

Please sign in to comment.