Skip to content

Commit 987bd92

Browse files
committed
feat: replace old trio files with new generated files
1 parent e0dde70 commit 987bd92

6 files changed

Lines changed: 121 additions & 40 deletions

File tree

src/components/User/Dashboard/DatasetOrganizer/FileTree.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
Edit,
1010
Description,
1111
Add,
12+
AutoAwesome,
13+
FolderSpecial,
1214
} from "@mui/icons-material";
1315
import {
1416
Box,
@@ -176,6 +178,10 @@ const FileTree: React.FC<FileTreeProps> = ({
176178
};
177179

178180
const renderFileIcon = (file: FileItem) => {
181+
// AI generated files — use AutoAwesome icon with purple color
182+
if (file.source === "ai") {
183+
return <AutoAwesome sx={{ color: Colors.purple, fontSize: 20 }} />;
184+
}
179185
if (file.type === "folder" || file.type === "zip") {
180186
return <Folder sx={{ color: Colors.darkGreen, fontSize: 20 }} />;
181187
}
@@ -464,6 +470,10 @@ const FileTree: React.FC<FileTreeProps> = ({
464470
}}
465471
>
466472
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 1.5 }}>
473+
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
474+
<AutoAwesome sx={{ fontSize: 10, color: Colors.purple }} />
475+
<Typography variant="caption">AI Generated</Typography>
476+
</Box>
467477
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
468478
<Box
469479
sx={{

src/components/User/Dashboard/DatasetOrganizer/LLMPanel.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
487487
contentType: "text",
488488
isUserMeta: true,
489489
parentId: null,
490+
source: "ai",
490491
},
491492
{
492493
id: generateId(),
@@ -500,6 +501,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
500501
contentType: "text",
501502
isUserMeta: true,
502503
parentId: null,
504+
source: "ai",
503505
},
504506
{
505507
id: generateId(),
@@ -513,10 +515,27 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
513515
contentType: "text",
514516
isUserMeta: true,
515517
parentId: null,
518+
source: "ai",
516519
},
517520
];
518521

519-
updateFiles((prev) => [...prev, ...trioFiles]);
522+
// updateFiles((prev) => [...prev, ...trioFiles]);
523+
// replace existing trio files, add if not exist
524+
updateFiles((prev) => {
525+
const trioNames = [
526+
"dataset_description.json",
527+
"README.md",
528+
"participants.tsv",
529+
];
530+
531+
// Remove old AI generated trio files
532+
const withoutOldTrio = prev.filter(
533+
(f) => !(f.source === "ai" && trioNames.includes(f.name))
534+
);
535+
536+
// Add new trio files
537+
return [...withoutOldTrio, ...trioFiles];
538+
});
520539
setTrioGenerated(true);
521540
setStatus(
522541
"✓ BIDS trio files generated and added to Virtual File System!"

src/components/User/Dashboard/DatasetOrganizer/index.tsx

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import {
99
Typography,
1010
Alert,
1111
CircularProgress,
12+
Dialog,
13+
DialogTitle,
14+
DialogContent,
15+
DialogActions,
16+
DialogContentText,
1217
} from "@mui/material";
1318
import { Colors } from "design/theme";
1419
import { useAppDispatch } from "hooks/useAppDispatch";
@@ -23,8 +28,6 @@ import {
2328
} from "redux/projects/projects.selector";
2429
import { FileItem } from "redux/projects/types/projects.interface";
2530

26-
//add
27-
2831
const DatasetOrganizer: React.FC = () => {
2932
const { projectId } = useParams<{ projectId: string }>();
3033
const navigate = useNavigate();
@@ -83,8 +86,8 @@ const DatasetOrganizer: React.FC = () => {
8386
setSelectedIds(new Set(state.selectedIds || []));
8487
setExpandedIds(new Set(state.expandedIds || []));
8588
setBaseDirectoryPath(state.baseDirectoryPath || "");
86-
setEvidenceBundle(state.evidenceBundle || null); // ✅ Add this
87-
setTrioGenerated(state.trioGenerated || false); // ✅ Add this
89+
setEvidenceBundle(state.evidenceBundle || null);
90+
setTrioGenerated(state.trioGenerated || false);
8891
setHasUnsavedChanges(false);
8992
}
9093
}, [currentProject]);
@@ -101,8 +104,8 @@ const DatasetOrganizer: React.FC = () => {
101104
selectedIds: Array.from(selectedIds),
102105
expandedIds: Array.from(expandedIds),
103106
baseDirectoryPath,
104-
evidenceBundle, // ✅ Add this
105-
trioGenerated, // ✅ Add this
107+
evidenceBundle,
108+
trioGenerated,
106109
},
107110
})
108111
).unwrap();
@@ -177,9 +180,7 @@ const DatasetOrganizer: React.FC = () => {
177180
URL.revokeObjectURL(url);
178181
};
179182

