Skip to content

Commit 40c85b7

Browse files
committed
review endPoint and label
1 parent 771208c commit 40c85b7

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

package-lock.json

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/tdb-dashboard/src/hooks/useOpenAI.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ export function useOpenAI(){
3030

3131
const location = useLocation()
3232

33-
34-
useEffect(()=>{
33+
const resetSearch =() => {
3534
if(location.state && location.state.previewPage === "documentView"){
36-
const resultSaved = localStorage.getItem(`${location.pathname}___SEARCH__RESULT`)
37-
const startSaved = localStorage.getItem(`${location.pathname}___START`) || 0
38-
setStartValue(Number(startSaved))
39-
if(resultSaved)setSearchResult(JSON.parse(resultSaved))
35+
const resultSaved = localStorage.getItem(`${location.pathname}___SEARCH__RESULT`)
36+
const startSaved = localStorage.getItem(`${location.pathname}___START`) || 0
37+
setStartValue(Number(startSaved))
38+
if(resultSaved)setSearchResult(JSON.parse(resultSaved))
39+
}else{
40+
setStartValue(0)
41+
setSearchResult(false)
4042
}
41-
},[location])
43+
}
4244

4345
function getUrl(action="changes"){
4446
const client = woqlClient.copy()
@@ -54,9 +56,9 @@ export function useOpenAI(){
5456
///changes/:orgid/:dbid/indexedcommit
5557
const getSearchableCommit = async (limit=1, status=null)=>{
5658
try{
57-
setLoading(true)
5859
setSearchableCommit(false)
59-
const url = `${getUrl()}/indexedcommits?limit=${limit}&status=${status}`
60+
setLoading(true)
61+
const url = `${getUrl('indexes')}?limit=${limit}&status=${status}`
6062
const result = await woqlClient.sendCustomRequest("GET", url)
6163
if(result && result.bindings){
6264
setSearchableCommit(result.bindings)
@@ -72,9 +74,10 @@ export function useOpenAI(){
7274
const getResearchResult = async (commit, freeText, domain, branch = "main" ) =>{
7375
if(woqlClient){
7476
try{
77+
setSearchResult(false)
7578
setLoading(true)
7679
localStorage.setItem(`${location.pathname}___SEARCH__TEXT`,freeText)
77-
const url = `${getUrl('index')}/search?domain=${domain}&commit=${commit}`
80+
const url = `${getUrl('indexes')}/search?domain=${domain}&commit=${commit}`
7881
const result = await woqlClient.sendCustomRequest("POST", url , {freeText:freeText})
7982
localStorage.setItem(`${location.pathname}___SEARCH__RESULT`,JSON.stringify(result))
8083
setSearchResult(result)
@@ -104,7 +107,7 @@ export function useOpenAI(){
104107

105108
const pollingCall = async (commitid,updateStatus) =>{
106109
try{
107-
const pollingUrl = `${getUrl()}/check/${commitid}`
110+
const pollingUrl = `${getUrl('indexes')}/check/${commitid}`
108111
const document = await woqlClient.sendCustomRequest("GET", pollingUrl)
109112
if(document.indexing_status !== "Assigned" && document.indexing_status !== "Error"){
110113
await timeout(5000)
@@ -301,6 +304,7 @@ export function useOpenAI(){
301304

302305

303306
return {pollingCall,
307+
resetSearch,
304308
getPrewiew,
305309
resetPreviewResult,
306310
getSearchableCommit,

packages/tdb-dashboard/src/pages/FreeTextSearch.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Alert from "react-bootstrap/Alert";
1616

1717
export function FreeTextSearch() {
1818

19-
const {getSearchableCommit, searchableCommit, searchResult,getResearchResult,start,setStart, error, setError,loading,} = useOpenAI()
19+
const {resetSearch, getSearchableCommit, searchableCommit, searchResult,getResearchResult,start,setStart, error, setError,loading,} = useOpenAI()
2020
const {dataProduct, organization} = useParams()
2121

2222
const search = useRef(null)
@@ -26,11 +26,14 @@ export function FreeTextSearch() {
2626

2727
const commit = Array.isArray(searchableCommit) && searchableCommit.length>0 ? searchableCommit[0].searchable_commit['@value'] : null
2828
useEffect(()=>{
29-
if(searchResult)getElements()
30-
29+
if(searchResult){
30+
getElements()
31+
}
3132
},[start,searchResult])
3233

3334
useEffect(()=>{
35+
setElements([])
36+
resetSearch()
3437
getSearchableCommit(1, "Assigned")
3538
},[dataProduct])
3639

0 commit comments

Comments
 (0)