Skip to content

Commit

Permalink
Merge pull request #837 from AI4Bharat/exportVOTR
Browse files Browse the repository at this point in the history
changes for csv bulk regenerate failed VOTR tasks
  • Loading branch information
aparna-aa authored Oct 22, 2024
2 parents ea882f2 + 4d9a68b commit 00ff0cb
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 18 deletions.
90 changes: 90 additions & 0 deletions src/common/RegenerateFailedVotrTasksDialog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
IconButton,
Tooltip,
Typography,
} from "@mui/material";
import React, { useState } from "react";
import { DropzoneArea } from "react-mui-dropzone";
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";

const RegenerateFailedVotrTasksDialog = ({ openDialog, handleClose, title, handleSubmit }) => {
const [uploadedFile, setUploadedFile] = useState();
const [disableMultiClick, setDisableMultiClick] = useState(false);

return (
<Dialog
open={openDialog}
onClose={handleClose}
fullWidth
maxWidth={"md"}
PaperProps={{ style: { borderRadius: "10px" } }}
scroll="paper"
>
<DialogTitle display="flex" alignItems={"center"}>
<Typography variant="h4">{title}</Typography>
</DialogTitle>

<DialogContent dividers>
<Typography align="center" variant="h6">Upload CSV file containing failed VOTR tasks id's
<Tooltip title="Download Sample CSV">
<IconButton
onClick={(e) => {
e.stopPropagation();
window.location.assign(
`https://chitralekhastoragedev.blob.core.windows.net/multimedia/SampleInputOrgUpload.csv`
);
}}
sx={{ color: "black", scale: "0.9" }}
>
<InfoOutlinedIcon />
</IconButton>
</Tooltip>
</Typography>
<DropzoneArea
acceptedFiles={[".csv"]}
showAlerts={false}
showPreviews={true}
showPreviewsInDropzone={false}
useChipsForPreview
previewGridProps={{ container: { spacing: 1, direction: "row" } }}
filesLimit={1}
previewText="Selected file:"
onChange={(file) => setUploadedFile(file)}
/>
</DialogContent>

<DialogActions>
<Button
variant="text"
onClick={handleClose}
sx={{ lineHeight: "1", borderRadius: "8px" }}
>
Cancel
</Button>

<Button
variant="contained"
onClick={() => {
setDisableMultiClick(true);
setTimeout(() => {
setDisableMultiClick(false);
}, 5000);
handleSubmit(uploadedFile, true);
}}
autoFocus
sx={{ lineHeight: "1", borderRadius: "8px" }}
disabled={disableMultiClick}
>
Upload
</Button>
</DialogActions>
</Dialog>
);
};

export default RegenerateFailedVotrTasksDialog;
26 changes: 24 additions & 2 deletions src/containers/Organization/MyOrganization.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import ProjectList from "./ProjectList";
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
import { AddOrganizationMember, AlertComponent, Loader } from "common";
import UploadFileDialog from "common/UploadFileDialog";
import RegenerateFailedVotrTasksDialog from "common/RegenerateFailedVotrTasksDialog";

