cleanup search documents action
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
ShapesIcon,
|
||||
ImportIcon,
|
||||
PinIcon,
|
||||
SearchIcon,
|
||||
} from "outline-icons";
|
||||
import * as React from "react";
|
||||
import getDataTransferFiles from "@shared/utils/getDataTransferFiles";
|
||||
@@ -17,7 +18,7 @@ import DocumentTemplatize from "~/scenes/DocumentTemplatize";
|
||||
import { createAction } from "~/actions";
|
||||
import { DocumentSection } from "~/actions/sections";
|
||||
import history from "~/utils/history";
|
||||
import { homePath, newDocumentPath } from "~/utils/routeHelpers";
|
||||
import { homePath, newDocumentPath, searchPath } from "~/utils/routeHelpers";
|
||||
|
||||
export const openDocument = createAction({
|
||||
name: ({ t }) => t("Open document"),
|
||||
@@ -318,6 +319,17 @@ export const createTemplate = createAction({
|
||||
},
|
||||
});
|
||||
|
||||
export const searchDocumentsForQuery = (searchQuery: string) =>
|
||||
createAction({
|
||||
id: "search",
|
||||
section: DocumentSection,
|
||||
name: ({ t }) =>
|
||||
t(`Search documents for "{{searchQuery}}"`, { searchQuery }),
|
||||
icon: <SearchIcon />,
|
||||
perform: () => history.push(searchPath(searchQuery)),
|
||||
visible: ({ location }) => location.pathname !== searchPath(),
|
||||
});
|
||||
|
||||
export const rootDocumentActions = [
|
||||
openDocument,
|
||||
createDocument,
|
||||
|
||||
@@ -23,11 +23,7 @@ import stores from "~/stores";
|
||||
import SearchQuery from "~/models/SearchQuery";
|
||||
import KeyboardShortcuts from "~/scenes/KeyboardShortcuts";
|
||||
import { createAction } from "~/actions";
|
||||
import {
|
||||
NavigationSection,
|
||||
SearchSection,
|
||||
RecentSearchesSection,
|
||||
} from "~/actions/sections";
|
||||
import { NavigationSection, RecentSearchesSection } from "~/actions/sections";
|
||||
import history from "~/utils/history";
|
||||
import {
|
||||
organizationSettingsPath,
|
||||
@@ -57,17 +53,6 @@ export const navigateToRecentSearchQuery = (searchQuery: SearchQuery) =>
|
||||
perform: () => history.push(searchPath(searchQuery.query)),
|
||||
});
|
||||
|
||||
export const navigateToSearchQuery = (searchQuery: string) =>
|
||||
createAction({
|
||||
id: "search",
|
||||
section: SearchSection,
|
||||
name: ({ t }) =>
|
||||
t(`Search documents for "{{searchQuery}}"`, { searchQuery }),
|
||||
icon: <SearchIcon />,
|
||||
perform: () => history.push(searchPath(searchQuery)),
|
||||
visible: ({ location }) => location.pathname !== searchPath(),
|
||||
});
|
||||
|
||||
export const navigateToDrafts = createAction({
|
||||
name: ({ t }) => t("Drafts"),
|
||||
section: NavigationSection,
|
||||
|
||||
@@ -14,5 +14,3 @@ export const UserSection = ({ t }: ActionContext) => t("People");
|
||||
|
||||
export const RecentSearchesSection = ({ t }: ActionContext) =>
|
||||
t("Recent searches");
|
||||
|
||||
export const SearchSection = "";
|
||||
|
||||
@@ -48,9 +48,7 @@ function CommandBar() {
|
||||
t("Type a command or search")
|
||||
}…`}
|
||||
/>
|
||||
<CommandBarResults
|
||||
prioritizeSearchResults={ui.commandBarOpenedFromSidebar}
|
||||
/>
|
||||
<CommandBarResults />
|
||||
{ui.commandBarOpenedFromSidebar && (
|
||||
<Hint size="small" type="tertiary">
|
||||
<QuestionMarkIcon size={18} color="currentColor" />
|
||||
|
||||
@@ -1,27 +1,14 @@
|
||||
import { useMatches, KBarResults } from "kbar";
|
||||
import { orderBy } from "lodash";
|
||||
import * as React from "react";
|
||||
import styled from "styled-components";
|
||||
import CommandBarItem from "~/components/CommandBarItem";
|
||||
import { SearchSection } from "~/actions/sections";
|
||||
|
||||
type Props = {
|
||||
prioritizeSearchResults: boolean;
|
||||
};
|
||||
|
||||
export default function CommandBarResults(props: Props) {
|
||||
export default function CommandBarResults() {
|
||||
const { results, rootActionId } = useMatches();
|
||||
|
||||
return (
|
||||
<KBarResults
|
||||
items={orderBy(results, (item) =>
|
||||
// this is an unfortunate hack until kbar supports priority internally
|
||||
typeof item !== "string" &&
|
||||
item.section === SearchSection &&
|
||||
props.prioritizeSearchResults
|
||||
? -1
|
||||
: 1
|
||||
)}
|
||||
items={results}
|
||||
maxHeight={400}
|
||||
onRender={({ item, active }) =>
|
||||
typeof item === "string" ? (
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useKBar } from "kbar";
|
||||
import * as React from "react";
|
||||
import {
|
||||
navigateToRecentSearchQuery,
|
||||
navigateToSearchQuery,
|
||||
} from "~/actions/definitions/navigation";
|
||||
import { searchDocumentsForQuery } from "~/actions/definitions/documents";
|
||||
import { navigateToRecentSearchQuery } from "~/actions/definitions/navigation";
|
||||
|
||||
import useCommandBarActions from "~/hooks/useCommandBarActions";
|
||||
import useStores from "~/hooks/useStores";
|
||||
|
||||
@@ -18,7 +17,9 @@ export default function SearchActions() {
|
||||
searchQuery: state.searchQuery,
|
||||
}));
|
||||
|
||||
useCommandBarActions(searchQuery ? [navigateToSearchQuery(searchQuery)] : []);
|
||||
useCommandBarActions(
|
||||
searchQuery ? [searchDocumentsForQuery(searchQuery)] : []
|
||||
);
|
||||
|
||||
useCommandBarActions(searches.recent.map(navigateToRecentSearchQuery));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user