Delete test case
This commit is contained in:
@@ -31,6 +31,27 @@ async function fetchCases(url) {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchDeleteCase(caseId: number) {
|
||||
const fetchOptions = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
|
||||
const url = `${apiServer}/cases/${caseId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error deleting project:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export default function Page({
|
||||
params,
|
||||
}: {
|
||||
@@ -52,9 +73,19 @@ export default function Page({
|
||||
fetchDataEffect();
|
||||
}, []);
|
||||
|
||||
const handleDeleteCase = async (caseId: number) => {
|
||||
await fetchDeleteCase(caseId);
|
||||
const data = await fetchCases(url);
|
||||
setCases(data);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<TestCaseTable projectId={params.folderId} cases={cases}/>
|
||||
<TestCaseTable
|
||||
projectId={params.folderId}
|
||||
cases={cases}
|
||||
onDeleteCase={handleDeleteCase}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,13 @@ type Case = {
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export default function TestCaseTable({ projectId, cases }) {
|
||||
type Props = {
|
||||
projectId: boolean;
|
||||
cases: Case[];
|
||||
onDeleteCase: (caseId: number) => void;
|
||||
};
|
||||
|
||||
export default function TestCaseTable({ projectId, cases, onDeleteCase }: Props) {
|
||||
const [selectedKeys, setSelectedKeys] = useState<Selection>(new Set([]));
|
||||
const [sortDescriptor, setSortDescriptor] = useState<SortDescriptor>({
|
||||
column: "id",
|
||||
@@ -94,8 +100,7 @@ export default function TestCaseTable({ projectId, cases }) {
|
||||
</Button>
|
||||
</DropdownTrigger>
|
||||
<DropdownMenu aria-label="test case actions">
|
||||
<DropdownItem>Edit test case</DropdownItem>
|
||||
<DropdownItem className="text-danger">
|
||||
<DropdownItem className="text-danger" onClick={() => onDeleteCase(testCase.id)}>
|
||||
Delete test case
|
||||
</DropdownItem>
|
||||
</DropdownMenu>
|
||||
|
||||
Reference in New Issue
Block a user