Skip to content

Commit 98aeaf7

Browse files
Hari KiranHari Kiran
authored andcommitted
Fix sub naming format under External data
1 parent 5bfd7af commit 98aeaf7

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/pages/DatasetDetailPage.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,31 @@ const DatasetDetailPage: React.FC = () => {
150150
const extractDataLinks = (obj: any, path: string): ExternalDataLink[] => {
151151
const links: ExternalDataLink[] = [];
152152

153-
const traverse = (node: any, currentPath: string) => {
153+
const traverse = (node: any, currentPath: string, parentKey: string = "") => {
154154
if (typeof node === "object" && node !== null) {
155155
for (const key in node) {
156156
if (key === "_DataLink_" && typeof node[key] === "string") {
157157
let correctedUrl = node[key].replace(/:\$.*$/, "");
158158
const sizeMatch = node[key].match(/size=(\d+)/);
159159
const size = sizeMatch
160160
? `${(parseInt(sizeMatch[1], 10) / 1024 / 1024).toFixed(2)} MB`
161-
: "Unknown Size";
162-
163-
const subMatch = currentPath.match(/sub-\d+/);
164-
const subPath = subMatch ? subMatch[0] : "Unknown Sub";
161+
: "Unknown Size";
165162

166163
const parts = currentPath.split("/");
167-
const label = parts[parts.length - 2] || "ExternalData";
168-
const folderRaw = parts.slice(0, -1).join("/") || "root";
169-
const folder = folderRaw.replace(/^\/+/, "");
164+
const subpath = parts.slice(-3).join("/");
165+
const label = parentKey || "ExternalData";
166+
170167
links.push({
171-
name: `${label} (${size}) [/${folder}]`,
168+
name: `${label} (${size}) [/${subpath}]`,
172169
size,
173170
path: currentPath, // keep full JSON path for file placement
174171
url: correctedUrl,
175172
index: links.length,
176173
});
177174
} else if (typeof node[key] === "object") {
178-
traverse(node[key], `${currentPath}/${key}`);
175+
const isMetaKey = key.startsWith("_");
176+
const newLabel = !isMetaKey ? key : parentKey;
177+
traverse(node[key], `${currentPath}/${key}`, newLabel);
179178
}
180179
}
181180
}
@@ -402,6 +401,15 @@ const DatasetDetailPage: React.FC = () => {
402401
);
403402
};
404403

404+
const extractFileName = (url: string): string => {
405+
const match = url.match(/file=([^&]+)/);
406+
return match ? decodeURIComponent(match[1]) : url;
407+
};
408+
409+
const isPreviewableFile = (fileName: string): boolean => {
410+
return /\.(nii\.gz|jdt|jdb|bmsh|jmsh|bnii)$/i.test(fileName);
411+
};
412+
405413
if (isInternal) {
406414
try {
407415
if (!(window as any).intdata) {
@@ -432,7 +440,9 @@ const DatasetDetailPage: React.FC = () => {
432440
}
433441
} else {
434442
// external
435-
if (/\.(nii\.gz|jdt|jdb|bmsh|jmsh|bnii)$/i.test(dataOrUrl)) {
443+
// if (/\.(nii\.gz|jdt|jdb|bmsh|jmsh|bnii)$/i.test(dataOrUrl)) {
444+
const fileName = typeof dataOrUrl === "string" ? extractFileName(dataOrUrl) : "";
445+
if (isPreviewableFile(fileName)) {
436446
(window as any).previewdataurl(dataOrUrl, idx);
437447
const panel = document.getElementById("chartpanel");
438448
if (panel) panel.style.display = "none"; // 🔒 Hide chart panel on 3D external

0 commit comments

Comments
 (0)