update runCase at once
This commit is contained in:
@@ -13,10 +13,6 @@ module.exports = function (sequelize) {
|
||||
const runCases = req.body;
|
||||
const t = await sequelize.transaction();
|
||||
|
||||
console.log('############## start edit');
|
||||
console.log(runCases);
|
||||
console.log('############## end edit');
|
||||
|
||||
const createRunCase = async (runCase) => {
|
||||
const newRunCase = await RunCase.create(
|
||||
{
|
||||
@@ -47,7 +43,7 @@ module.exports = function (sequelize) {
|
||||
transaction: t,
|
||||
}
|
||||
);
|
||||
return step;
|
||||
return runCase;
|
||||
};
|
||||
|
||||
try {
|
||||
|
||||
@@ -209,6 +209,7 @@ export default function CaseEditor({ projectId, folderId, caseId, messages, loca
|
||||
await updateSteps(context.token.access_token, Number(caseId), testCase.Steps);
|
||||
}
|
||||
setIsUpdating(false);
|
||||
setIsDirty(false);
|
||||
}}
|
||||
>
|
||||
{isUpdating ? messages.updating : messages.update}
|
||||
|
||||
@@ -140,30 +140,21 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
||||
|
||||
const handleIncludeExcludeCase = async (isInclude: boolean, clickedTestCaseId: number) => {
|
||||
setIsDirty(true);
|
||||
if (isInclude) {
|
||||
const newRunCase: RunCaseType = {
|
||||
id: 0,
|
||||
runId: Number(runId),
|
||||
caseId: clickedTestCaseId,
|
||||
status: 0,
|
||||
editState: 'new',
|
||||
};
|
||||
const keys = [clickedTestCaseId];
|
||||
const newRunCases = processRunCases(isInclude, keys, Number(runId), runCases);
|
||||
setRunCases(newRunCases);
|
||||
|
||||
setRunCases([...runCases, newRunCase]);
|
||||
} else {
|
||||
const deleteRunCase = runCases.find((runCase) => runCase.caseId === clickedTestCaseId);
|
||||
if (!deleteRunCase) {
|
||||
return;
|
||||
}
|
||||
deleteRunCase.editState = 'deleted';
|
||||
|
||||
setRunCases((prevRunCases) =>
|
||||
prevRunCases.map((runCase) => (runCase.caseId === deleteRunCase.runId ? deleteRunCase : runCase))
|
||||
);
|
||||
const updatedTestCases = testcases.map((testcase) => {
|
||||
if (testcase.id === clickedTestCaseId) {
|
||||
return { ...testcase, isIncluded: isInclude };
|
||||
}
|
||||
return testcase;
|
||||
});
|
||||
setTestCases(updatedTestCases);
|
||||
};
|
||||
|
||||
const handleBulkIncludeExcludeCases = async (isInclude: boolean) => {
|
||||
setIsDirty(true);
|
||||
let keys: number[] = [];
|
||||
if (selectedKeys === 'all') {
|
||||
keys = testcases.map((item) => item.id);
|
||||
@@ -215,6 +206,7 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
||||
await updateRun(context.token.access_token, testRun);
|
||||
await updateRunCases(context.token.access_token, Number(runId), runCases);
|
||||
setIsUpdating(false);
|
||||
setIsDirty(false);
|
||||
}}
|
||||
>
|
||||
{isUpdating ? messages.updating : messages.update}
|
||||
|
||||
@@ -156,17 +156,23 @@ function processRunCases(
|
||||
runId: number,
|
||||
currentRunCases: RunCaseType[]
|
||||
): RunCaseType[] {
|
||||
if (isInclude) {
|
||||
const updatedRunCases = currentRunCases.map((runCase) => {
|
||||
if (keys.includes(runCase.caseId) && runCase.editState === 'deleted') {
|
||||
return { ...runCase, editState: 'changed' } as RunCaseType;
|
||||
}
|
||||
return runCase;
|
||||
});
|
||||
const updatedRunCases = [...currentRunCases];
|
||||
|
||||
if (isInclude) {
|
||||
keys.forEach((caseId) => {
|
||||
const existingRunCase = currentRunCases.find((runCase) => runCase.caseId === caseId);
|
||||
if (!existingRunCase) {
|
||||
if (existingRunCase) {
|
||||
// already included
|
||||
if (existingRunCase.editState === 'notChanged') {
|
||||
// do nothing
|
||||
} else if (existingRunCase.editState === 'changed') {
|
||||
// do nothing
|
||||
} else if (existingRunCase.editState === 'new') {
|
||||
// do nothing
|
||||
} else if (existingRunCase.editState === 'deleted') {
|
||||
existingRunCase.editState = 'changed';
|
||||
}
|
||||
} else {
|
||||
updatedRunCases.push({
|
||||
id: -1,
|
||||
runId: runId,
|
||||
@@ -176,27 +182,26 @@ function processRunCases(
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return updatedRunCases;
|
||||
} else {
|
||||
const updatedRunCases = currentRunCases
|
||||
.filter((runCase) => {
|
||||
// If editState is 'new', remove from the array
|
||||
if (keys.includes(runCase.caseId) && runCase.editState === 'new') {
|
||||
return false;
|
||||
keys.forEach((caseId) => {
|
||||
const existingRunCase = currentRunCases.find((runCase) => runCase.caseId === caseId);
|
||||
if (!existingRunCase) {
|
||||
// already excluded
|
||||
} else {
|
||||
if (existingRunCase.editState === 'notChanged') {
|
||||
existingRunCase.editState = 'deleted';
|
||||
} else if (existingRunCase.editState === 'changed') {
|
||||
existingRunCase.editState = 'deleted';
|
||||
} else if (existingRunCase.editState === 'new') {
|
||||
existingRunCase.editState = 'deleted';
|
||||
} else if (existingRunCase.editState === 'deleted') {
|
||||
// do nothing
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.map((runCase) => {
|
||||
// If editState isn't 'new', set editState to 'deleted'.
|
||||
if (keys.includes(runCase.caseId) && runCase.editState !== 'new') {
|
||||
return { ...runCase, editState: 'deleted' } as RunCaseType;
|
||||
}
|
||||
return runCase;
|
||||
});
|
||||
}
|
||||
|
||||
return updatedRunCases;
|
||||
}
|
||||
}
|
||||
|
||||
async function updateRunCases(jwt: string, runId: number, runCases: RunCaseType[]) {
|
||||
@@ -209,9 +214,7 @@ async function updateRunCases(jwt: string, runId: number, runCases: RunCaseType[
|
||||
body: JSON.stringify(runCases),
|
||||
};
|
||||
|
||||
console.log(runCases);
|
||||
const url = `${apiServer}/runcases/update?runId=${runId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useEffect } from 'react';
|
||||
|
||||
export const useFormGuard = (isDirty: boolean, confirmText: string) => {
|
||||
useEffect(() => {
|
||||
console.log(isDirty);
|
||||
const handleClick = (event: MouseEvent) => {
|
||||
if (isDirty && event.target instanceof Element && event.target.closest('a:not([target="_blank"]')) {
|
||||
if (!window.confirm(confirmText)) {
|
||||
|
||||
Reference in New Issue
Block a user