180-
// ========================================================================
181183
// BACK BUTTON WITH DIALOG
182-
// ========================================================================
183184
const handleBack = () => {
184185
if (hasUnsavedChanges) {
185186
setShowExitDialog(true);
@@ -333,8 +334,8 @@ const DatasetOrganizer: React.FC = () => {
333334
<DropZone
334335
files={files}
335336
setFiles={updateFiles} // Pass wrapper
336-
baseDirectoryPath={baseDirectoryPath} // ✅ ADD this line
337-
setBaseDirectoryPath={setBaseDirectoryPath} // ✅ ADD this line
337+
baseDirectoryPath={baseDirectoryPath}
338+
setBaseDirectoryPath={setBaseDirectoryPath}
338339
selectedIds={selectedIds}
339340
setSelectedIds={setSelectedIds}
340341
expandedIds={expandedIds}
@@ -359,14 +360,61 @@ const DatasetOrganizer: React.FC = () => {
359360
files={files}
360361
baseDirectoryPath={baseDirectoryPath}
361362
setBaseDirectoryPath={setBaseDirectoryPath}
362-
evidenceBundle={evidenceBundle} // ✅ Pass this
363-
setEvidenceBundle={setEvidenceBundle} // ✅ Pass this
364-
trioGenerated={trioGenerated} // ✅ Pass this
365-
setTrioGenerated={setTrioGenerated} // ✅ Pass this
366-
updateFiles={updateFiles} // ✅ Pass this to add trio files
363+
evidenceBundle={evidenceBundle}
364+
setEvidenceBundle={setEvidenceBundle}
365+
trioGenerated={trioGenerated}
366+
setTrioGenerated={setTrioGenerated}
367+
updateFiles={updateFiles}
367368
onClose={() => setShowLLMPanel(false)}
368369
/>
369370
)}
371+
372+
{/* Exit Confirmation Dialog */}
373+
<Dialog open={showExitDialog} onClose={() => setShowExitDialog(false)}>
374+
<DialogTitle>Unsaved Changes</DialogTitle>
375+
<DialogContent>
376+
<DialogContentText>
377+
You have unsaved changes. Are you sure you want to leave? Your
378+
changes will be lost.
379+
</DialogContentText>
380+
</DialogContent>
381+
<DialogActions>
382+
<Button
383+
variant="outlined"
384+
onClick={() => setShowExitDialog(false)}
385+
sx={{ color: Colors.purple, border: Colors.purple }}
386+
>
387+
Stay
388+
</Button>
389+
<Button
390+
onClick={() => {
391+
setShowExitDialog(false);
392+
navigate("/dashboard");
393+
}}
394+
variant="outlined"
395+
sx={{ color: Colors.purple, border: Colors.purple }}
396+
>
397+
Leave Without Saving
398+
</Button>
399+
<Button
400+
onClick={async () => {
401+
await handleSave();
402+
setShowExitDialog(false);
403+
navigate("/dashboard");
404+
}}
405+
variant="contained"
406+
sx={{
407+
background: `linear-gradient(135deg, ${Colors.rose} 0%, ${Colors.purple} 100%)`,
408+
"&:hover": {
409+
background: `linear-gradient(135deg, ${Colors.purple} 0%, ${Colors.rose} 100%)`,
410+
border: "none",
411+
},
412+
}}
413+
>
414+
Save & Leave
415+
</Button>
416+
</DialogActions>
417+
</Dialog>
370418
</Box>
371419
);
372420
};

src/components/User/Dashboard/DatasetOrganizer/utils/fileProcessors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const processFile = async (
8484
// sourcePath: file.name,
8585
// sourcePath: fullPath, // ← Now includes base path if provided
8686
sourcePath: relativePath, //add
87+
source: "user", // add source
8788
};
8889

