-
Notifications
You must be signed in to change notification settings - Fork 131
Expose project members in project list modal #1258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
469d759
Expose project members in project list modal
ikhoon 739601d
Address review feedback
ikhoon 9ac1296
Address review feedback
ikhoon ad3b736
Merge branch 'codex/project-members-modal' of github.com:ikhoon/centr…
ikhoon ac4b216
format
ikhoon 9c03a0a
minor clean up
ikhoon b71723c
lint
ikhoon 3ad5e7e
address comments
ikhoon c57b712
Merge branch 'main' into codex/project-members-modal
ikhoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
|
|
||
| test.beforeEach('Login', async ({ page }) => { | ||
| await page.goto('/'); | ||
|
|
||
| await expect(page.getByText(/Login/)).toBeVisible(); | ||
| await page.getByPlaceholder('ID').fill('foo'); | ||
| await page.getByPlaceholder('Password').fill('bar'); | ||
| const loginResponsePromise = page.waitForResponse((response) => response.url().includes('/api/v1/login')); | ||
| await page.getByRole('button', { name: 'Login' }).click(); | ||
| await loginResponsePromise; | ||
| }); | ||
|
|
||
| test('view project members from list', async ({ page }) => { | ||
| await page.goto('/app/projects'); | ||
|
|
||
| const projectRows = page.locator('tr', { has: page.getByRole('button', { name: 'View members' }) }); | ||
| await expect(projectRows.first()).toBeVisible(); | ||
| const rowCount = await projectRows.count(); | ||
| let projectName = ''; | ||
| let members: string[] = []; | ||
| let targetRowIndex = 0; | ||
| for (let i = 0; i < rowCount; i += 1) { | ||
| const row = projectRows.nth(i); | ||
| const candidateName = (await row.getByRole('link').first().innerText()).trim(); | ||
| const metadataResponse = await page.request.get(`/api/v1/projects/${encodeURIComponent(candidateName)}`); | ||
| if (!metadataResponse.ok()) { | ||
| continue; | ||
| } | ||
| const metadata = await metadataResponse.json(); | ||
| const candidateMembers = Object.entries(metadata.members).map( | ||
| ([login, member]: [string, { login?: string }]) => member.login || login, | ||
| ); | ||
| if (candidateMembers.length > 0) { | ||
| projectName = candidateName; | ||
| members = candidateMembers; | ||
| targetRowIndex = i; | ||
| break; | ||
| } | ||
| } | ||
| if (!projectName) { | ||
| const fallbackRow = projectRows.first(); | ||
| projectName = (await fallbackRow.getByRole('link').first().innerText()).trim(); | ||
| } | ||
|
|
||
| const projectRow = projectRows.nth(targetRowIndex); | ||
| await projectRow.getByRole('button', { name: 'View members' }).click(); | ||
|
|
||
| const dialog = page.getByRole('dialog'); | ||
| await expect(dialog).toBeVisible(); | ||
| await expect(dialog.getByText('Project members')).toBeVisible(); | ||
| if (members.length > 0) { | ||
| await expect(dialog.getByTestId('project-member-login').first()).toBeVisible({ timeout: 15000 }); | ||
| } | ||
| }); |
118 changes: 118 additions & 0 deletions
118
webapp/src/dogma/features/project/ProjectOwnersModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { | ||
| ListItem, | ||
| Modal, | ||
| ModalBody, | ||
| ModalCloseButton, | ||
| ModalContent, | ||
| ModalHeader, | ||
| ModalOverlay, | ||
| Text, | ||
| UnorderedList, | ||
| } from '@chakra-ui/react'; | ||
| import { useGetMetadataByProjectNameQuery } from 'dogma/features/api/apiSlice'; | ||
| import { FaCrown } from 'react-icons/fa'; | ||
| import { FaUserGroup } from 'react-icons/fa6'; | ||
| import ErrorMessageParser from 'dogma/features/services/ErrorMessageParser'; | ||
|
|
||
| interface ProjectOwnersModalProps { | ||
| projectName: string | null; | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| export const ProjectOwnersModal = ({ projectName, isOpen, onClose }: ProjectOwnersModalProps) => { | ||
| const { data, isLoading, isError, error } = useGetMetadataByProjectNameQuery(projectName ?? '', { | ||
| refetchOnFocus: true, | ||
| skip: !projectName, | ||
| }); | ||
| const allMembers = data | ||
| ? Object.entries(data.members).map(([login, member]) => ({ | ||
| ...member, | ||
| login: member.login || login, | ||
| })) | ||
| : []; | ||
| const owners = allMembers.filter((member) => member.role === 'OWNER'); | ||
| const members = allMembers.filter((member) => member.role !== 'OWNER'); | ||
|
|
||
| return ( | ||
| <Modal isOpen={isOpen} onClose={onClose}> | ||
| <ModalOverlay /> | ||
| <ModalContent> | ||
| <ModalHeader>Project members</ModalHeader> | ||
| <ModalCloseButton /> | ||
| <ModalBody> | ||
| {isLoading ? ( | ||
| <Text color="gray.500">Loading members...</Text> | ||
| ) : isError ? ( | ||
| <Text color="red.500" mb={2}> | ||
| {ErrorMessageParser.parse(error) || 'Failed to load members.'} | ||
| </Text> | ||
| ) : owners.length === 0 ? ( | ||
| <Text color="gray.600">System administrators</Text> | ||
| ) : ( | ||
| <> | ||
| {owners.length > 0 && ( | ||
| <> | ||
| <Text fontWeight="semibold" mb={2}> | ||
| <FaCrown | ||
| style={{ | ||
| marginRight: '8px', | ||
| display: 'inline-block', | ||
| color: '#3182CE', | ||
| marginTop: '1px', | ||
| marginBottom: '-1px', | ||
| }} | ||
| /> | ||
| Owners | ||
| </Text> | ||
| <UnorderedList spacing={2} mb={4} stylePosition="outside" pl={4}> | ||
| {owners.map((member) => ( | ||
| <ListItem | ||
| key={member.login} | ||
| display="list-item" | ||
| sx={{ '::marker': { color: 'blue.500', fontWeight: 'bold' } }} | ||
| > | ||
| <Text data-testid="project-member-login" as="span" fontWeight="semibold"> | ||
| {member.login} | ||
| </Text> | ||
| </ListItem> | ||
| ))} | ||
| </UnorderedList> | ||
| </> | ||
| )} | ||
| {members.length > 0 && ( | ||
| <> | ||
| <Text fontWeight="semibold" mb={2}> | ||
| <FaUserGroup | ||
| style={{ | ||
| marginRight: '8px', | ||
| display: 'inline-block', | ||
| color: '#38A169', | ||
| marginTop: '1px', | ||
| marginBottom: '-1px', | ||
| }} | ||
| /> | ||
| Members | ||
| </Text> | ||
| <UnorderedList spacing={2} stylePosition="outside" pl={4}> | ||
| {members.map((member) => ( | ||
| <ListItem | ||
| key={member.login} | ||
| display="list-item" | ||
| sx={{ '::marker': { color: 'green.500', fontWeight: 'bold' } }} | ||
| > | ||
| <Text data-testid="project-member-login" as="span" fontWeight="semibold"> | ||
| {member.login} | ||
| </Text> | ||
| </ListItem> | ||
| ))} | ||
| </UnorderedList> | ||
| </> | ||
| )} | ||
| </> | ||
| )} | ||
| </ModalBody> | ||
| </ModalContent> | ||
| </Modal> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question) This API seems to require
@RequiresProjectRole(ProjectRole.MEMBER)- will GUEST/users who are not members of a project be able to view members?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that point. 😅
In production, GUEST is not an anonymous user but may be authenticated by a third party IdP such as Okta. Therefore, it makes sense to allow GUEST to access the project metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add another api that only provides the member information later. I think it's okay for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. We can consider adding additional APIs when we have a chance.