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