11import React , { useState , FC , CSSProperties , ReactNode } from "react" ;
2- import { NavigateFunction , useNavigate } from "react-router-dom" ;
2+ import { useLocation , NavigateFunction , useNavigate , Location } from "react-router-dom" ;
33import { Button , Tooltip , Typography , TypographyProps } from "@mui/material" ;
44import { styled } from "@mui/material/styles" ;
55import ControlPointIcon from "@mui/icons-material/ControlPoint" ;
@@ -36,26 +36,24 @@ export const TopStickyRow: FC<{
3636 minWidth : string ;
3737 text : string ;
3838 } > = ( { minWidth, text } ) => (
39- < Button
40- onClick = { insideProgramPage ? undefined : ( ) => setExpanded ( ! expanded ) }
41- color = "inherit"
42- sx = { {
43- minWidth,
44- justifyContent : "flex-start" ,
45- paddingLeft : "0px" ,
46- } }
47- >
48- { insideProgramPage || (
49- < ExpandMore
50- fontSize = "small"
51- style = { {
52- transform : expanded ? "rotate(0deg)" : "rotate(-90deg)" ,
53- transition : "transform 0.5s ease" ,
39+ insideProgramPage ? < BoldTypography sx = { { fontSize : "clamp(13px, 1.5vw, 15px)" } } > { text } </ BoldTypography > : < Button
40+ onClick = { ( ) => setExpanded ( ! expanded ) }
41+ color = "inherit"
42+ sx = { {
43+ minWidth,
44+ justifyContent : "flex-start" ,
45+ paddingLeft : "0px" ,
5446 } }
55- />
56- ) }
57- < BoldTypography sx = { { fontSize : "clamp(13px, 1.5vw, 15px)" } } > { text } </ BoldTypography >
58- </ Button >
47+ >
48+ < ExpandMore
49+ fontSize = "small"
50+ style = { {
51+ transform : expanded ? "rotate(0deg)" : "rotate(-90deg)" ,
52+ transition : "transform 0.5s ease" ,
53+ } }
54+ />
55+ < BoldTypography sx = { { fontSize : "clamp(13px, 1.5vw, 15px)" } } > { text } </ BoldTypography >
56+ </ Button >
5957 ) ;
6058
6159 return (
@@ -208,10 +206,11 @@ const NoMarginCell: FC<{
208206/** One row in the table, rendering all the fields of a single RecordData. */
209207const Row : FC < { record : RecordData , hideProgramColumn : boolean } > = ( { record, hideProgramColumn } ) => {
210208 const navigate = useNavigate ( ) ;
209+ const location = useLocation ( ) ;
211210
212211 return (
213212 < div className = "p-dropdown-item" style = { { minWidth : hideProgramColumn ? stickyHeaderWidthWithoutProgram : stickyHeaderWidth } } >
214- < Cell item = { applicantBodyTemplate ( record , navigate ) } width = { columnWidthMap [ 0 ] } />
213+ < Cell item = { applicantBodyTemplate ( record , navigate , location ) } width = { columnWidthMap [ 0 ] } />
215214 { hideProgramColumn || < Cell item = { programBodyTemplate ( record , navigate ) } width = { columnWidthMap [ 1 ] } /> }
216215 < Cell item = { statusBodyTemplate ( record ) } width = { columnWidthMap [ 2 ] } />
217216 < Cell item = { finalBodyTemplate ( record ) } width = { columnWidthMap [ 3 ] } />
@@ -302,28 +301,37 @@ const timelineBodyTemplate = (rowData: RecordData, timelineKey: string) => (
302301 </ div >
303302) ;
304303
305- const applicantBodyTemplate = ( rowData : RecordData , navigate : NavigateFunction ) => (
306- < div
307- title = "查看申请人信息"
308- className = "chip-plain"
309- style = { {
310- display : "block" ,
311- borderRadius : "16px" ,
312- padding : "0 10px" ,
313- height : "1.6rem" ,
314- lineHeight : "1.6rem" ,
315- fontSize : "0.8rem" ,
316- maxWidth : "8rem" ,
317- width : "fit-content" ,
318- overflow : "hidden" ,
319- textOverflow : "ellipsis" ,
320- whiteSpace : "nowrap" ,
321- } }
322- onClick = { ( ) => navigate ( `/datapoints/applicant/${ rowData . ApplicantID } ` ) }
323- >
324- { rowData . ApplicantID }
325- </ div >
326- ) ;
304+ const applicantBodyTemplate = ( rowData : RecordData , navigate : NavigateFunction , location : Location ) => {
305+ const handleClick = ( ) => {
306+ if ( location . pathname . startsWith ( "/datapoints" ) ) {
307+ navigate ( `/datapoints/applicant/${ rowData . ApplicantID } ` ) ;
308+ } else if ( location . pathname . startsWith ( "/programs" ) ) {
309+ navigate ( `/programs/${ encodeURIComponent ( rowData . ProgramID ) } /applicant/${ rowData . ApplicantID } ` ) ;
310+ }
311+ } ;
312+ return (
313+ < div
314+ title = "查看申请人信息"
315+ className = "chip-plain"
316+ style = { {
317+ display : "block" ,
318+ borderRadius : "16px" ,
319+ padding : "0 10px" ,
320+ height : "1.6rem" ,
321+ lineHeight : "1.6rem" ,
322+ fontSize : "0.8rem" ,
323+ maxWidth : "8rem" ,
324+ width : "fit-content" ,
325+ overflow : "hidden" ,
326+ textOverflow : "ellipsis" ,
327+ whiteSpace : "nowrap" ,
328+ } }
329+ onClick = { handleClick }
330+ >
331+ { rowData . ApplicantID }
332+ </ div >
333+ )
334+ } ;
327335
328336const programBodyTemplate = ( rowData : RecordData , navigate : NavigateFunction ) => (
329337 < div
@@ -390,6 +398,7 @@ export const PlainTable: FC<{
390398 // key={`header-${r.ProgramID}-${Date.now()}`}
391399 record = { r }
392400 width = { insideProgramPage ? stickyHeaderWidthWithoutProgram : stickyHeaderWidth }
401+ key = { r . ProgramID }
393402 />
394403 ) ;
395404 }
@@ -398,6 +407,7 @@ export const PlainTable: FC<{
398407 // key={r.RecordID+Date.now()}
399408 record = { r }
400409 hideProgramColumn = { insideProgramPage }
410+ key = { r . RecordID }
401411 /> ) ;
402412 } ) ;
403413
0 commit comments