From 1cf88c9dbd3bdf97f5a94487a8bdf7e8941991ed Mon Sep 17 00:00:00 2001 From: grvwy Date: Tue, 20 May 2025 00:47:09 +0200 Subject: [PATCH] logic fixes making sure the logic works and added a clear form for UX --- src/components/TagsManager.vue | 85 +++++++++++++++++++--------------- src/lang/en.json | 8 ++-- 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/components/TagsManager.vue b/src/components/TagsManager.vue index ae39b70d4..6f1f2df96 100644 --- a/src/components/TagsManager.vue +++ b/src/components/TagsManager.vue @@ -126,27 +126,21 @@ - -
- -
- {{ $t(validateDraftTag.messageKey, validateDraftTag.messageParams) }} -
- +
+ {{ $t(validateDraftTag.messageKey, validateDraftTag.messageParams) }} +
@@ -281,12 +275,13 @@ export default { return { invalid: true, messageKey: "tagAlreadyOnMonitor", messageParams: null }; } - // If an existing tag is selected and has no value, it's valid (value is optional) - if (this.newDraftTag.select != null && draftTagValue === "") { - return { invalid: false, messageKey: null, messageParams: null }; + // If an existing tag is selected at this point, it has passed all relevant checks + if (this.newDraftTag.select != null) { + return { invalid: false, messageKey: null, messageParams: null }; } - // If none of the above, invalid: false + // If it's a new tag definition, and it passed its specific checks, it's valid. + // (This also serves as a final default to valid if other logic paths were missed, though ideally covered above) return { invalid: false, messageKey: null, messageParams: null }; }, }, @@ -554,7 +549,26 @@ export default { * @returns {void} */ confirmAndCommitStagedTags() { + // Phase 1: If there's a currently valid newDraftTag that hasn't been staged yet, + // (e.g. user typed a full tag and directly clicked the footer "Add"), then stage it now. + // stageCurrentTag has its own check for validateDraftTag.invalid and will clear the draft. + if (!this.validateDraftTag.invalid) { + // Check if newDraftTag actually has content, to avoid staging an empty cleared draft. + // A valid draft implies it has content, but double-checking select or name is safer. + if (this.newDraftTag.select || (this.newDraftTag.name && this.newDraftTag.color)) { + this.stageCurrentTag(); + } + } + + // Phase 2: Process everything that is now in stagedForBatchAdd. + if (this.stagedForBatchAdd.length === 0) { + this.clearDraftTag(); // Ensure draft is clear even if nothing was committed + this.modal.hide(); + return; + } + for (const sTag of this.stagedForBatchAdd) { + let isAnUndo = false; // Flag to track if this was an undo // Check if it's an "undo delete" if (sTag.systemTagId) { // Only existing system tags can be an undo delete const undoDeleteIndex = this.deleteTags.findIndex( @@ -562,30 +576,27 @@ export default { ); if (undoDeleteIndex > -1) { this.deleteTags.splice(undoDeleteIndex, 1); - // If it was an undo, we don't need to add it to newTags again, as it's already in preSelectedTags or newTags from a previous session effectively - // However, the plan implies adding to newTags regardless. Let's stick to the plan. - // If this tag was previously in preSelectedTags and then deleted (in deleteTags), - // removing it from deleteTags makes it active again via selectedTags computed prop. - // If it was newly added in this session, then deleted, then re-staged, it would be in newTags. - // For simplicity and to align with the plan V.4 which says "Push this object to this.newTags": + isAnUndo = true; } } - // Create tag object for this.newTags - // The `new: true` flag indicates it's part of this transaction for the monitor. - // It does not strictly mean it is a new system tag. - const tagObjectForNewTags = { - id: sTag.systemTagId, // This will be null for brand new system tags - color: sTag.color, - name: sTag.name, - value: sTag.value, - new: true, // As per plan, signals new to this monitor transaction - }; - this.newTags.push(tagObjectForNewTags); + // Only add to newTags if it's not an "undo delete" operation. + // An "undo delete" means the tag is now considered active again from its previous state. + if (!isAnUndo) { + const tagObjectForNewTags = { + id: sTag.systemTagId, // This will be null for brand new system tags + color: sTag.color, + name: sTag.name, + value: sTag.value, + new: true, // As per plan, signals new to this monitor transaction + }; + this.newTags.push(tagObjectForNewTags); + } } - this.stagedForBatchAdd = []; - this.clearDraftTag(); // Resets input fields + // newDraftTag should have been cleared if stageCurrentTag ran in Phase 1, or earlier. + // Call clearDraftTag again to be certain the form is reset before closing. + this.clearDraftTag(); this.modal.hide(); }, }, diff --git a/src/lang/en.json b/src/lang/en.json index 24826fd87..08dc3eaba 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -191,8 +191,8 @@ "Add New below or Select...": "Add New below or Select…", "Tag with this name already exist.": "Tag with this name already exists.", "Tag with this value already exist.": "Tag with this value already exists.", - "tagAlreadyOnMonitor": "This tag (name + value) is already on this monitor.", - "tagAlreadyStaged": "This tag (name + value) is already staged for this batch.", + "tagAlreadyOnMonitor": "This tag (name and value) is already on the monitor or pending addition.", + "tagAlreadyStaged": "This tag (name and value) is already staged for this batch.", "tagLimitReached": "Cannot stage more than {limit} new system tags in a single batch.", "tagNameExists": "A system tag with this name already exists. Select it from the list or use a different name.", "color": "Color", @@ -1104,5 +1104,7 @@ "smsplanetNeedToApproveName": "Needs to be approved in the client panel", "Disable URL in Notification": "Disable URL in Notification", "Add Another Tag": "Add Another Tag", - "Staged Tags for Batch Add": "Staged Tags for Batch Add" + "Staged Tags for Batch Add": "Staged Tags for Batch Add", + "Clear Form": "Clear Form", + "pause": "Pause" }