Skip to content

Commit c10c3f1

Browse files
committed
ILEX-135 handle edit term flow
1 parent 4cf821b commit c10c3f1

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/components/TermEditor/NewTermSidebar.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ const ResultItem = ({ result, searchValue, onResultAction, user }) => {
159159
}
160160
});
161161

162+
console.log("result: ", result)
163+
162164
return (
163165
<Box
164166
width={1}

src/components/TermEditor/newTerm/AddNewTermDialog.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ const AddNewTermDialog = ({ open, handleClose }) => {
179179
if (result?.label) {
180180
setSelectedTermValue(result.label);
181181
handleTermValueChange(result.label);
182+
setIsEditing(true); // Set editing state when a term is selected from sidebar
182183
}
183184
};
184185

@@ -244,7 +245,7 @@ const AddNewTermDialog = ({ open, handleClose }) => {
244245

245246
return (
246247
<CustomizedDialog
247-
title="Add new term"
248+
title={isEditing ? "Edit term" : "Add new term"}
248249
open={open}
249250
handleClose={handleClose}
250251
HeaderRightSideContent={

src/hooks/useTermSearch.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
1010
const [synonymValidationStatus, setSynonymValidationStatus] = useState({})
1111
const { user } = useContext(GlobalDataContext)
1212
const checkedSynonymsRef = useRef(new Set())
13+
const preservedResultsRef = useRef([]) // Store results during editing
1314

1415
const checkSynonym = useCallback(async (synonym, searchType) => {
1516
try {
@@ -28,8 +29,17 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
2829
}, [user?.groupname])
2930

3031
const searchTerm = useCallback(async (searchTerm, searchType) => {
31-
if (!searchTerm || !searchType || isEditing) {
32+
if (!searchTerm || !searchType) {
3233
setSearchResults([])
34+
preservedResultsRef.current = []
35+
return
36+
}
37+
38+
// Don't search again if we're in editing mode, but preserve existing results
39+
if (isEditing) {
40+
if (preservedResultsRef.current.length > 0) {
41+
setSearchResults(preservedResultsRef.current)
42+
}
3343
return
3444
}
3545

@@ -50,6 +60,7 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
5060
})) || []
5161

5262
setSearchResults(searchResults)
63+
preservedResultsRef.current = searchResults // Preserve for editing mode
5364
} catch (error) {
5465
if (error?.response?.status === 409 && error?.response?.data?.existing) {
5566
onExactMatchChange(true)
@@ -64,6 +75,7 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
6475
}
6576
)
6677
setSearchResults(exactMatches)
78+
preservedResultsRef.current = exactMatches // Preserve exact matches too
6779
} else {
6880
onExactMatchChange(false)
6981
setSearchResults([])
@@ -98,6 +110,7 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
98110
useEffect(() => {
99111
if (!term) {
100112
setSearchResults([])
113+
preservedResultsRef.current = [] // Clear preserved results when no term
101114
onExactMatchChange(false)
102115
return
103116
}

0 commit comments

Comments
 (0)