11import React from "react" ;
2- import { Card , Form , Input , Button , message , Space , Typography } from "antd" ;
2+ import { Card , Form , Input , Button , Modal , Space , Typography } from "antd" ;
33import { FolderOpenOutlined , UploadOutlined } from "@ant-design/icons" ;
44import UnifiedFileInput from "../../components/UnifiedFileInput" ;
55
@@ -12,22 +12,57 @@ const { Title, Text } = Typography;
1212function DatasetLoader ( { onLoad, loading } ) {
1313 const [ form ] = Form . useForm ( ) ;
1414
15- const handleSubmit = ( values ) => {
16- const datasetPath =
17- typeof values . datasetPath === "object"
18- ? values . datasetPath . path
19- : values . datasetPath ;
20- const maskPath =
21- typeof values . maskPath === "object"
22- ? values . maskPath . path
23- : values . maskPath ;
15+ const resolvePath = ( value ) => {
16+ if ( ! value ) return "" ;
17+ if ( typeof value === "string" ) return value . trim ( ) ;
18+ return ( value . path || value . folderPath || "" ) . trim ( ) ;
19+ } ;
20+
21+ const showValidationError = ( title , description ) => {
22+ Modal . error ( {
23+ title,
24+ content : description ,
25+ okText : "Got it" ,
26+ } ) ;
27+ } ;
28+
29+ const handleSubmit = async ( values ) => {
30+ const datasetPath = resolvePath ( values . datasetPath ) ;
31+ const maskPath = resolvePath ( values . maskPath ) ;
32+ const projectName = ( values . projectName || "" ) . trim ( ) ;
33+
34+ if ( ! projectName ) {
35+ showValidationError (
36+ "Project name required" ,
37+ "Please provide a name for this proofreading session." ,
38+ ) ;
39+ return ;
40+ }
2441
2542 if ( ! datasetPath ) {
26- message . error ( "Please provide a dataset path" ) ;
43+ showValidationError (
44+ "Dataset path required" ,
45+ "Select a dataset file/folder before starting the session." ,
46+ ) ;
2747 return ;
2848 }
2949
30- onLoad ( datasetPath , maskPath , values . projectName || "Untitled Project" ) ;
50+ if ( datasetPath . includes ( ".." ) || maskPath . includes ( ".." ) ) {
51+ showValidationError (
52+ "Invalid path" ,
53+ "Paths containing '..' are not allowed. Please pick a direct file/folder path." ,
54+ ) ;
55+ return ;
56+ }
57+
58+ try {
59+ await onLoad ( datasetPath , maskPath , projectName || "Untitled Project" ) ;
60+ } catch ( error ) {
61+ showValidationError (
62+ "Failed to load dataset" ,
63+ "Unable to start proofreading with the provided paths. Check the selected files and try again." ,
64+ ) ;
65+ }
3166 } ;
3267
3368 return (
@@ -75,16 +110,11 @@ function DatasetLoader({ onLoad, loading }) {
75110 label = "Dataset Path"
76111 name = "datasetPath"
77112 rules = { [ { required : true , message : "Please enter dataset path" } ] }
78- help = "File, directory, or glob (e.g., /path/to/images/*.tif)"
79113 >
80114 < UnifiedFileInput placeholder = "/path/to/dataset" />
81115 </ Form . Item >
82116
83- < Form . Item
84- label = "Mask Path (Optional)"
85- name = "maskPath"
86- help = "Mask file or directory (optional)"
87- >
117+ < Form . Item label = "Mask Path (Optional)" name = "maskPath" >
88118 < UnifiedFileInput placeholder = "/path/to/masks" />
89119 </ Form . Item >
90120
@@ -101,13 +131,6 @@ function DatasetLoader({ onLoad, loading }) {
101131 </ Button >
102132 </ Form . Item >
103133 </ Form >
104-
105- < div style = { { marginTop : 16 } } >
106- < Text type = "secondary" style = { { fontSize : 12 } } >
107- Supported: single TIFF (2D/3D), image folders (PNG/JPG/TIFF), or glob
108- patterns like `*.tif`.
109- </ Text >
110- </ div >
111134 </ Card >
112135 ) ;
113136}
0 commit comments