Recording deletion warning while runs are active
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,
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ 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`);
|
||||||
@@ -47,16 +51,52 @@ export const getStoredRecording = async (id: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const checkRunsForRecording = async (id: string): Promise<boolean> => {
|
||||||
|
const apiKey = localStorage.getItem('x-api-key');
|
||||||
|
|
||||||
|
// Check if the API key exists
|
||||||
|
if (!apiKey) {
|
||||||
|
console.error('API key is missing.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${apiUrl}/api/robots/${id}/runs`, {
|
||||||
|
headers: {
|
||||||
|
'x-api-key': apiKey, // Pass the valid API key in the header
|
||||||
|
},
|
||||||
|
withCredentials: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const runs = response.data;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { IconButton, Button, Box, Typography, TextField } from "@mui/material";
|
|||||||
import { Schedule, DeleteForever, Edit, PlayCircle, Settings, Power } from "@mui/icons-material";
|
import { Schedule, DeleteForever, Edit, PlayCircle, Settings, Power } 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";
|
||||||
@@ -159,6 +159,13 @@ export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handl
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const hasAssociatedRuns = async (robotId: string): Promise<boolean> => {
|
||||||
|
|
||||||
|
const associatedRuns = await fetch(`/api/robot/${robotId}/runs`);
|
||||||
|
const data = await associatedRuns.json();
|
||||||
|
return data.length > 0;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Box display="flex" justifyContent="space-between" alignItems="center">
|
<Box display="flex" justifyContent="space-between" alignItems="center">
|
||||||
@@ -252,6 +259,13 @@ export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handl
|
|||||||
return (
|
return (
|
||||||
<TableCell key={column.id} align={column.align}>
|
<TableCell key={column.id} align={column.align}>
|
||||||
<IconButton aria-label="add" size="small" onClick={() => {
|
<IconButton aria-label="add" size="small" onClick={() => {
|
||||||
|
checkRunsForRecording(row.id).then((result: boolean) => {
|
||||||
|
if (result) {
|
||||||
|
notify('warning', 'Recording has associated runs, please delete them first');
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
deleteRecordingFromStorage(row.id).then((result: boolean) => {
|
deleteRecordingFromStorage(row.id).then((result: boolean) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
setRows([]);
|
setRows([]);
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ 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 {
|
||||||
@@ -56,6 +58,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);
|
||||||
|
localStorage.setItem('x-api-key', 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user