feat: Add tracking of search source in UI

This commit is contained in:
Tom Moor 2020-09-24 21:56:37 -07:00
parent 40d52e9a78
commit 6f1f855083
6 changed files with 24 additions and 11 deletions

View File

@ -12,6 +12,7 @@ import { searchUrl } from "utils/routeHelpers";
type Props = {
history: RouterHistory,
theme: Object,
source: string,
placeholder?: string,
collectionId?: string,
};
@ -33,7 +34,10 @@ class InputSearch extends React.Component<Props> {
handleSearchInput = (ev) => {
ev.preventDefault();
this.props.history.push(
searchUrl(ev.target.value, this.props.collectionId)
searchUrl(ev.target.value, {
collectionId: this.props.collectionId,
ref: this.props.source,
})
);
};

View File

@ -140,6 +140,7 @@ class CollectionScene extends React.Component<Props> {
<>
<Action>
<InputSearch
source="collection"
placeholder="Search in collection…"
collectionId={match.params.id}
/>

View File

@ -67,7 +67,7 @@ class Dashboard extends React.Component<Props> {
</Switch>
<Actions align="center" justify="flex-end">
<Action>
<InputSearch />
<InputSearch source="dashboard" />
</Action>
<Action>
<NewDocumentMenu />

View File

@ -37,7 +37,7 @@ class Drafts extends React.Component<Props> {
<Actions align="center" justify="flex-end">
<Action>
<InputSearch />
<InputSearch source="drafts" />
</Action>
<Action>
<NewDocumentMenu />

View File

@ -49,7 +49,7 @@ class Starred extends React.Component<Props> {
<Actions align="center" justify="flex-end">
<Action>
<InputSearch />
<InputSearch source="starred" />
</Action>
<Action>
<NewDocumentMenu />

View File

@ -63,14 +63,22 @@ export function newDocumentUrl(
return `/collections/${collectionId}/new?${queryString.stringify(params)}`;
}
export function searchUrl(query?: string, collectionId?: string): string {
let route = "/search";
if (query) route += `/${encodeURIComponent(query)}`;
if (collectionId) {
route += `?collectionId=${collectionId}`;
export function searchUrl(
query?: string,
params?: {
collectionId?: string,
ref?: string,
}
return route;
): string {
let search = queryString.stringify(params);
let route = "/search";
if (query) {
route += `/${encodeURIComponent(query)}`;
}
search = search ? `?${search}` : "";
return `${route}${search}`;
}
export function notFoundUrl(): string {