Merge pull request #48 from mstg/cancel-button

Add Cancel button to running tasks
This commit is contained in:
resf-prow[bot] 2022-10-30 21:15:07 +00:00 committed by GitHub
commit 08e6055195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 22 deletions

View File

@ -40,6 +40,7 @@ import { packageApi, taskApi } from 'peridot/ui/src/api';
import { import {
V1GetTaskResponse, V1GetTaskResponse,
V1TaskType, V1TaskType,
V1TaskStatus,
} from 'bazel-bin/peridot/proto/v1/client_typescript'; } from 'bazel-bin/peridot/proto/v1/client_typescript';
import { ToolbarHeader } from 'common/mui/ToolbarHeader'; import { ToolbarHeader } from 'common/mui/ToolbarHeader';
import Divider from '@mui/material/Divider'; import Divider from '@mui/material/Divider';
@ -54,12 +55,14 @@ import TabContext from '@mui/lab/TabContext';
import TabList from '@mui/lab/TabList'; import TabList from '@mui/lab/TabList';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import Tab from '@mui/material/Tab'; import Tab from '@mui/material/Tab';
import Button from '@mui/material/Button';
import TabPanel from '@mui/lab/TabPanel'; import TabPanel from '@mui/lab/TabPanel';
import ProjectTaskFullLog from 'peridot/ui/src/components/ProjectTaskFullLog'; import ProjectTaskFullLog from 'peridot/ui/src/components/ProjectTaskFullLog';
import { RemoteErrors } from 'common/ui/types'; import { RemoteErrors } from 'common/ui/types';
import Tabs from '@mui/material/Tabs'; import Tabs from '@mui/material/Tabs';
import Toolbar from '@mui/material/Toolbar'; import Toolbar from '@mui/material/Toolbar';
import { ProjectTasksSubtasks } from 'peridot/ui/src/components/ProjectTasksSubtasks'; import { ProjectTasksSubtasks } from 'peridot/ui/src/components/ProjectTasksSubtasks';
import { reqap } from 'common/ui/reqap';
export interface ProjectPackageDetailsRouteProps { export interface ProjectPackageDetailsRouteProps {
id: string; id: string;
@ -77,6 +80,7 @@ export default function (
V1GetTaskResponse | undefined | null | RemoteErrors V1GetTaskResponse | undefined | null | RemoteErrors
>(undefined); >(undefined);
const [tabValue, setTabValue] = React.useState('1'); const [tabValue, setTabValue] = React.useState('1');
const [submitting, setSubmitting] = React.useState(false);
const handleTabValueChange = (event, newValue) => { const handleTabValueChange = (event, newValue) => {
setTabValue(newValue); setTabValue(newValue);
@ -91,6 +95,26 @@ export default function (
setTaskRes setTaskRes
); );
const cancelTask = async () => {
if (!confirm('Are you sure you want to cancel this task?')) {
return;
}
setSubmitting(true);
const [err, res] = await reqap(() =>
taskApi.cancelTask({
id: props.match.params.id,
projectId: project.id || '',
})
);
if (err) {
alert(err);
setSubmitting(false);
return;
}
window.location.reload();
};
return ( return (
<> <>
{suspenseRemoteResource(taskRes, (res) => { {suspenseRemoteResource(taskRes, (res) => {
@ -119,6 +143,7 @@ export default function (
</div> </div>
</ToolbarHeader> </ToolbarHeader>
<Divider /> <Divider />
<div className="w-full flex items-center justify-between bg-white">
<div className="w-full bg-white flex divide-x divide-gray-100"> <div className="w-full bg-white flex divide-x divide-gray-100">
<div className="p-5 w-128 space-y-1"> <div className="p-5 w-128 space-y-1">
<h2 className="font-bold text-lg">Type</h2> <h2 className="font-bold text-lg">Type</h2>
@ -145,6 +170,20 @@ export default function (
</div> </div>
)} )}
</div> </div>
{!parentTask.parentTaskId &&
parentTask.status == V1TaskStatus.Running && (
<div className="p-5">
<Button
variant="contained"
disabled={submitting}
color="error"
onClick={cancelTask}
>
Cancel
</Button>
</div>
)}
</div>
<Divider /> <Divider />
<Box className="bg-white"> <Box className="bg-white">
<Tabs value={tabValue} onChange={handleTabValueChange}> <Tabs value={tabValue} onChange={handleTabValueChange}>

View File

@ -1 +1 @@
rules_byc/internal/byc_bundle/tsconfig.json rules_resf/internal/resf_bundle/tsconfig.json