Merge pull request #309 from getmaxun/robot-sort

chore: cleanup src/api
This commit is contained in:
Karishma Shukla
2025-01-01 23:32:37 +05:30
committed by GitHub
3 changed files with 15 additions and 35 deletions

View File

@@ -5,11 +5,6 @@ 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`);
@@ -82,11 +77,7 @@ export const getStoredRecording = async (id: string) => {
} }
} }
export const checkRunsForRecording = async (id: string): Promise<boolean> => { export const checkRunsForRecording = async (id: string): Promise<boolean> => {
try { try {
const response = await axios.get(`${apiUrl}/storage/recordings/${id}/runs`); const response = await axios.get(`${apiUrl}/storage/recordings/${id}/runs`);
@@ -99,32 +90,26 @@ export const checkRunsForRecording = async (id: string): Promise<boolean> => {
} }
}; };
export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => { export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => {
const hasRuns = await checkRunsForRecording(id); const hasRuns = await checkRunsForRecording(id);
if (hasRuns) { if (hasRuns) {
return false; 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 true; 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> => {
@@ -159,7 +144,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 {

View File

@@ -3,7 +3,7 @@ import { emptyWorkflow } from "../shared/constants";
import { default as axios, AxiosResponse } from "axios"; import { default as axios, AxiosResponse } from "axios";
import { apiUrl } from "../apiConfig"; import { apiUrl } from "../apiConfig";
export const getActiveWorkflow = async(id: string) : Promise<WorkflowFile> => { export const getActiveWorkflow = async (id: string): Promise<WorkflowFile> => {
try { try {
const response = await axios.get(`${apiUrl}/workflow/${id}`) const response = await axios.get(`${apiUrl}/workflow/${id}`)
if (response.status === 200) { if (response.status === 200) {
@@ -11,13 +11,13 @@ export const getActiveWorkflow = async(id: string) : Promise<WorkflowFile> => {
} else { } else {
throw new Error('Something went wrong when fetching a recorded workflow'); throw new Error('Something went wrong when fetching a recorded workflow');
} }
} catch(error: any) { } catch (error: any) {
console.log(error); console.log(error);
return emptyWorkflow; return emptyWorkflow;
} }
}; };
export const getParamsOfActiveWorkflow = async(id: string) : Promise<string[]|null> => { export const getParamsOfActiveWorkflow = async (id: string): Promise<string[] | null> => {
try { try {
const response = await axios.get(`${apiUrl}/workflow/params/${id}`) const response = await axios.get(`${apiUrl}/workflow/params/${id}`)
if (response.status === 200) { if (response.status === 200) {
@@ -25,15 +25,15 @@ export const getParamsOfActiveWorkflow = async(id: string) : Promise<string[]|nu
} else { } else {
throw new Error('Something went wrong when fetching the parameters of the recorded workflow'); throw new Error('Something went wrong when fetching the parameters of the recorded workflow');
} }
} catch(error: any) { } catch (error: any) {
console.log(error); console.log(error);
return null; return null;
} }
}; };
export const deletePair = async(index: number): Promise<WorkflowFile> => { export const deletePair = async (index: number): Promise<WorkflowFile> => {
try { try {
const response = await axios.delete(`${apiUrl}/workflow/pair/${index}`); const response = await axios.delete(`${apiUrl}/workflow/pair/${index}`);
if (response.status === 200) { if (response.status === 200) {
return response.data; return response.data;
} else { } else {
@@ -45,11 +45,11 @@ export const deletePair = async(index: number): Promise<WorkflowFile> => {
} }
}; };
export const AddPair = async(index: number, pair: WhereWhatPair): Promise<WorkflowFile> => { export const AddPair = async (index: number, pair: WhereWhatPair): Promise<WorkflowFile> => {
try { try {
const response = await axios.post(`${apiUrl}/workflow/pair/${index}`, { const response = await axios.post(`${apiUrl}/workflow/pair/${index}`, {
pair, pair,
}, {headers: {'Content-Type': 'application/json'}}); }, { headers: { 'Content-Type': 'application/json' } });
if (response.status === 200) { if (response.status === 200) {
return response.data; return response.data;
} else { } else {
@@ -61,11 +61,11 @@ export const AddPair = async(index: number, pair: WhereWhatPair): Promise<Workfl
} }
}; };
export const UpdatePair = async(index: number, pair: WhereWhatPair): Promise<WorkflowFile> => { export const UpdatePair = async (index: number, pair: WhereWhatPair): Promise<WorkflowFile> => {
try { try {
const response = await axios.put(`${apiUrl}/workflow/pair/${index}`, { const response = await axios.put(`${apiUrl}/workflow/pair/${index}`, {
pair, pair,
}, {headers: {'Content-Type': 'application/json'}}); }, { headers: { 'Content-Type': 'application/json' } });
if (response.status === 200) { if (response.status === 200) {
return response.data; return response.data;
} else { } else {

View File

@@ -33,10 +33,6 @@ interface Column {
format?: (value: string) => string; format?: (value: string) => string;
} }
interface Data { interface Data {
id: string; id: string;
name: string; name: string;
@@ -441,7 +437,6 @@ const OptionsButton = ({ handleEdit, handleDelete, handleDuplicate }: OptionsBut
</ListItemIcon> </ListItemIcon>
<ListItemText>{t('recordingtable.duplicate')}</ListItemText> <ListItemText>{t('recordingtable.duplicate')}</ListItemText>
</MenuItem> </MenuItem>
</Menu> </Menu>
</> </>
); );