Spaces:
Runtime error
Runtime error
File size: 7,290 Bytes
b366dd7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | import React, { useState } from 'react';
import {
Box,
Typography,
TextField,
Select,
MenuItem,
FormControl,
InputLabel,
Button,
Grid,
Paper,
Accordion,
AccordionSummary,
AccordionDetails,
CircularProgress,
IconButton,
} from '@mui/material';
import {
ExpandMore as ExpandMoreIcon,
FolderOpen as FolderOpenIcon,
Refresh as RefreshIcon,
Clear as ClearIcon,
} from '@mui/icons-material';
import ProcessingStatus from './ProcessingStatus';
interface FileProcessingManagerProps {
fileType: 'Shell' | 'MSAG' | 'Dx Supplementary';
}
const FileProcessingManager: React.FC<FileProcessingManagerProps> = ({ fileType }) => {
const [folderPath, setFolderPath] = useState('C://BenefitAgents/Inputfiles');
const [environment, setEnvironment] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [loadStatus, setLoadStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle');
const [configAccordionExpanded, setConfigAccordionExpanded] = useState(true);
const [triggerProcessing, setTriggerProcessing] = useState(false);
const environments = [
{ value: 'CRMTSTLIB', label: 'CRMTSTLIB - Testing' },
{ value: 'RL1FLO', label: 'RL1FLO - O Lib - Release 1' },
{ value: 'RL1FLM', label: 'RL1FLM - M Lib - Release 1' },
{ value: 'RL2FLO', label: 'RL2FLO - O Lib - Release 2' },
{ value: 'RL2FLM', label: 'RL2FLM - M Lib - Release 2' },
{ value: 'RL3FLO', label: 'RL1FLO - O Lib - Release 3' },
{ value: 'RL3FLM', label: 'RL1FLM - M Lib - Release 3' },
{ value: 'RL4FLO', label: 'RL2FLO - O Lib - Release 4' },
{ value: 'RL4FLM', label: 'RL2FLM - M Lib - Release 4' },
];
const handleFolderSelect = () => {
// In a real application, this would open a file dialog
// For now, we'll simulate folder selection
const input = document.createElement('input');
input.type = 'file';
input.webkitdirectory = true;
input.onchange = (e) => {
const files = (e.target as HTMLInputElement).files;
if (files && files.length > 0) {
const path = files[0].webkitRelativePath.split('/')[0];
setFolderPath(path);
}
};
input.click();
};
const handleLoad = async () => {
if (!folderPath || !environment) return;
setConfigAccordionExpanded(false); // Auto-minimize the configuration accordion
setTriggerProcessing(true);
};
const handleClear = () => {
setFolderPath('C://BenefitAgents/Inputfiles');
setEnvironment('');
setIsLoading(false);
setLoadStatus('idle');
setConfigAccordionExpanded(true); // Expand configuration accordion when clearing
setTriggerProcessing(false);
};
const handleLoadingChange = (loading: boolean) => {
setIsLoading(loading);
};
const handleStatusChange = (status: 'idle' | 'loading' | 'success' | 'error') => {
setLoadStatus(status);
};
const handleProcessingComplete = () => {
setTriggerProcessing(false);
};
const isLoadButtonEnabled = folderPath && environment && !isLoading;
return (
<Box
sx={{
height: '100%',
display: 'flex',
flexDirection: 'column',
overflow: 'auto'
}}
>
{/* Configuration Accordion */}
<Accordion
expanded={configAccordionExpanded}
onChange={() => setConfigAccordionExpanded(!configAccordionExpanded)}
sx={{ flexShrink: 0 }}
>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
sx={{
backgroundColor: 'grey.50',
'& .MuiAccordionSummary-content': {
alignItems: 'center',
},
}}
>
<Typography variant="h6" sx={{ fontWeight: 600 }}>
{fileType} Configuration
</Typography>
</AccordionSummary>
<AccordionDetails sx={{ p: 3 }}>
{/* Configuration Form */}
<Paper sx={{ p: 3, mb: 4 }}>
<Typography variant="h6" gutterBottom sx={{ fontWeight: 600, mb: 3 }}>
{fileType} Processing Configuration
</Typography>
<Grid container spacing={3}>
{/* Folder Path Selection */}
<Grid item xs={12}>
<Box sx={{ display: 'flex', gap: 2, alignItems: 'flex-end' }}>
<TextField
fullWidth
label="Input Files Folder Path"
value={folderPath}
onChange={(e) => setFolderPath(e.target.value)}
variant="outlined"
helperText="Default path or select a custom folder"
/>
<IconButton
onClick={handleFolderSelect}
sx={{
p: 1.5,
backgroundColor: 'primary.main',
color: 'white',
'&:hover': {
backgroundColor: 'primary.dark',
},
}}
>
<FolderOpenIcon />
</IconButton>
</Box>
</Grid>
{/* Environment Selection */}
<Grid item xs={12} md={6}>
<FormControl fullWidth>
<InputLabel>Environment</InputLabel>
<Select
value={environment}
label="Environment"
onChange={(e) => setEnvironment(e.target.value)}
>
{environments.map((env) => (
<MenuItem key={env.value} value={env.value}>
{env.label}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
{/* Action Buttons */}
<Grid item xs={12}>
<Box sx={{ display: 'flex', gap: 2, mt: 2 }}>
<Button
variant="contained"
size="large"
onClick={handleLoad}
disabled={!isLoadButtonEnabled}
startIcon={isLoading ? <CircularProgress size={20} /> : <RefreshIcon />}
sx={{ minWidth: 120 }}
>
{isLoading ? 'Loading...' : 'Load'}
</Button>
<Button
variant="outlined"
size="large"
onClick={handleClear}
startIcon={<ClearIcon />}
sx={{ minWidth: 120 }}
>
Clear
</Button>
</Box>
</Grid>
</Grid>
</Paper>
</AccordionDetails>
</Accordion>
{/* Processing Status Component */}
<ProcessingStatus
fileType={fileType}
folderPath={folderPath}
environment={environment}
inputType="file"
isLoading={isLoading}
onLoadingChange={handleLoadingChange}
onStatusChange={handleStatusChange}
triggerProcessing={triggerProcessing}
onProcessingComplete={handleProcessingComplete}
/>
</Box>
);
};
export default FileProcessingManager; |