Skip to content

Commit

Permalink
#1320 Search page
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jul 8, 2024
1 parent d7f09b7 commit ac93f8a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
13 changes: 13 additions & 0 deletions ontrack-web-core/components/providers/RefDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const refDataSignature = {
list: [],
index: {},
},
/**
* List of search result types
*/
searchResultTypes: [],
/**
* Version of Ontrack
*/
Expand Down Expand Up @@ -100,6 +104,14 @@ export default function RefDataContextProvider({children}) {
id
description
}
searchResultTypes {
feature {
id
}
id
name
description
}
}
`
).then(data => {
Expand All @@ -108,6 +120,7 @@ export default function RefDataContextProvider({children}) {
eventTypes: data.eventTypes,
jobStates: jobStates,
version: data.info.version.display,
searchResultTypes: data.searchResultTypes,
})
})
}
Expand Down
10 changes: 3 additions & 7 deletions ontrack-web-core/components/search/NavBarSearch.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import {Input} from "antd";
import {useRouter} from "next/router";
import {useSearch} from "@/pages/search";

export default function NavBarSearch({style}) {

const router = useRouter()

const onSearch = async (value) => {
await router.push(`/search?q=${encodeURIComponent(value)}`)
}
const search = useSearch()

return (
<>
<Input.Search
style={style}
placeholder="Search..."
onSearch={onSearch}
onSearch={search}
/>
</>
)
Expand Down
41 changes: 41 additions & 0 deletions ontrack-web-core/components/search/SearchView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {useRefData} from "@components/providers/RefDataProvider";
import {useGraphQLClient} from "@components/providers/ConnectionContextProvider";
import Head from "next/head";
import {pageTitle} from "@components/common/Titles";
import {homeUri} from "@components/common/Links";
import {CloseCommand} from "@components/common/Commands";
import {homeBreadcrumbs} from "@components/common/Breadcrumbs";
import MainPage from "@components/layouts/MainPage";

export default function SearchView({q}) {
const {searchResultTypes} = useRefData()
const client = useGraphQLClient()

// useEffect(() => {
// if (client && q) {
// client.request(
// gql`
// query Search($q: String!) {
// search()
// }
// `,
// {q}
// )
// }
// }, [client, q])

return (
<>
<Head>
{pageTitle("Search")}
</Head>
<MainPage
title="Search"
breadcrumbs={homeBreadcrumbs()}
commands={[
<CloseCommand key="close" href={homeUri()}/>,
]}
/>
</>
)
}
28 changes: 28 additions & 0 deletions ontrack-web-core/pages/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {useRouter} from "next/router";
import MainLayout from "@components/layouts/MainLayout";
import SearchView from "@components/search/SearchView";

export const useSearch = () => {

const router = useRouter()

return async (value) => {
await router.push(`/search?q=${encodeURIComponent(value)}`)
}

}

export default function SearchPage() {
const router = useRouter()
const {q} = router.query

return (
<>
<main>
<MainLayout>
<SearchView q={q}/>
</MainLayout>
</main>
</>
)
}

0 comments on commit ac93f8a

Please sign in to comment.