Skip to content

Commit

Permalink
(0.9.21f2) Hot Fix: Invalid scenes failing and UX improvements (#621)
Browse files Browse the repository at this point in the history
* DPO3DPKRT-844/Display Media Group in Batch Generation Table (#618)
* DPO3DPKRT-840/UX Improvements to Batch Generation (#619)
* DPO3DPKRT-843/invalid Scenes Crash Batch Download (#620)
  • Loading branch information
EMaslowskiQ authored Aug 14, 2024
1 parent 6071b1b commit e717580
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 148 deletions.
5 changes: 3 additions & 2 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export default class API {
const body = JSON.stringify({ statusOnly, rePublish, idSystemObject });
let uri: string = API_ROUTES.GEN_DOWNLOADS;
console.log('[PACKRAT:DEBUG] body: ',body);
console.trace('API.generateDownloads');

let options;
if(statusOnly) {
Expand Down Expand Up @@ -82,8 +81,10 @@ export default class API {
return fetch(`${serverEndpoint}/${route}`, defaultOptions)
.then(response => {
// Check if the response returned a successful status code
if (!response.ok)
if (!response.ok) {
console.log('response: ',response);
return { success: false, message: response.statusText };
}
return response.json(); // Assuming the server responds with JSON
})
.catch(error => {
Expand Down
147 changes: 100 additions & 47 deletions client/src/pages/Admin/components/AdminToolsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const SelectScenesTable = <T extends DBReference>({ onUpdateSelection, data, col
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
};
const resolveProperty = (obj: T, path: string): string | undefined => {
const resolveProperty = (obj: T, path: string): string => {

if(!obj || path.length<=0) {
console.log(`[Packrat:ERROR] invalid inputs for resolveProperty (obj: ${obj ? 'true':'false'} | path: ${path})`);
Expand Down Expand Up @@ -400,26 +400,27 @@ const SelectScenesTable = <T extends DBReference>({ onUpdateSelection, data, col
/>
</TableCell>
{ columns.map((columnHeading) => (
<TableCell
key={columnHeading.key}
align={columnHeading.align ?? 'center'}
padding='none'
component='th'
sortDirection={orderBy === columnHeading.key ? order : false}
>
<TableSortLabel
active={orderBy === columnHeading.key}
direction={orderBy === columnHeading.key ? order : 'asc'}
onClick={createSortHandler(columnHeading.key)}
<Tooltip key={columnHeading.key} title={columnHeading.tooltip ?? columnHeading.key} disableHoverListener={!columnHeading.tooltip}>
<TableCell
align={columnHeading.align ?? 'center'}
padding='none'
component='th'
sortDirection={orderBy === columnHeading.key ? order : false}
>
{columnHeading.label}
{orderBy === columnHeading.key ? (
<span className={classes.visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</span>
) : null}
</TableSortLabel>
</TableCell>
<TableSortLabel
active={orderBy === columnHeading.key}
direction={orderBy === columnHeading.key ? order : 'asc'}
onClick={createSortHandler(columnHeading.key)}
>
{columnHeading.label}
{orderBy === columnHeading.key ? (
<span className={classes.visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</span>
) : null}
</TableSortLabel>
</TableCell>
</Tooltip>
))}
</TableRow>
</TableHead>
Expand Down Expand Up @@ -454,17 +455,25 @@ const SelectScenesTable = <T extends DBReference>({ onUpdateSelection, data, col
{columns.map((column) => (
// we do 'id' above so we can flag the entire row for accessibility
(column.key!=='id') && (
<TableCell key={column.key} align={column.align ?? 'center'}>
{ (column.link && column.link===true) ? (
<>
<a href={resolveProperty(row, `${column.key}_link`)} target='_blank' rel='noopener noreferrer' onClick={handleElementClick}>
{resolveProperty(row,column.key)}
</a>
</>
) : (
resolveProperty(row, column.key)
)}
</TableCell>
<Tooltip
key={column.key}
title={resolveProperty(row,column.key)}
>
<TableCell
align={column.align ?? 'center'}
style={{ whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden', maxWidth: '10rem', }}
>
{ (column.link && column.link===true) ? (
<>
<a href={resolveProperty(row, `${column.key}_link`)} target='_blank' rel='noopener noreferrer' onClick={handleElementClick}>
{resolveProperty(row,column.key)}
</a>
</>
) : (
resolveProperty(row, column.key)
)}
</TableCell>
</Tooltip>
)
))}
</TableRow>
Expand Down Expand Up @@ -590,11 +599,12 @@ const AdminToolsBatchGeneration = (): React.ReactElement => {
}, []);
const getColumnHeader = (): ColumnHeader[] => {
return [
{ key: 'id', label: 'ID', align: 'center' },
{ key: 'name', label: 'Scene Name', align: 'center', link: true },
{ key: 'subject.name', label: 'Subject Name', align: 'center' },
{ key: 'downloads.status', label: 'Downloads', align: 'center' },
{ key: 'publishedState', label: 'Published', align: 'center' },
{ key: 'id', label: 'ID', align: 'center', tooltip: 'idSystemObject for the scene' },
{ key: 'name', label: 'Scene', align: 'center', tooltip: 'Name of the scene', link: true },
{ key: 'mediaGroup.name', label: 'Media Group', align: 'center', tooltip: 'What MediaGroup the scene belongs to. Includes the the subtitle (if any).' },
{ key: 'subject.name', label: 'Subject', align: 'center', tooltip: 'The official subject name for the object' },
{ key: 'downloads.status', label: 'Downloads', align: 'center', tooltip: 'Are downloads in good standing (GOOD), available but contain errors (ERROR), or are not available (MISSING).' },
{ key: 'publishedState', label: 'Published', align: 'center', tooltip: 'Is the scene published and with what accessibility' },
// { key: 'datePublished', label: 'Published (Date)', align: 'center' },
// { key: 'isReviewed', label: 'Reviewed', align: 'center' }
];
Expand Down Expand Up @@ -628,15 +638,43 @@ const AdminToolsBatchGeneration = (): React.ReactElement => {
const response: RequestResponse = await API.generateDownloads(sceneIDs,false,republishScenes);
if(response.success === false) {

// if the job is running then handle differently
if(response.message && response.message.includes('already running')) {
console.log(`[Packrat:WARN] cannot do ${BatchOperations[operation]}. (${response.message})`);
toast.warn(`Not running ${BatchOperations[operation]}. Job already running. Please wait for it to finish.`);
} else {
console.log(`[Packrat:ERROR] cannot run ${BatchOperations[operation]}. (${response.message})`);
toast.error(`Cannot ${BatchOperations[operation]}. Check the report.`);
// make sure we have data and responses
if(!response.data || !Array.isArray(response.data)) {
console.log(`[Packrat:ERROR] cannot run ${BatchOperations[operation]}. invalid response data.`,response);
toast.error(`${BatchOperations[operation]} failed. Got unexpected data from server.`);
return;
}
return;

// get our unique error messages
const uniqueMessages = Array.from(
new Set(
response.data
.filter(response => !response.success && response.message) // Ensure there is a message
.map(response => `${response.id}: ${response.message}`) // Extract the messages
)
);
const toastErrorMsg: string = (uniqueMessages.length>1) ? 'Check the console.' : uniqueMessages[0];

// see if we have nuance to the response (i.e. some failed/some passed)
const allFailed: boolean = response.data.every( response => response.succcess===false );
if(allFailed===true) {
const errorMsg: string = (response.data.length>1)
? `All ${response.data.length} scenes failed during ${BatchOperations[operation]} run.`
: `${BatchOperations[operation]} cannot run. ${uniqueMessages[0]}`;

console.log(`[Packrat:ERROR] ${errorMsg}`,response.data);
toast.error(`${BatchOperations[operation]} failed. (${toastErrorMsg})`);
return;
}

// only some failed so we need to handle this
const failedCount: number = response.data.filter(response => !response.success).length;
console.log(`[Packrat:ERROR] ${response.data.length}/${selectedList.length} scenes failed. (${uniqueMessages.join(' |')})`,response.data);
toast.warn(`${BatchOperations[operation]} had issues. ${failedCount} scenes failed. (${toastErrorMsg})`);

// we bail early so the selection is maintained on failure
// TODO: deselect those that were successful.
return false;
}

// clear selection on succcess
Expand Down Expand Up @@ -688,7 +726,22 @@ const AdminToolsBatchGeneration = (): React.ReactElement => {
</IconButton>
<Collapse in={showBatchOps} className={classes.container}>
<Box className={classes.collapseContainer} style={{ paddingTop: '10px', width: '100%' }}>
<TableContainer component={Paper} elevation={0} style={{ overflow: 'hidden' }}>
<Box style={{ paddingLeft: '1rem' }}>
<Typography variant='body2' gutterBottom>
This tool allows you to batch download and generate scenes with ease.
</Typography>
{/* <Typography variant='body1'>
To get started, select your intended project from the dropdown menu. (<strong>Note:</strong> You can only select one project at a time.)
</Typography>
<Typography variant='body1' gutterBottom>
If needed, you can filter the results by scene name. Once you have made your selections, click the <strong>Submit</strong> button to begin processing. Progress can be monitored in the <strong>Workflow Tab</strong>.
</Typography> */}
<Typography variant='body1' color='error' gutterBottom>
Please remember, the process is limited to <strong>10 items</strong> at a time to prevent overloading the system.
</Typography>
</Box>

<TableContainer component={Paper} elevation={0} style={{ overflow: 'hidden', marginTop: '2rem' }}>
<Table className={tableClasses.table}>
<TableBody>
<TableRow className={tableClasses.tableRow}>
Expand Down Expand Up @@ -737,7 +790,7 @@ const AdminToolsBatchGeneration = (): React.ReactElement => {

<TableRow className={tableClasses.tableRow}>
<TableCell className={clsx(tableClasses.tableCell, classes.fieldLabel)}>
<Tooltip title={'Filters scenes to the selected project. This will reset your selection and what scenes are available in the table below.'}>
<Tooltip title={'Filters scenes to the selected project. This will reset your selection and what scenes are available in the table below. Changing the project will deselect anything currently selected.'}>
<Typography className={tableClasses.labelText}>Filter: Project</Typography>
</Tooltip>
</TableCell>
Expand Down Expand Up @@ -797,7 +850,7 @@ const AdminToolsBatchGeneration = (): React.ReactElement => {
disableElevation
disabled={!isListValid}
>
Go
Submit
</Button>
<Button
className={classes.btn}
Expand Down
Loading

0 comments on commit e717580

Please sign in to comment.