Merge pull request #176 from AmitChauhan63390/delete_runs_notification
feat: show notification on robot delete with existing runs
This commit is contained in:
@@ -289,7 +289,7 @@ router.get("/robots/:id", requireAPIKey, async (req: Request, res: Response) =>
|
|||||||
* type: string
|
* type: string
|
||||||
* example: "Failed to retrieve runs"
|
* example: "Failed to retrieve runs"
|
||||||
*/
|
*/
|
||||||
router.get("/robots/:id/runs", requireAPIKey, async (req: Request, res: Response) => {
|
router.get("/robots/:id/runs",requireAPIKey, async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const runs = await Run.findAll({
|
const runs = await Run.findAll({
|
||||||
where: {
|
where: {
|
||||||
@@ -321,6 +321,7 @@ router.get("/robots/:id/runs", requireAPIKey, async (req: Request, res: Response
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
function formatRunResponse(run: any) {
|
function formatRunResponse(run: any) {
|
||||||
const formattedRun = {
|
const formattedRun = {
|
||||||
id: run.id,
|
id: run.id,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { workflowQueue } from '../worker';
|
|||||||
import { AuthenticatedRequest } from './record';
|
import { AuthenticatedRequest } from './record';
|
||||||
import { computeNextRun } from '../utils/schedule';
|
import { computeNextRun } from '../utils/schedule';
|
||||||
import { capture } from "../utils/analytics";
|
import { capture } from "../utils/analytics";
|
||||||
|
import { tryCatch } from 'bullmq';
|
||||||
|
|
||||||
export const router = Router();
|
export const router = Router();
|
||||||
|
|
||||||
@@ -57,6 +58,59 @@ router.get('/recordings/:id', requireSignIn, async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.get(('/recordings/:id/runs'), requireSignIn, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const runs = await Run.findAll({
|
||||||
|
where: {
|
||||||
|
robotMetaId: req.params.id
|
||||||
|
},
|
||||||
|
raw: true
|
||||||
|
});
|
||||||
|
const formattedRuns = runs.map(formatRunResponse);
|
||||||
|
const response = {
|
||||||
|
statusCode: 200,
|
||||||
|
messageCode: "success",
|
||||||
|
runs: {
|
||||||
|
totalCount: formattedRuns.length,
|
||||||
|
items: formattedRuns,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
res.status(200).json(response);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching runs:", error);
|
||||||
|
res.status(500).json({
|
||||||
|
statusCode: 500,
|
||||||
|
messageCode: "error",
|
||||||
|
message: "Failed to retrieve runs",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function formatRunResponse(run: any) {
|
||||||
|
const formattedRun = {
|
||||||
|
id: run.id,
|
||||||
|
status: run.status,
|
||||||
|
name: run.name,
|
||||||
|
robotId: run.robotMetaId, // Renaming robotMetaId to robotId
|
||||||
|
startedAt: run.startedAt,
|
||||||
|
finishedAt: run.finishedAt,
|
||||||
|
runId: run.runId,
|
||||||
|
runByUserId: run.runByUserId,
|
||||||
|
runByScheduleId: run.runByScheduleId,
|
||||||
|
runByAPI: run.runByAPI,
|
||||||
|
data: {},
|
||||||
|
screenshot: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (run.serializableOutput && run.serializableOutput['item-0']) {
|
||||||
|
formattedRun.data = run.serializableOutput['item-0'];
|
||||||
|
} else if (run.binaryOutput && run.binaryOutput['item-0']) {
|
||||||
|
formattedRun.screenshot = run.binaryOutput['item-0'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRun;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PUT endpoint to update the name and limit of a robot.
|
* PUT endpoint to update the name and limit of a robot.
|
||||||
@@ -217,9 +271,6 @@ router.post('/recordings/:id/duplicate', requireSignIn, async (req: Authenticate
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DELETE endpoint for deleting a recording from the storage.
|
* DELETE endpoint for deleting a recording from the storage.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import { ScheduleSettings } from "../components/molecules/ScheduleSettings";
|
|||||||
import { CreateRunResponse, ScheduleRunResponse } from "../pages/MainPage";
|
import { CreateRunResponse, ScheduleRunResponse } from "../pages/MainPage";
|
||||||
import { apiUrl } from "../apiConfig";
|
import { apiUrl } from "../apiConfig";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const getStoredRecordings = async (): Promise<string[] | null> => {
|
export const getStoredRecordings = async (): Promise<string[] | null> => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${apiUrl}/storage/recordings`);
|
const response = await axios.get(`${apiUrl}/storage/recordings`);
|
||||||
@@ -77,18 +82,49 @@ export const getStoredRecording = async (id: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const checkRunsForRecording = async (id: string): Promise<boolean> => {
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${apiUrl}/storage/recordings/${id}/runs`);
|
||||||
|
|
||||||
|
const runs = response.data;
|
||||||
|
console.log(runs.runs.totalCount)
|
||||||
|
return runs.runs.totalCount > 0;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error checking runs for recording:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => {
|
export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => {
|
||||||
|
|
||||||
|
const hasRuns = await checkRunsForRecording(id);
|
||||||
|
|
||||||
|
if (hasRuns) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const response = await axios.delete(`${apiUrl}/storage/recordings/${id}`);
|
const response = await axios.delete(`${apiUrl}/storage/recordings/${id}`);
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
return response.data;
|
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Couldn't delete stored recording ${id}`);
|
throw new Error(`Couldn't delete stored recording ${id}`);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteRunFromStorage = async (id: string): Promise<boolean> => {
|
export const deleteRunFromStorage = async (id: string): Promise<boolean> => {
|
||||||
@@ -123,7 +159,7 @@ export const createRunForStoredRecording = async (id: string, settings: RunSetti
|
|||||||
try {
|
try {
|
||||||
const response = await axios.put(
|
const response = await axios.put(
|
||||||
`${apiUrl}/storage/runs/${id}`,
|
`${apiUrl}/storage/runs/${id}`,
|
||||||
{ ...settings });
|
{ ...settings });
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
return response.data;
|
return response.data;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ import { IconButton, Button, Box, Typography, TextField, MenuItem, Menu, ListIte
|
|||||||
import { Schedule, DeleteForever, Edit, PlayCircle, Settings, Power, ContentCopy, } from "@mui/icons-material";
|
import { Schedule, DeleteForever, Edit, PlayCircle, Settings, Power, ContentCopy, } from "@mui/icons-material";
|
||||||
import LinkIcon from '@mui/icons-material/Link';
|
import LinkIcon from '@mui/icons-material/Link';
|
||||||
import { useGlobalInfoStore } from "../../context/globalInfo";
|
import { useGlobalInfoStore } from "../../context/globalInfo";
|
||||||
import { deleteRecordingFromStorage, getStoredRecordings } from "../../api/storage";
|
import { checkRunsForRecording, deleteRecordingFromStorage, getStoredRecordings } from "../../api/storage";
|
||||||
import { Add } from "@mui/icons-material";
|
import { Add } from "@mui/icons-material";
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { stopRecording } from "../../api/recording";
|
import { stopRecording } from "../../api/recording";
|
||||||
import { GenericModal } from '../atoms/GenericModal';
|
import { GenericModal } from '../atoms/GenericModal';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { apiUrl } from '../../apiConfig';
|
||||||
import { Menu as MenuIcon } from '@mui/icons-material';
|
import { Menu as MenuIcon } from '@mui/icons-material';
|
||||||
|
|
||||||
/** TODO:
|
/** TODO:
|
||||||
@@ -161,6 +163,8 @@ export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handl
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Box display="flex" justifyContent="space-between" alignItems="center">
|
<Box display="flex" justifyContent="space-between" alignItems="center">
|
||||||
@@ -256,6 +260,13 @@ export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handl
|
|||||||
<OptionsButton
|
<OptionsButton
|
||||||
handleEdit={() => handleEditRobot(row.id, row.name, row.params || [])}
|
handleEdit={() => handleEditRobot(row.id, row.name, row.params || [])}
|
||||||
handleDelete={() => {
|
handleDelete={() => {
|
||||||
|
|
||||||
|
checkRunsForRecording(row.id).then((result: boolean) => {
|
||||||
|
if (result) {
|
||||||
|
notify('warning', 'Cannot delete recording as it has active runs');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
deleteRecordingFromStorage(row.id).then((result: boolean) => {
|
deleteRecordingFromStorage(row.id).then((result: boolean) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
setRows([]);
|
setRows([]);
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ const ApiKeyManager = () => {
|
|||||||
const [copySuccess, setCopySuccess] = useState<boolean>(false);
|
const [copySuccess, setCopySuccess] = useState<boolean>(false);
|
||||||
const { notify } = useGlobalInfoStore();
|
const { notify } = useGlobalInfoStore();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchApiKey = async () => {
|
const fetchApiKey = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -49,6 +53,7 @@ const ApiKeyManager = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchApiKey();
|
fetchApiKey();
|
||||||
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const generateApiKey = async () => {
|
const generateApiKey = async () => {
|
||||||
@@ -56,6 +61,7 @@ const ApiKeyManager = () => {
|
|||||||
try {
|
try {
|
||||||
const { data } = await axios.post(`${apiUrl}/auth/generate-api-key`);
|
const { data } = await axios.post(`${apiUrl}/auth/generate-api-key`);
|
||||||
setApiKey(data.api_key);
|
setApiKey(data.api_key);
|
||||||
|
|
||||||
notify('success', `Generated API Key successfully`);
|
notify('success', `Generated API Key successfully`);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
notify('error', `Failed to generate API Key - ${error.message}`);
|
notify('error', `Failed to generate API Key - ${error.message}`);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { useActionContext } from '../../context/browserActions';
|
|||||||
import { useBrowserSteps, TextStep } from '../../context/browserSteps';
|
import { useBrowserSteps, TextStep } from '../../context/browserSteps';
|
||||||
import { useGlobalInfoStore } from '../../context/globalInfo';
|
import { useGlobalInfoStore } from '../../context/globalInfo';
|
||||||
|
|
||||||
|
|
||||||
interface ElementInfo {
|
interface ElementInfo {
|
||||||
tagName: string;
|
tagName: string;
|
||||||
hasOnlyText?: boolean;
|
hasOnlyText?: boolean;
|
||||||
@@ -316,7 +317,7 @@ export const BrowserWindow = () => {
|
|||||||
}
|
}
|
||||||
}, [paginationMode, resetPaginationSelector]);
|
}, [paginationMode, resetPaginationSelector]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onClick={handleClick} style={{ width: '900px' }} id="browser-window">
|
<div onClick={handleClick} style={{ width: '900px' }} id="browser-window">
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user