Skip to content

Commit 4fc7f90

Browse files
authored
fix(tags): persist tag selections in the case and session editors (#456)
Adding a tag in the case or session editor created the Tag but never linked it, and selecting an existing tag while also creating one was lost too. Creating a tag invalidates the parent queries (the case/session rows include their tags), which refetches the case/session; a reset/re-sync effect then reverted the user's in-progress tag selection to the saved tags before the form submitted, so the new (or selected) tags were dropped. The run editor was unaffected because it keeps tags in plain component state with no such re-sync. - Case editor: the defaults-restore effect now preserves the current tags value (currentValues.tags) on re-run, matching how issues were already preserved. - Session editor: selectedTags is initialized from the loaded session once (guarded by a ref) instead of re-syncing on every sessionData change.
1 parent 18e497a commit 4fc7f90

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

  • testplanit/app/[locale]/projects

testplanit/app/[locale]/projects/repository/[projectId]/[caseId]/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,11 @@ export default function TestCaseDetails() {
914914
folderId: testcase.folderId,
915915
estimate: testcase.estimate ? formatSeconds(testcase.estimate) : "",
916916
automated: testcase.automated,
917-
tags: testcase.tags?.map((tag: any) => tag.id) || [],
917+
// Preserve the in-progress tag selection across re-runs of this effect (e.g. creating a tag
918+
// invalidates the Tags query and refetches the case, re-firing this reset). Without this the
919+
// user's edits to tags are silently reverted to the case's saved tags, like issues below.
920+
tags:
921+
currentValues.tags || testcase.tags?.map((tag: any) => tag.id) || [],
918922
// Preserve existing issues value if it's already set (from external issues)
919923
issues:
920924
currentValues.issues ||

testplanit/app/[locale]/projects/sessions/[projectId]/[sessionId]/page.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,10 @@ export default function SessionPage() {
804804
);
805805
const [isSubmitting, setIsSubmitting] = useState(false);
806806
const [selectedTags, setSelectedTags] = useState<number[]>([]);
807+
// Initialize selectedTags from the loaded session ONCE. Creating a tag invalidates parent queries
808+
// (the session includes its tags), refetching sessionData; without this guard the re-sync effect
809+
// below would revert the user's in-progress tag edits on that refetch.
810+
const hasInitializedTagsRef = useRef(false);
807811
const [missionContent, setMissionContent] =
808812
useState<JSONContent>(emptyEditorContent);
809813
const [noteContent, setNoteContent] =
@@ -1251,7 +1255,6 @@ export default function SessionPage() {
12511255
keepDefaultValues: true,
12521256
});
12531257
setInitialValues(formValues);
1254-
setSelectedTags(sessionData.tags.map((tag) => tag.id));
12551258

12561259
// Delay setting form as initialized
12571260
requestAnimationFrame(() => {
@@ -1402,10 +1405,12 @@ export default function SessionPage() {
14021405
}
14031406
}, [sessionData, sessionData?.note, sessionData?.mission]);
14041407

1405-
// Add useEffect for initial tags
1408+
// Initialize the tag selection from the loaded session, once (see hasInitializedTagsRef) so a
1409+
// tag-create refetch of sessionData does not revert in-progress edits.
14061410
useEffect(() => {
1407-
if (sessionData) {
1411+
if (sessionData && !hasInitializedTagsRef.current) {
14081412
setSelectedTags(sessionData.tags.map((tag) => tag.id));
1413+
hasInitializedTagsRef.current = true;
14091414
}
14101415
}, [sessionData]);
14111416

0 commit comments

Comments
 (0)