const TabPanel = (props) => {
const { children, value, index, ...other } = props;
Expand Down Expand Up @@ -72,6 +73,7 @@ const MyOrganization = () => {
const [openUploadBulkVideoDialog, setOpenUploadBulkVideoDialog] =
useState(false);
const [isUserOrgOwner, setIsUserOrgOwner] = useState(false);
const [openRegenerateFailedVotrTasksDialog, setOpenRegenerateFailedVotrTasksDialog] = useState(false);

const organizationDetails = useSelector(
(state) => state.getOrganizationDetails.data
Expand All @@ -88,6 +90,7 @@ const MyOrganization = () => {
if (success) {
if (apiType === "UPLOAD_CSV") {
setOpenUploadBulkVideoDialog(false);
setOpenRegenerateFailedVotrTasksDialog(false);
}

if (apiType === "GET_USERS_ROLES") {
Expand All @@ -103,6 +106,7 @@ const MyOrganization = () => {
setAlertMessage(data.message);
setAlertColumn("csvAlertColumns");
setOpenUploadBulkVideoDialog(false);
setOpenRegenerateFailedVotrTasksDialog(false);
}
}
}
Expand Down Expand Up @@ -175,13 +179,13 @@ const MyOrganization = () => {
);
};

const handeFileUpload = (file) => {
const handeFileUpload = (file, regenerate = false) => {
const reader = new FileReader();
reader.onload = async () => {
const csvData = reader.result;
const csv = btoa(csvData);

const uploadCSVObj = new UploadCSVAPI("org", id, csv);
const uploadCSVObj = new UploadCSVAPI("org", id, csv, regenerate);
dispatch(APITransport(uploadCSVObj));
};
reader.readAsBinaryString(file[0]);
Expand Down Expand Up @@ -243,6 +247,15 @@ const MyOrganization = () => {
Add New Project
</Button>

<Button
style={{ marginRight: "10px" }}
className={classes.projectButton}
onClick={() => setOpenRegenerateFailedVotrTasksDialog(true)}
variant="contained"
>
Regenerate Failed VOTR Tasks
</Button>

<Button
style={{ marginRight: "10px" }}
className={classes.projectButton}
Expand Down Expand Up @@ -375,6 +388,15 @@ const MyOrganization = () => {
handleSubmit={handeFileUpload}
/>
)}

{openRegenerateFailedVotrTasksDialog && (
<RegenerateFailedVotrTasksDialog
openDialog={openRegenerateFailedVotrTasksDialog}
handleClose={() => setOpenRegenerateFailedVotrTasksDialog(false)}
title={"Regenerate Failed VOTR Tasks"}
handleSubmit={handeFileUpload}
/>
)}
</Grid>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,6 @@ const SettingsButtonComponent = ({
</Tooltip>
)}

<Tooltip title="Complete" placement="bottom">
<IconButton
className={classes.rightPanelBtnGrp}
disabled={getDisbled("complete") || apiInProgress}
onClick={() => setOpenConfirmDialog(true)}
>
<VerifiedIcon className={classes.rightPanelSvg} />
</IconButton>
</Tooltip>

<Divider orientation="vertical" className={classes.rightPanelDivider} />

<Tooltip title="Undo" placement="bottom">
Expand Down Expand Up @@ -524,6 +514,19 @@ const SettingsButtonComponent = ({
/>
)}

<Divider orientation="vertical" className={classes.rightPanelDivider} />

<Tooltip title="Complete" placement="bottom">
<IconButton
className={classes.rightPanelBtnGrp}
disabled={getDisbled("complete") || apiInProgress}
onClick={() => setOpenConfirmDialog(true)}
style={{backgroundColor:"red"}}
>
<VerifiedIcon className={classes.rightPanelSvg}/>
</IconButton>
</Tooltip>

{taskData?.task_type?.includes("TRANSLATION_VOICEOVER") &&
<>
<Divider orientation="vertical" className={classes.rightPanelDivider} />
Expand Down
12 changes: 10 additions & 2 deletions src/hooks/useAutoSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ export const useAutoSave = () => {
}
};

saveIntervalRef.current = setInterval(handleAutosave, 60 * 1000);
if(taskDetails?.task_type?.includes("TRANSLATION_VOICEOVER")){
saveIntervalRef.current = setInterval(handleAutosave, 5 * 60 * 1000);
}else{
saveIntervalRef.current = setInterval(handleAutosave, 60 * 1000);
}

const handleVisibilityChange = () => {
if (!document.hidden) {
saveIntervalRef.current = setInterval(handleAutosave, 60 * 1000);
if(taskDetails?.task_type?.includes("TRANSLATION_VOICEOVER")){
saveIntervalRef.current = setInterval(handleAutosave, 5 * 60 * 1000);
}else{
saveIntervalRef.current = setInterval(handleAutosave, 60 * 1000);
}
} else {
handleAutosave();
clearInterval(saveIntervalRef.current);
Expand Down
12 changes: 8 additions & 4 deletions src/redux/actions/api/Project/UploadCSV.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ENDPOINTS from "../../../../config/apiendpoint";
import C from "../../../constants";

export default class UploadCSVAPI extends API {
constructor(apiType = "project", id, csv, timeout = 2000) {
constructor(apiType = "project", id, csv, regenerate, timeout = 2000) {
super("POST", timeout, false);
this.type = C.UPLOAD_CSV;

Expand All @@ -21,9 +21,13 @@ export default class UploadCSVAPI extends API {
org_id: +this.id,
};

this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.video}${
apiType === "project" ? "upload_csv_data" : "upload_csv_org"
}`;
if(regenerate){
this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.voiceover}csv_bulk_regenerate`;
}else{
this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.video}${
apiType === "project" ? "upload_csv_data" : "upload_csv_org"
}`;
}
}

processResponse(res) {
Expand Down

0 comments on commit 00ff0cb

Please sign in to comment.