From d0980719b438cfd235b40a81d7b40e509b1ccffd Mon Sep 17 00:00:00 2001 From: Pranav2612000 Date: Sat, 17 Feb 2024 21:28:58 +0530 Subject: [PATCH] feat: update document type search ui --- app/scenes/Search/Search.tsx | 26 ++++---- .../Search/components/DocumentTypeFilter.tsx | 66 +++++-------------- app/stores/DocumentsStore.ts | 4 +- shared/i18n/locales/en_US/translation.json | 9 +-- 4 files changed, 36 insertions(+), 69 deletions(-) diff --git a/app/scenes/Search/Search.tsx b/app/scenes/Search/Search.tsx index 283b1d38e0..a138fac4d7 100644 --- a/app/scenes/Search/Search.tsx +++ b/app/scenes/Search/Search.tsx @@ -9,7 +9,10 @@ import breakpoint from "styled-components-breakpoint"; import { v4 as uuidv4 } from "uuid"; import { Pagination } from "@shared/constants"; import { hideScrollbars } from "@shared/styles"; -import { DateFilter as TDateFilter } from "@shared/types"; +import { + DateFilter as TDateFilter, + StatusFilter as TStatusFilter, +} from "@shared/types"; import ArrowKeyNavigation from "~/components/ArrowKeyNavigation"; import DocumentListItem from "~/components/DocumentListItem"; import Empty from "~/components/Empty"; @@ -54,18 +57,18 @@ 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; + const statusFilter = params.getAll("statusFilter")?.length + ? (params.getAll("statusFilter") as TStatusFilter[]) + : [TStatusFilter.Published, TStatusFilter.Draft]; const titleFilter = params.get("titleFilter") === "true"; const filters = React.useMemo( () => ({ query, - includeArchived, - includeDrafts, + statusFilter, collectionId, userId, dateFilter, @@ -73,8 +76,7 @@ function Search(props: Props) { }), [ query, - includeArchived, - includeDrafts, + JSON.stringify(statusFilter), collectionId, userId, dateFilter, @@ -118,8 +120,7 @@ function Search(props: Props) { collectionId?: string | undefined; userId?: string | undefined; dateFilter?: TDateFilter; - includeArchived?: boolean | undefined; - includeDrafts?: boolean | undefined; + statusFilter?: TStatusFilter[]; titleFilter?: boolean | undefined; }) => { history.replace({ @@ -214,10 +215,9 @@ function Search(props: Props) { <> - handleFilterChange({ includeArchived, includeDrafts }) + statusFilter={statusFilter} + onSelect={({ statusFilter }) => + handleFilterChange({ statusFilter }) } /> void; + statusFilter: TStatusFilter[]; + onSelect: (option: { statusFilter: TStatusFilter[] }) => void; }; -enum DocumentType { - Published = "published", - Active = "active", - All = "all", -} - -const DocumentTypeFilter = ({ - includeArchived, - includeDrafts, - onSelect, -}: Props) => { +const DocumentTypeFilter = ({ statusFilter, onSelect }: Props) => { const { t } = useTranslation(); const options = React.useMemo( () => [ { - key: DocumentType.Published, + key: TStatusFilter.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: TStatusFilter.Archived, + label: t("Archived documents"), }, { - key: DocumentType.All, - label: t("All documents"), - note: t("Documents you have access to, including drafts and archived"), + key: TStatusFilter.Draft, + label: t("Draft documents"), }, ], [t] ); - const getActiveKey = () => { - if (includeArchived && includeDrafts) { - return DocumentType.All; + const handleSelect = (key: TStatusFilter) => { + let modifiedStatusFilter; + if (statusFilter.includes(key)) { + modifiedStatusFilter = statusFilter.filter((status) => status !== key); + } else { + modifiedStatusFilter = [...statusFilter, key]; } - 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 }); - } + onSelect({ statusFilter: modifiedStatusFilter }); }; return ( ); }; diff --git a/app/stores/DocumentsStore.ts b/app/stores/DocumentsStore.ts index b296164943..defd956ba5 100644 --- a/app/stores/DocumentsStore.ts +++ b/app/stores/DocumentsStore.ts @@ -10,6 +10,7 @@ import type { JSONObject, NavigationNode, PublicTeam, + StatusFilter, } from "@shared/types"; import { subtractDate } from "@shared/utils/date"; import { bytesToHumanReadable } from "@shared/utils/files"; @@ -36,8 +37,7 @@ export type SearchParams = { offset?: number; limit?: number; dateFilter?: DateFilter; - includeArchived?: boolean; - includeDrafts?: boolean; + statusFilter?: StatusFilter[]; collectionId?: string; userId?: string; shareId?: string; diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index aaff28e2e1..3d161a80a4 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -738,12 +738,9 @@ "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", + "Archived documents": "Archived documents", + "Draft documents": "Draft documents", + "Any status": "Any status", "Search Results": "Search Results", "Remove search": "Remove search", "Any author": "Any author",