diff --git a/app/scenes/Search/Search.tsx b/app/scenes/Search/Search.tsx index 0b8b7a715..85ec89e20 100644 --- a/app/scenes/Search/Search.tsx +++ b/app/scenes/Search/Search.tsx @@ -30,9 +30,9 @@ import { searchPath } from "~/utils/routeHelpers"; import { decodeURIComponentSafe } from "~/utils/urls"; import CollectionFilter from "./components/CollectionFilter"; import DateFilter from "./components/DateFilter"; +import DocumentTypeFilter from "./components/DocumentTypeFilter"; import RecentSearches from "./components/RecentSearches"; import SearchInput from "./components/SearchInput"; -import StatusFilter from "./components/StatusFilter"; import UserFilter from "./components/UserFilter"; type Props = { notFound?: boolean }; @@ -55,6 +55,7 @@ function Search(props: Props) { // filters const query = decodeURIComponentSafe(routeMatch.params.term ?? ""); const includeArchived = params.get("includeArchived") === "true"; + const includeDrafts = params.get("includeDrafts") !== "false"; const collectionId = params.get("collectionId") ?? undefined; const userId = params.get("userId") ?? undefined; const dateFilter = (params.get("dateFilter") as TDateFilter) ?? undefined; @@ -64,12 +65,21 @@ function Search(props: Props) { () => ({ query, includeArchived, + includeDrafts, collectionId, userId, dateFilter, titleFilter, }), - [query, includeArchived, collectionId, userId, dateFilter, titleFilter] + [ + query, + includeArchived, + includeDrafts, + collectionId, + userId, + dateFilter, + titleFilter, + ] ); const requestFn = React.useMemo(() => { @@ -109,6 +119,7 @@ function Search(props: Props) { userId?: string | undefined; dateFilter?: TDateFilter; includeArchived?: boolean | undefined; + includeDrafts?: boolean | undefined; titleFilter?: boolean | undefined; }) => { history.replace({ @@ -202,10 +213,11 @@ function Search(props: Props) { {query ? ( <> - - handleFilterChange({ includeArchived }) + includeDrafts={includeDrafts} + onSelect={({ includeArchived, includeDrafts }) => + handleFilterChange({ includeArchived, includeDrafts }) } /> void; +}; + +enum DocumentType { + Published = "published", + Active = "active", + All = "all", +} + +const DocumentTypeFilter = ({ + includeArchived, + includeDrafts, + onSelect, +}: Props) => { + const { t } = useTranslation(); + const options = React.useMemo( + () => [ + { + key: DocumentType.Published, + label: t("Published documents"), + note: t("Documents you have access to, excluding drafts"), + }, + { + key: DocumentType.Active, + label: t("Active documents"), + note: t("Documents you have access to, including drafts"), + }, + { + key: DocumentType.All, + label: t("All documents"), + note: t("Documents you have access to, including drafts and archived"), + }, + ], + [t] + ); + + const getActiveKey = () => { + if (includeArchived && includeDrafts) { + return DocumentType.All; + } + + if (includeDrafts) { + return DocumentType.Active; + } + + return DocumentType.Published; + }; + + const handleSelect = (key: DocumentType) => { + switch (key) { + case DocumentType.Published: + return onSelect({ includeArchived: false, includeDrafts: false }); + case DocumentType.Active: + return onSelect({ includeArchived: false, includeDrafts: true }); + case DocumentType.All: + return onSelect({ includeArchived: true, includeDrafts: true }); + default: + onSelect({ includeArchived: false, includeDrafts: false }); + } + }; + + return ( + + ); +}; + +export default DocumentTypeFilter; diff --git a/app/scenes/Search/components/StatusFilter.tsx b/app/scenes/Search/components/StatusFilter.tsx deleted file mode 100644 index 6d506cf2a..000000000 --- a/app/scenes/Search/components/StatusFilter.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import * as React from "react"; -import { useTranslation } from "react-i18next"; -import FilterOptions from "~/components/FilterOptions"; - -type Props = { - includeArchived?: boolean; - onSelect: (key: boolean) => void; -}; - -const StatusFilter = ({ includeArchived, onSelect }: Props) => { - const { t } = useTranslation(); - const options = React.useMemo( - () => [ - { - key: "", - label: t("Active documents"), - note: t("Documents in collections you are able to access"), - }, - { - key: "true", - label: t("All documents"), - note: t("Include documents that are in the archive"), - }, - ], - [t] - ); - - return ( - onSelect(key === "true")} - defaultLabel={t("Active documents")} - /> - ); -}; - -export default StatusFilter; diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 5536699ea..dd966bdca 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -720,12 +720,15 @@ "Past week": "Past week", "Past month": "Past month", "Past year": "Past year", + "Published documents": "Published documents", + "Documents you have access to, excluding drafts": "Documents you have access to, excluding drafts", + "Active documents": "Active documents", + "Documents you have access to, including drafts": "Documents you have access to, including drafts", + "All documents": "All documents", + "Documents you have access to, including drafts and archived": "Documents you have access to, including drafts and archived", + "Document type": "Document type", "Search Results": "Search Results", "Remove search": "Remove search", - "Active documents": "Active documents", - "Documents in collections you are able to access": "Documents in collections you are able to access", - "All documents": "All documents", - "Include documents that are in the archive": "Include documents that are in the archive", "Any author": "Any author", "Author": "Author", "We were unable to find the page you’re looking for.": "We were unable to find the page you’re looking for.",