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 = { type Props = {
history: RouterHistory, history: RouterHistory,
theme: Object, theme: Object,
source: string,
placeholder?: string, placeholder?: string,
collectionId?: string, collectionId?: string,
}; };
@ -33,7 +34,10 @@ class InputSearch extends React.Component<Props> {
handleSearchInput = (ev) => { handleSearchInput = (ev) => {
ev.preventDefault(); ev.preventDefault();
this.props.history.push( 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> <Action>
<InputSearch <InputSearch
source="collection"
placeholder="Search in collection…" placeholder="Search in collection…"
collectionId={match.params.id} collectionId={match.params.id}
/> />

View File

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

View File

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

View File

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

View File

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