Reduce cognitive complexity by extracting helper functions (S3776)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -217,55 +217,25 @@ function onNavItemBtnClick(event) {
|
|||||||
case "FILES":
|
case "FILES":
|
||||||
store.filesTag = navItemCandidate;
|
store.filesTag = navItemCandidate;
|
||||||
break;
|
break;
|
||||||
case "DISCOVER":
|
case "DISCOVER": {
|
||||||
type = route.params.type;
|
type = route.params.type;
|
||||||
fileId = route.params.fileId;
|
fileId = route.params.fileId;
|
||||||
isCheckPage = route.name.includes("Check");
|
isCheckPage = route.name.includes("Check");
|
||||||
|
const discoverRoutes = {
|
||||||
switch (navItemCandidate) {
|
MAP: "Map",
|
||||||
case "MAP":
|
CONFORMANCE: "Conformance",
|
||||||
if (isCheckPage) {
|
PERFORMANCE: "Performance",
|
||||||
|
};
|
||||||
|
const baseName = discoverRoutes[navItemCandidate];
|
||||||
|
if (baseName) {
|
||||||
|
const routeName = isCheckPage ? `Check${baseName}` : baseName;
|
||||||
router.push({
|
router.push({
|
||||||
name: "CheckMap",
|
name: routeName,
|
||||||
params: { type: type, fileId: fileId },
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
router.push({
|
|
||||||
name: "Map",
|
|
||||||
params: { type: type, fileId: fileId },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "CONFORMANCE":
|
|
||||||
if (isCheckPage) {
|
|
||||||
// Beware of Swal popup, it might disturb which is the current active page
|
|
||||||
router.push({
|
|
||||||
name: "CheckConformance",
|
|
||||||
params: { type: type, fileId: fileId },
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Beware of Swal popup, it might disturb which is the current active page
|
|
||||||
router.push({
|
|
||||||
name: "Conformance",
|
|
||||||
params: { type: type, fileId: fileId },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "PERFORMANCE":
|
|
||||||
if (isCheckPage) {
|
|
||||||
router.push({
|
|
||||||
name: "CheckPerformance",
|
|
||||||
params: { type: type, fileId: fileId },
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
router.push({
|
|
||||||
name: "Performance",
|
|
||||||
params: { type: type, fileId: fileId },
|
params: { type: type, fileId: fileId },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case "COMPARE":
|
case "COMPARE":
|
||||||
switch (navItemCandidate) {
|
switch (navItemCandidate) {
|
||||||
case "MAP":
|
case "MAP":
|
||||||
|
|||||||
@@ -310,20 +310,10 @@ const onInputDoubleClick = () => {
|
|||||||
isEditable.value = true;
|
isEditable.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onConfirmBtnClick = async () => {
|
/** Handles account creation in the confirm flow. */
|
||||||
// rule for minimum length
|
async function handleCreateNew() {
|
||||||
validatePwdLength();
|
|
||||||
if (!isPwdLengthValid.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// rule for account uniqueness
|
|
||||||
switch (whichCurrentModal.value) {
|
|
||||||
case MODAL_CREATE_NEW:
|
|
||||||
await checkAccountIsUnique();
|
await checkAccountIsUnique();
|
||||||
if (!isAccountUnique.value) {
|
if (!isAccountUnique.value) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
await acctMgmtStore.createNewAccount({
|
await acctMgmtStore.createNewAccount({
|
||||||
username: inputUserAccount.value,
|
username: inputUserAccount.value,
|
||||||
password: inputPwd.value === undefined ? "" : inputPwd.value,
|
password: inputPwd.value === undefined ? "" : inputPwd.value,
|
||||||
@@ -335,30 +325,39 @@ const onConfirmBtnClick = async () => {
|
|||||||
modalStore.closeModal();
|
modalStore.closeModal();
|
||||||
acctMgmtStore.setShouldUpdateList(true);
|
acctMgmtStore.setShouldUpdateList(true);
|
||||||
await router.push("/account-admin");
|
await router.push("/account-admin");
|
||||||
break;
|
}
|
||||||
case MODAL_ACCT_EDIT:
|
|
||||||
|
/** Handles account editing in the confirm flow. */
|
||||||
|
async function handleEditAccount() {
|
||||||
await checkAccountIsUnique();
|
await checkAccountIsUnique();
|
||||||
if (!isAccountUnique.value) {
|
if (!isAccountUnique.value) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Note that the old username and new username can be different
|
// Note that the old username and new username can be different
|
||||||
// Distinguish between cases with and without a password
|
const editDetail = {
|
||||||
|
newUsername: inputUserAccount.value,
|
||||||
|
name: inputName.value === undefined ? "" : inputName.value,
|
||||||
|
is_active: true,
|
||||||
|
};
|
||||||
if (isResetPwdSectionShow.value) {
|
if (isResetPwdSectionShow.value) {
|
||||||
await acctMgmtStore.editAccount(currentViewingUser.value.username, {
|
editDetail.password = inputPwd.value;
|
||||||
newUsername: inputUserAccount.value,
|
|
||||||
password: inputPwd.value,
|
|
||||||
name: inputName.value === undefined ? "" : inputName.value,
|
|
||||||
is_active: true,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await acctMgmtStore.editAccount(currentViewingUser.value.username, {
|
|
||||||
newUsername: inputUserAccount.value,
|
|
||||||
name: inputName.value === undefined ? "" : inputName.value,
|
|
||||||
is_active: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
await acctMgmtStore.editAccount(
|
||||||
|
currentViewingUser.value.username,
|
||||||
|
editDetail,
|
||||||
|
);
|
||||||
toast.success(i18next.t("AcctMgmt.MsgAccountEdited"));
|
toast.success(i18next.t("AcctMgmt.MsgAccountEdited"));
|
||||||
isEditable.value = false;
|
isEditable.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onConfirmBtnClick = async () => {
|
||||||
|
validatePwdLength();
|
||||||
|
if (!isPwdLengthValid.value) return;
|
||||||
|
|
||||||
|
switch (whichCurrentModal.value) {
|
||||||
|
case MODAL_CREATE_NEW:
|
||||||
|
await handleCreateNew();
|
||||||
|
break;
|
||||||
|
case MODAL_ACCT_EDIT:
|
||||||
|
await handleEditAccount();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user