Skip to content

Commit

Permalink
add get redirect with full text
Browse files Browse the repository at this point in the history
  • Loading branch information
vsseixaso committed Jan 9, 2025
1 parent 79334f0 commit 7d2cd2c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
36 changes: 30 additions & 6 deletions react/RedirectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
withTargetPath,
} from './components/admin/TargetPathContext'
import Redirects from './queries/Redirects.graphql'
import RedirectWithoutBinding from './queries/RedirectWithoutBinding.graphql'

interface CustomProps {
hasMultipleBindings: boolean
Expand Down Expand Up @@ -243,12 +244,35 @@ const RedirectList: React.FC<Props> = ({
const innerNext = innerData?.redirect?.listRedirects.next
const next = innerNext ?? data?.redirect?.listRedirects.next

if (!filteredRedirects.length && next) {
const { data } = await refetch({ limit: REDIRECTS_LIMIT, next })
handleInputSearchChange(e, data)
} else {
setRedirectList(filteredRedirects)
}
const listRedirectsPromise = (async () => {
if (!filteredRedirects.length && next) {
const { data } = await refetch({ limit: REDIRECTS_LIMIT, next })
return data.redirect.listRedirects.routes
} else {
return filteredRedirects
}
})()

const fullTextSearchPromise = (async () => {
if (term.length) {
const { data: fullTextData } = await client.query({
query: RedirectWithoutBinding,
variables: {
path: term,
},
})
if (fullTextData?.redirect?.get) {
return [fullTextData.redirect.get]
}
}
return []
})()

const result = await Promise.race([
listRedirectsPromise,
fullTextSearchPromise,
])
setRedirectList(result)

if (term.length) {
setFiltered(true)
Expand Down
11 changes: 11 additions & 0 deletions react/queries/RedirectWithoutBinding.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query RedirectWithoutBinding($path: String!) {
redirect @context(provider: "vtex.rewriter") {
get(path: $path) {
binding
endDate
from
to
type
}
}
}

0 comments on commit 7d2cd2c

Please sign in to comment.