Skip to content

Commit 6bb41a8

Browse files
committed
feat: add role-aware links to User, Instrument, Calls, FAP in ProposalsT
1 parent 6254d9b commit 6bb41a8

3 files changed

Lines changed: 67 additions & 7 deletions

File tree

apps/frontend/src/components/experiment/ExperimentsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export default function ExperimentsTable({
180180
<RoleBasedLink
181181
roleRoutes={{
182182
[UserRole.USER_OFFICER]: `/Proposals?reviewModal=${rowData.proposal.primaryKey}&from=${from}`,
183-
// [UserRole.INSTRUMENT_SCIENTIST]: `/Proposals?reviewModal=${rowData.proposal.primaryKey}&from=${from}`,
183+
[UserRole.INSTRUMENT_SCIENTIST]: `/Proposals?reviewModal=${rowData.proposal.primaryKey}&from=${from}`,
184184
}}
185185
>
186186
{rowData.proposal.proposalId}

apps/frontend/src/components/proposal/ProposalTableOfficer.tsx

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import CopyToClipboard from 'components/common/CopyToClipboard';
3737
import MaterialTable from 'components/common/DenseMaterialTable';
3838
import ListStatusIcon from 'components/common/icons/ListStatusIcon';
3939
import ScienceIcon from 'components/common/icons/ScienceIcon';
40+
import RoleBasedLink from 'components/common/RoleBasedLink';
4041
import UOLoader from 'components/common/UOLoader';
4142
import AssignProposalsToFaps from 'components/fap/Proposals/ProposalsView/AssignProposalsToFaps';
4243
import AssignProposalsToInstruments from 'components/instrument/AssignProposalsToInstruments';
@@ -68,6 +69,7 @@ import { useDownloadPDFProposal } from 'hooks/proposal/useDownloadPDFProposal';
6869
import { useDownloadProposalAttachment } from 'hooks/proposal/useDownloadProposalAttachment';
6970
import { useDownloadXLSXProposal } from 'hooks/proposal/useDownloadXLSXProposal';
7071
import { ProposalViewData } from 'hooks/proposal/useProposalsCoreData';
72+
import { fromArrayToCommaSeparatedLinks } from 'utils/fromArrayToCommaSeparatedLinks';
7173
import {
7274
addColumns,
7375
fromArrayToCommaSeparated,
@@ -130,9 +132,17 @@ let columns: Column<ProposalViewData>[] = [
130132
sorting: false,
131133
emptyValue: '-',
132134
render: (proposalView) =>
133-
proposalView.principalInvestigator?.lastname
134-
? `${proposalView.principalInvestigator.lastname}, ${getPreferredName(proposalView.principalInvestigator)}`
135-
: '',
135+
proposalView.principalInvestigator?.lastname ? (
136+
<RoleBasedLink
137+
roleRoutes={{
138+
[UserRole.USER_OFFICER]: `/People/${proposalView.principalInvestigator.id}`,
139+
}}
140+
>
141+
{`${proposalView.principalInvestigator.lastname}, ${getPreferredName(proposalView.principalInvestigator)}`}
142+
</RoleBasedLink>
143+
) : (
144+
''
145+
),
136146
},
137147
{
138148
title: 'PI Email',
@@ -157,6 +167,15 @@ let columns: Column<ProposalViewData>[] = [
157167
{
158168
title: 'Call',
159169
field: 'callShortCode',
170+
// No per-call route exists, so officers link to the Calls list page.
171+
render: (rowData) =>
172+
rowData.callShortCode ? (
173+
<RoleBasedLink roleRoutes={{ [UserRole.USER_OFFICER]: '/Calls' }}>
174+
{rowData.callShortCode}
175+
</RoleBasedLink>
176+
) : (
177+
''
178+
),
160179
},
161180
];
162181

@@ -200,10 +219,17 @@ const instrumentManagementColumns = (
200219
{
201220
title: t('instrument'),
202221
field: 'instruments.name',
222+
// No per-instrument route exists, so officers link to the Instruments list page.
223+
203224
render: (rowData: ProposalViewData) =>
204-
fromArrayToCommaSeparated(
205-
rowData.instruments?.map((instrument) => instrument.name)
225+
fromArrayToCommaSeparatedLinks(
226+
rowData.instruments?.map((instrument) => ({
227+
key: instrument.id,
228+
label: instrument.name,
229+
roleRoutes: { [UserRole.USER_OFFICER]: '/Instruments' },
230+
}))
206231
),
232+
207233
customFilterAndSearch: () => true,
208234
},
209235
];
@@ -223,7 +249,13 @@ const fapReviewColumns = (t: TFunction<'translation', undefined>) => [
223249
title: t('FAP'),
224250
field: 'faps.code',
225251
render: (rowData: ProposalViewData) =>
226-
fromArrayToCommaSeparated(rowData.faps?.map((fap) => fap.code)),
252+
fromArrayToCommaSeparatedLinks(
253+
rowData.faps?.map((fap) => ({
254+
key: fap.id,
255+
label: fap.code,
256+
roleRoutes: { [UserRole.USER_OFFICER]: `/FapPage/${fap.id}` },
257+
}))
258+
),
227259
},
228260
];
229261
const SELECT_ALL_ACTION_TOOLTIP = 'select-all-prefetched-proposals';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
3+
import RoleBasedLink, {
4+
RoleBasedLinkProps,
5+
} from 'components/common/RoleBasedLink';
6+
7+
type CommaSeparatedLink = {
8+
key: React.Key;
9+
label: React.ReactNode;
10+
roleRoutes: RoleBasedLinkProps['roleRoutes'];
11+
};
12+
13+
export function fromArrayToCommaSeparatedLinks(
14+
links: CommaSeparatedLink[] | null | undefined
15+
) {
16+
return (
17+
<>
18+
{links?.map((link, index) => (
19+
<React.Fragment key={link.key}>
20+
{index > 0 && ', '}
21+
<RoleBasedLink roleRoutes={link.roleRoutes}>
22+
{link.label}
23+
</RoleBasedLink>
24+
</React.Fragment>
25+
))}
26+
</>
27+
);
28+
}

0 commit comments

Comments
 (0)