@@ -9,27 +9,32 @@ import { CommunityReport } from "../models/community-report";
99import { Covariate } from "../models/covariate" ;
1010import { readParquetFile } from "../utils/parquet-utils" ;
1111
12- // Paths to default files in the public folder
13- const defaultFiles = [
14- process . env . PUBLIC_URL + "/artifacts/create_final_entities.parquet" ,
15- process . env . PUBLIC_URL + "/artifacts/create_final_relationships.parquet" ,
16- process . env . PUBLIC_URL + "/artifacts/create_final_documents.parquet" ,
17- process . env . PUBLIC_URL + "/artifacts/create_final_text_units.parquet" ,
18- process . env . PUBLIC_URL + "/artifacts/create_final_communities.parquet" ,
19- process . env . PUBLIC_URL + "/artifacts/create_final_community_reports.parquet" ,
20- process . env . PUBLIC_URL + "/artifacts/create_final_covariates.parquet" ,
12+ const baseFileNames = [
13+ "entities.parquet" ,
14+ "relationships.parquet" ,
15+ "documents.parquet" ,
16+ "text_units.parquet" ,
17+ "communities.parquet" ,
18+ "community_reports.parquet" ,
19+ "covariates.parquet" ,
2120] ;
2221
23- const fileSchemas : { [ key : string ] : string } = {
24- "create_final_entities .parquet" : "entity" ,
25- "create_final_relationships .parquet" : "relationship" ,
26- "create_final_text_units .parquet" : "text_unit " ,
27- "create_final_communities .parquet" : "community " ,
28- "create_final_community_reports .parquet" : "community_report " ,
29- "create_final_documents .parquet" : "document " ,
30- "create_final_covariates .parquet" : "covariate" ,
22+ const baseMapping : { [ key : string ] : string } = {
23+ "entities .parquet" : "entity" ,
24+ "relationships .parquet" : "relationship" ,
25+ "documents .parquet" : "document " ,
26+ "text_units .parquet" : "text_unit " ,
27+ "communities .parquet" : "community " ,
28+ "community_reports .parquet" : "community_report " ,
29+ "covariates .parquet" : "covariate" ,
3130} ;
3231
32+ const fileSchemas : { [ key : string ] : string } = { } ;
33+ Object . entries ( baseMapping ) . forEach ( ( [ key , value ] ) => {
34+ fileSchemas [ key ] = value ;
35+ fileSchemas [ `create_final_${ key } ` ] = value ;
36+ } ) ;
37+
3338const useFileHandler = ( ) => {
3439 const navigate = useNavigate ( ) ;
3540 const [ entities , setEntities ] = useState < Entity [ ] > ( [ ] ) ;
@@ -57,8 +62,8 @@ const useFileHandler = () => {
5762
5863 for ( const file of files ) {
5964 const fileName =
60- typeof file === "string" ? file . split ( "/" ) . pop ( ) ! : file . name ;
61- const schema = fileSchemas [ fileName ] ;
65+ typeof file === "string" ? file . split ( "/" ) . pop ( ) ! : file . name ;
66+ const schema = fileSchemas [ fileName ] || fileSchemas [ `create_final_ ${ fileName } ` ] ;
6267
6368 let data ;
6469 if ( typeof file === "string" ) {
@@ -144,12 +149,17 @@ const useFileHandler = () => {
144149 const loadDefaultFiles = async ( ) => {
145150 const filesToLoad = [ ] ;
146151
147- for ( const file of defaultFiles ) {
148- const fileExists = await checkFileExists ( file ) ;
149- if ( fileExists ) {
150- filesToLoad . push ( file ) ; // Add to load queue if the file exists
152+ for ( const baseName of baseFileNames ) {
153+ const prefixedPath = process . env . PUBLIC_URL + `/artifacts/create_final_${ baseName } ` ;
154+ const unprefixedPath = process . env . PUBLIC_URL + `/artifacts/${ baseName } ` ;
155+
156+ if ( await checkFileExists ( prefixedPath ) ) {
157+ filesToLoad . push ( prefixedPath ) ;
158+ } else if ( await checkFileExists ( unprefixedPath ) ) {
159+ filesToLoad . push ( unprefixedPath ) ;
151160 }
152161 }
162+
153163 if ( filesToLoad . length > 0 ) {
154164 await loadFiles ( filesToLoad ) ;
155165 navigate ( "/graph" , { replace : true } ) ;
0 commit comments