Skip to content

Commit 9c2e258

Browse files
committed
feat: highlight and scroll for any row via focus param
1 parent b94dcbb commit 9c2e258

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

src/components/DatasetDetailPage/FileTree/FileTreeRow.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,15 @@ const FileTreeRow: React.FC<Props> = ({
124124

125125
const rowRef = React.useRef<HTMLDivElement | null>(null);
126126
// Highlight only if this row is exactly the subject folder (e.g., "sub-04")
127-
const isSubjectFolder =
128-
node.kind === "folder" && /^sub-[A-Za-z0-9]+$/i.test(node.name);
127+
// const isSubjectFolder =
128+
// node.kind === "folder" && /^sub-[A-Za-z0-9]+$/i.test(node.name);
129129
const isExactHit =
130130
!!highlightText &&
131-
isSubjectFolder &&
132-
node.name.toLowerCase() === highlightText.toLowerCase();
131+
node.name.trim().toLowerCase() === highlightText.trim().toLowerCase();
133132

134133
React.useEffect(() => {
135134
if (isExactHit && rowRef.current) {
136135
rowRef.current.scrollIntoView({ behavior: "smooth", block: "center" });
137-
// subtle flash
138-
// rowRef.current.animate(
139-
// [
140-
// { backgroundColor: `${Colors.yellow}`, offset: 0 }, // turn yellow
141-
// { backgroundColor: `${Colors.yellow}`, offset: 0.85 }, // stay yellow 85% of time
142-
// { backgroundColor: "transparent", offset: 1 }, // then fade out
143-
// ],
144-
// { duration: 8000, easing: "ease", fill: "forwards" }
145-
// );
146136
}
147137
}, [isExactHit]);
148138

@@ -294,7 +284,15 @@ const FileTreeRow: React.FC<Props> = ({
294284
// if the node is a file
295285
return (
296286
<Box
297-
sx={{ display: "flex", alignItems: "flex-start", gap: 1, py: 0.5, px: 1 }}
287+
ref={rowRef}
288+
sx={{
289+
display: "flex",
290+
alignItems: "flex-start",
291+
gap: 1,
292+
py: 0.5,
293+
px: 1,
294+
...rowHighlightSx,
295+
}}
298296
>
299297
<Box sx={{ pl: level * 1.25, pt: "2px" }}>
300298
<InsertDriveFileIcon

src/components/SearchPage/SubjectCard.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ const SubjectCard: React.FC<SubjectCardProps> = ({
3434
}) => {
3535
const { modalities, tasks, sessions, types } = parsedJson.value;
3636
const subjectLink = `${RoutesEnum.DATABASES}/${dbname}/${dsname}`;
37-
const canonicalSubj = /^sub-/i.test(subj)
38-
? subj
39-
: `sub-${String(subj)
40-
.replace(/^sub-/i, "")
41-
.replace(/^0+/, "")
42-
.padStart(2, "0")}`;
37+
const formattedSubj = /^sub-/i.test(subj) ? subj : `sub-${String(subj)}`;
4338

4439
// get the gender of subject
4540
const genderCode = parsedJson?.key?.[1];
@@ -91,7 +86,7 @@ const SubjectCard: React.FC<SubjectCardProps> = ({
9186
}}
9287
component={Link}
9388
// to={subjectLink}
94-
to={`${subjectLink}?focusSubj=${encodeURIComponent(canonicalSubj)}`}
89+
to={`${subjectLink}?focus=${encodeURIComponent(formattedSubj)}`}
9590
// target="_blank"
9691
>
9792
<PersonOutlineIcon />

src/pages/UpdatedDatasetDetailPage.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@ const UpdatedDatasetDetailPage: React.FC = () => {
5757
const { dbName, docId } = useParams<{ dbName: string; docId: string }>();
5858
const navigate = useNavigate();
5959
const [searchParams, setSearchParams] = useSearchParams();
60-
// for subject highlight
61-
const focusSubjRaw = searchParams.get("focusSubj") || undefined;
62-
const focusSubj = !focusSubjRaw
63-
? undefined
64-
: /^sub-/i.test(focusSubjRaw)
65-
? focusSubjRaw
66-
: `sub-${focusSubjRaw.replace(/^0+/, "").padStart(2, "0")}`;
60+
// for highlight
61+
const focus = searchParams.get("focus") || undefined;
6762

6863
// for revision
6964
const rev = searchParams.get("rev") || undefined;
@@ -902,7 +897,7 @@ const UpdatedDatasetDetailPage: React.FC = () => {
902897
onPreview={handlePreview} // pass the function down to FileTree
903898
getInternalByPath={getInternalByPath}
904899
getJsonByPath={getJsonByPath}
905-
highlightText={focusSubj} // for subject highlight
900+
highlightText={focus} // for highlight
906901
/>
907902
</Box>
908903
</Box>

0 commit comments

Comments
 (0)