-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Connor Barker <connorlbark@gmail.com> Co-authored-by: Matt Bemis <MatthewBemis@users.noreply.github.com>
- Loading branch information
1 parent
3db6627
commit 307420f
Showing
15 changed files
with
282 additions
and
13 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
.../main/java/bio/terra/pearl/api/admin/controller/enrollee/WithdrawnEnrolleeController.java
This file contains 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,42 @@ | ||
package bio.terra.pearl.api.admin.controller.enrollee; | ||
|
||
import bio.terra.pearl.api.admin.api.WithdrawnEnrolleeApi; | ||
import bio.terra.pearl.api.admin.service.auth.AuthUtilService; | ||
import bio.terra.pearl.api.admin.service.auth.context.PortalStudyEnvAuthContext; | ||
import bio.terra.pearl.api.admin.service.enrollee.WithdrawnEnrolleeExtService; | ||
import bio.terra.pearl.core.model.EnvironmentName; | ||
import bio.terra.pearl.core.model.admin.AdminUser; | ||
import bio.terra.pearl.core.model.participant.WithdrawnEnrollee; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.util.List; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class WithdrawnEnrolleeController implements WithdrawnEnrolleeApi { | ||
|
||
private final AuthUtilService authUtilService; | ||
private final HttpServletRequest request; | ||
private final WithdrawnEnrolleeExtService withdrawnEnrolleeExtService; | ||
|
||
public WithdrawnEnrolleeController( | ||
AuthUtilService authUtilService, | ||
WithdrawnEnrolleeExtService enrolleeExtService, | ||
HttpServletRequest request) { | ||
this.authUtilService = authUtilService; | ||
this.withdrawnEnrolleeExtService = enrolleeExtService; | ||
this.request = request; | ||
} | ||
|
||
@Override | ||
public ResponseEntity<Object> getAll( | ||
String portalShortcode, String studyShortcode, String envName) { | ||
AdminUser operator = authUtilService.requireAdminUser(request); | ||
EnvironmentName environmentName = EnvironmentName.valueOfCaseInsensitive(envName); | ||
List<WithdrawnEnrollee> enrollees = | ||
withdrawnEnrolleeExtService.getAll( | ||
PortalStudyEnvAuthContext.of( | ||
operator, portalShortcode, studyShortcode, environmentName)); | ||
return ResponseEntity.ok(enrollees); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...src/main/java/bio/terra/pearl/api/admin/service/enrollee/WithdrawnEnrolleeExtService.java
This file contains 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,23 @@ | ||
package bio.terra.pearl.api.admin.service.enrollee; | ||
|
||
import bio.terra.pearl.api.admin.service.auth.EnforcePortalStudyEnvPermission; | ||
import bio.terra.pearl.api.admin.service.auth.context.PortalStudyEnvAuthContext; | ||
import bio.terra.pearl.core.model.participant.WithdrawnEnrollee; | ||
import bio.terra.pearl.core.service.participant.WithdrawnEnrolleeService; | ||
import java.util.List; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class WithdrawnEnrolleeExtService { | ||
private final WithdrawnEnrolleeService withdrawnEnrolleeService; | ||
|
||
public WithdrawnEnrolleeExtService(WithdrawnEnrolleeService withdrawnEnrolleeService) { | ||
this.withdrawnEnrolleeService = withdrawnEnrolleeService; | ||
} | ||
|
||
@EnforcePortalStudyEnvPermission(permission = "participant_data_view") | ||
public List<WithdrawnEnrollee> getAll(PortalStudyEnvAuthContext authContext) { | ||
return withdrawnEnrolleeService.findByStudyEnvironmentIdNoData( | ||
authContext.getStudyEnvironment().getId()); | ||
} | ||
} |
This file contains 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
19 changes: 19 additions & 0 deletions
19
...est/java/bio/terra/pearl/api/admin/service/enrollee/WithdrawnEnrolleeExtServiceTests.java
This file contains 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,19 @@ | ||
package bio.terra.pearl.api.admin.service.enrollee; | ||
|
||
import bio.terra.pearl.api.admin.AuthAnnotationSpec; | ||
import bio.terra.pearl.api.admin.AuthTestUtils; | ||
import bio.terra.pearl.api.admin.BaseSpringBootTest; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class WithdrawnEnrolleeExtServiceTests extends BaseSpringBootTest { | ||
@Autowired private WithdrawnEnrolleeExtService withdrawnEnrolleeExtService; | ||
|
||
@Test | ||
public void testMethodAnnotations() { | ||
AuthTestUtils.assertAllMethodsAnnotated( | ||
withdrawnEnrolleeExtService, | ||
Map.of("getAll", AuthAnnotationSpec.withPortalStudyEnvPerm("participant_data_view"))); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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
19 changes: 19 additions & 0 deletions
19
ui-admin/src/study/participants/participantList/WithdrawnEnrolleeList.test.tsx
This file contains 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,19 @@ | ||
import React from 'react' | ||
import { mockStudyEnvContext, renderInPortalRouter } from 'test-utils/mocking-utils' | ||
import WithdrawnEnrolleeList from './WithdrawnEnrolleeList' | ||
import Api from 'api/api' | ||
import { waitFor, screen } from '@testing-library/react' | ||
|
||
|
||
test('renders list', async () => { | ||
const studyEnvContext = mockStudyEnvContext() | ||
jest.spyOn(Api, 'fetchWithdrawnEnrollees').mockResolvedValue([ | ||
{ shortcode: 'BLEH', userData: '{"username": "foo@bar.com", "createdAt": 0}', createdAt: 123 } | ||
]) | ||
renderInPortalRouter(studyEnvContext.portal, | ||
<WithdrawnEnrolleeList studyEnvContext={studyEnvContext} />) | ||
await waitFor(() => expect(screen.queryByTestId('loading-spinner')).not.toBeInTheDocument()) | ||
expect(screen.getByText('BLEH')).toBeInTheDocument() | ||
// email should be hidden by default | ||
expect(screen.queryByText('foo@bar.com')).not.toBeInTheDocument() | ||
}) |
94 changes: 94 additions & 0 deletions
94
ui-admin/src/study/participants/participantList/WithdrawnEnrolleeList.tsx
This file contains 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,94 @@ | ||
import React, { useState } from 'react' | ||
import { paramsFromContext, StudyEnvContextT } from '../../StudyEnvironmentRouter' | ||
import { renderPageHeader } from '../../../util/pageUtils' | ||
import { useLoadingEffect } from '../../../api/api-utils' | ||
import Api, { WithdrawnEnrollee } from '../../../api/api' | ||
import { basicTableLayout, ColumnVisibilityControl } from '../../../util/tableUtils' | ||
import LoadingSpinner from '../../../util/LoadingSpinner' | ||
import { | ||
ColumnDef, | ||
getCoreRowModel, | ||
getSortedRowModel, | ||
SortingState, | ||
useReactTable, | ||
VisibilityState | ||
} from '@tanstack/react-table' | ||
import { instantToDefaultString } from '@juniper/ui-core' | ||
import { NavBreadcrumb } from '../../../navbar/AdminNavbar' | ||
import { DocsKey, ZendeskLink } from '../../../util/zendeskUtils' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons' | ||
|
||
type WithdrawnEnrolleeExtract = WithdrawnEnrollee & { | ||
userDataObj: { username: string, createdAt: number } | ||
} | ||
|
||
/** | ||
* show a list of withdrawn enrollees with account information | ||
*/ | ||
export default function WithdrawnEnrolleeList({ studyEnvContext }: { studyEnvContext: StudyEnvContextT}) { | ||
const [enrollees, setEnrollees] = useState<WithdrawnEnrolleeExtract[]>([]) | ||
const [sorting, setSorting] = React.useState<SortingState>([{ 'id': 'createdAt', 'desc': true }]) | ||
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({ | ||
'email': false | ||
}) | ||
const { isLoading } = useLoadingEffect(async () => { | ||
const result = await Api.fetchWithdrawnEnrollees(paramsFromContext(studyEnvContext)) | ||
const extracts: WithdrawnEnrolleeExtract[] = result.map(enrollee => ({ | ||
...enrollee, | ||
userDataObj: JSON.parse(enrollee.userData) | ||
})) | ||
setEnrollees(extracts) | ||
}, [studyEnvContext.currentEnvPath]) | ||
|
||
const columns: ColumnDef<WithdrawnEnrolleeExtract>[] = [{ | ||
header: 'Shortcode', | ||
accessorKey: 'shortcode' | ||
}, { | ||
header: 'Email', | ||
id: 'email', | ||
accessorKey: 'userDataObj.username' | ||
}, { | ||
header: 'Account created', | ||
accessorKey: 'userDataObj.createdAt', | ||
meta: { | ||
columnType: 'instant' | ||
}, | ||
cell: info => instantToDefaultString(info.getValue() as number) | ||
}, { | ||
header: 'Withdrawn', | ||
accessorKey: 'createdAt', | ||
meta: { | ||
columnType: 'instant' | ||
}, | ||
cell: info => instantToDefaultString(info.getValue() as number) | ||
}] | ||
|
||
const table = useReactTable({ | ||
data: enrollees, | ||
columns, | ||
state: { | ||
sorting, | ||
columnVisibility | ||
}, | ||
onColumnVisibilityChange: setColumnVisibility, | ||
enableRowSelection: true, | ||
onSortingChange: setSorting, | ||
getCoreRowModel: getCoreRowModel(), | ||
getSortedRowModel: getSortedRowModel() | ||
}) | ||
return <div className="container-fluid px-4 py-2"> | ||
{ renderPageHeader('Withdrawn enrollees') } | ||
<NavBreadcrumb value={'withdrawnList'}>Withdrawn</NavBreadcrumb> | ||
<FontAwesomeIcon icon={faInfoCircle}/> More information about the | ||
<ZendeskLink doc={DocsKey.WITHDRAWAL}> withdrawal process</ZendeskLink>. | ||
<LoadingSpinner isLoading={isLoading}> | ||
<div className="d-flex justify-content-end"> | ||
<ColumnVisibilityControl table={table}/> | ||
</div> | ||
<div className="d-flex align-items-center justify-content-between"> | ||
{ basicTableLayout(table) } | ||
</div> | ||
</LoadingSpinner> | ||
</div> | ||
} |
Oops, something went wrong.