8990
// Only extract content for text files
@@ -234,6 +235,7 @@ export const processZip = async (
234235
parentId: parentId,
235236
fileType: fileType as any,
236237
sourcePath: `${zipName}/${path}`, // only relative path
238+
source: "user",
237239
// sourcePath: fileSourcePath,//change
238240
};
239241

src/components/User/Dashboard/DatasetOrganizer/utils/llmHelpers.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import { FileItem } from "redux/projects/types/projects.interface";
1313
export const buildFileSummary = (files: FileItem[]): string => {
1414
let summary = "";
1515

16-
// Check if trio files exist
17-
const datasetDesc = files.find((f) => f.name === "dataset_description.json");
18-
const readme = files.find((f) => f.name === "README.md");
19-
const participants = files.find((f) => f.name === "participants.tsv");
16+
// Trio section — AI generated files only
17+
const datasetDesc = files.find(
18+
(f) => f.source === "ai" && f.name === "dataset_description.json"
19+
);
20+
const readme = files.find((f) => f.source === "ai" && f.name === "README.md");
21+
const participants = files.find(
22+
(f) => f.source === "ai" && f.name === "participants.tsv"
23+
);
2024

2125
const hasTrioFiles = datasetDesc || readme || participants;
2226

@@ -42,29 +46,19 @@ export const buildFileSummary = (files: FileItem[]): string => {
4246
summary += "=".repeat(70) + "\n\n";
4347
}
4448

49+
// Data files section — user dropped files only
4550
summary += "DATA FILES TO CONVERT:\n";
4651
summary += "=".repeat(70) + "\n";
4752

48-
// List data files with detailed categorization
4953
const dataFiles = files.filter(
50-
(f) =>
51-
!f.isUserMeta ||
52-
["dataset_description.json", "README.md", "participants.tsv"].includes(
53-
f.name
54-
)
54+
(f) => f.source === "user" && f.type === "file"
5555
);
5656

5757
dataFiles.forEach((f) => {
58-
if (
59-
!["dataset_description.json", "README.md", "participants.tsv"].includes(
60-
f.name
61-
)
62-
) {
63-
const category = categorizeFile(f);
64-
summary += ` - ${f.name} [${category}]`;
65-
if (f.sourcePath) summary += ` (${f.sourcePath})`;
66-
summary += "\n";
67-
}
58+
const category = categorizeFile(f);
59+
summary += ` - ${f.name} [${category}]`;
60+
if (f.sourcePath) summary += ` (${f.sourcePath})`;
61+
summary += "\n";
6862
});
6963

7064
return summary;
@@ -194,11 +188,14 @@ export const buildEvidenceBundle = (
194188
root: baseDirectoryPath,
195189
counts_by_ext: counts,
196190
all_files: files
197-
.filter((f) => !f.isUserMeta)
191+
// .filter((f) => !f.isUserMeta)
192+
.filter((f) => f.source === "user" && f.type === "file")
198193
.map((f) => f.sourcePath || f.name),
199194
documents: files
200195
// .filter((f) => f.content && ["text", "office"].includes(f.fileType || ""))
196+
201197
.filter((f) => {
198+
if (f.source !== "user") return false; // exclude AI files
202199
if (!f.content || f.content.trim().length === 0) return false;
203200

204201
// ✅ Text files - primary source
@@ -232,10 +229,14 @@ export const buildEvidenceBundle = (
232229
},
233230
trio_found: {
234231
"dataset_description.json": files.some(
235-
(f) => f.name === "dataset_description.json"
232+
(f) => f.source === "ai" && f.name === "dataset_description.json"
233+
),
234+
"README.md": files.some(
235+
(f) => f.source === "ai" && f.name === "README.md"
236+
),
237+
"participants.tsv": files.some(
238+
(f) => f.source === "ai" && f.name === "participants.tsv"
236239
),
237-
"README.md": files.some((f) => f.name === "README.md"),
238-
"participants.tsv": files.some((f) => f.name === "participants.tsv"),
239240
},
240241
};
241242
};

src/redux/projects/types/projects.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface FileItem {
1616
contentType?: string;
1717
sourcePath?: string;
1818
isUserMeta?: boolean;
19+
source?: "user" | "ai";
1920
note?: string;
2021
loading?: boolean;
2122
}

0 commit comments

Comments
 (0)