transformation-ui / src /components /FileProcessingManager.tsx
Rajavignesh
Updating the UI Code
b366dd7
Raw History Blame Contribute Delete
7.29 kB
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;