Skip to content

Commit d1313d6

Browse files
authored
Merge pull request #101 from NeuroJSON/dev-fan
feat: add copyable preview URLs in dataset detail page
2 parents bd5c7cd + bfccf4a commit d1313d6

File tree

5 files changed

+238
-179
lines changed

5 files changed

+238
-179
lines changed

src/components/DatasetDetailPage/FileTree/FileTree.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ import React from "react";
88
type Props = {
99
title: string;
1010
tree: TreeNode[];
11-
filesCount: number;
12-
totalBytes: number;
11+
// filesCount: number;
12+
// totalBytes: number;
1313
// for preview in tree row
1414
onPreview: (src: string | any, index: number, isInternal?: boolean) => void;
1515
getInternalByPath: (path: string) => { data: any; index: number } | undefined;
1616
getJsonByPath?: (path: string) => any;
1717
highlightText?: string;
1818
};
1919

20-
const formatSize = (n: number) => {
21-
if (n < 1024) return `${n} B`;
22-
if (n < 1024 ** 2) return `${(n / 1024).toFixed(1)} KB`;
23-
if (n < 1024 ** 3) return `${(n / 1024 ** 2).toFixed(2)} MB`;
24-
if (n < 1024 ** 4) return `${(n / 1024 ** 3).toFixed(2)} GB`;
25-
return `${(n / 1024 ** 4).toFixed(2)} TB`;
26-
};
20+
// const formatSize = (n: number) => {
21+
// if (n < 1024) return `${n} B`;
22+
// if (n < 1024 ** 2) return `${(n / 1024).toFixed(1)} KB`;
23+
// if (n < 1024 ** 3) return `${(n / 1024 ** 2).toFixed(2)} MB`;
24+
// if (n < 1024 ** 4) return `${(n / 1024 ** 3).toFixed(2)} GB`;
25+
// return `${(n / 1024 ** 4).toFixed(2)} TB`;
26+
// };
2727

2828
const FileTree: React.FC<Props> = ({
2929
title,
3030
tree,
31-
filesCount,
32-
totalBytes,
31+
// filesCount,
32+
// totalBytes,
3333
onPreview,
3434
getInternalByPath,
3535
getJsonByPath,

src/components/DatasetDetailPage/FileTree/FileTreeRow.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,14 @@ const FileTreeRow: React.FC<Props> = ({
123123
const externalUrl = node.link?.url;
124124

125125
const rowRef = React.useRef<HTMLDivElement | null>(null);
126-
// 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);
126+
// Highlight only if this row is exactly the same as the focus highlightText
129127
const isExactHit =
130-
!!highlightText &&
131-
isSubjectFolder &&
132-
node.name.toLowerCase() === highlightText.toLowerCase();
128+
node.name.trim().toLowerCase() ===
129+
(highlightText ?? "").trim().toLowerCase();
133130

134131
React.useEffect(() => {
135132
if (isExactHit && rowRef.current) {
136133
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-
// );
146134
}
147135
}, [isExactHit]);
148136

@@ -294,7 +282,15 @@ const FileTreeRow: React.FC<Props> = ({
294282
// if the node is a file
295283
return (
296284
<Box
297-
sx={{ display: "flex", alignItems: "flex-start", gap: 1, py: 0.5, px: 1 }}
285+
ref={rowRef}
286+
sx={{
287+
display: "flex",
288+
alignItems: "flex-start",
289+
gap: 1,
290+
py: 0.5,
291+
px: 1,
292+
...rowHighlightSx,
293+
}}
298294
>
299295
<Box sx={{ pl: level * 1.25, pt: "2px" }}>
300296
<InsertDriveFileIcon

src/components/DatasetDetailPage/FileTree/utils.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ export const buildTreeFromDoc = (
8787
if (Array.isArray(doc)) {
8888
doc.forEach((item, i) => {
8989
const path = `${curPath}/[${i}]`;
90+
if (linkMap.has(path)) {
91+
// console.log("PATH", path);
92+
// console.log("has exact", linkMap.has(path));
93+
// console.log("has _DataLink_", linkMap.has(`${path}/_DataLink_`));
94+
} else {
95+
// console.log("nothing matching in array docs");
96+
}
97+
9098
const linkHere = linkMap.get(path) || linkMap.get(`${path}/_DataLink_`);
91-
// For primitive items, show "1: value" in the *name*
9299
const isPrimitive =
93100
item === null || ["string", "number", "boolean"].includes(typeof item);
94101
const label = isPrimitive ? `${i}: ${formatLeafValue(item)}` : String(i); // objects/arrays just show "1", "2", ...
@@ -97,7 +104,7 @@ export const buildTreeFromDoc = (
97104
out.push({
98105
kind: "folder",
99106
// name: `[${i}]`,
100-
name: label,
107+
name: label, // For primitive items, show "1: value" in the name
101108
path,
102109
link: linkHere,
103110
children: buildTreeFromDoc(item, linkMap, path),
@@ -113,12 +120,21 @@ export const buildTreeFromDoc = (
113120
});
114121
}
115122
});
123+
// console.log("out", out);
116124
return out;
117125
}
118126

119127
Object.keys(doc).forEach((key) => {
120128
const val = doc[key];
121129
const path = `${curPath}/${key}`;
130+
if (linkMap.has(path)) {
131+
// console.log("PATH", path);
132+
// console.log("has exact", linkMap.has(path));
133+
// console.log("has _DataLink_", linkMap.has(`${path}/_DataLink_`));
134+
} else {
135+
// console.log("nothing match in object keys");
136+
}
137+
122138
const linkHere = linkMap.get(path) || linkMap.get(`${path}/_DataLink_`);
123139

124140
if (val && typeof val === "object") {

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 />

0 commit comments

Comments
 (0)