From d66935cd19a7ae565849f2f25c393bf74ffc0866 Mon Sep 17 00:00:00 2001 From: Nar Cuenca Date: Wed, 10 May 2023 11:39:49 +0800 Subject: [PATCH 1/3] task: added resource type filter --- .../components/AdvancedSearch.tsx | 57 ++++++++++++++++++- .../ContentSearch/components/config.ts | 9 +++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/shell/components/ContentSearch/components/AdvancedSearch.tsx b/src/shell/components/ContentSearch/components/AdvancedSearch.tsx index 9df7273250..60e12c28d0 100644 --- a/src/shell/components/ContentSearch/components/AdvancedSearch.tsx +++ b/src/shell/components/ContentSearch/components/AdvancedSearch.tsx @@ -32,8 +32,9 @@ import { } from "../../../components/Filters/DateFilter/types"; import { DateFilterModal } from "../../../components/Filters/DateFilter/DateFilterModal"; import { DateRangeFilterModal } from "../../../components/Filters/DateFilter/DateRangeFilterModal"; -import { PRESET_DATES, CUSTOM_DATES } from "./config"; +import { PRESET_DATES, CUSTOM_DATES, RESOURCE_TYPES } from "./config"; +type ResourceType = "content" | "schema" | null; interface User { firstName: string; lastName: string; @@ -44,6 +45,7 @@ export interface SearchData { keyword: string; user: User | null; date: DateFilterValue | null; + resourceType: ResourceType; } interface AdvancedSearch { keyword: string; @@ -66,6 +68,7 @@ export const AdvancedSearch: FC = ({ keyword, onClose }) => { keyword: "", user: null, date: null, + resourceType: null, } ); const isCustomDate = CUSTOM_DATES.map((d) => d.value).includes( @@ -158,7 +161,7 @@ export const AdvancedSearch: FC = ({ keyword, onClose }) => { const handleSearchClicked = () => { const isOnSearchPage = location.pathname === "/search"; - const { keyword, user, date } = searchData; + const { keyword, user, date, resourceType } = searchData; const searchParams = new URLSearchParams(); if (keyword) { @@ -199,6 +202,10 @@ export const AdvancedSearch: FC = ({ keyword, onClose }) => { } } + if (resourceType) { + searchParams.set("resource", resourceType); + } + if (keyword) { onClose(); @@ -312,6 +319,51 @@ export const AdvancedSearch: FC = ({ keyword, onClose }) => { sx={{ height: "40px" }} /> + + + Resource Type + + + + + + Date Modified @@ -387,6 +439,7 @@ export const AdvancedSearch: FC = ({ keyword, onClose }) => { keyword: "", user: null, date: null, + resourceType: null, }); }} > diff --git a/src/shell/components/ContentSearch/components/config.ts b/src/shell/components/ContentSearch/components/config.ts index 01f68a1e97..7187842ac8 100644 --- a/src/shell/components/ContentSearch/components/config.ts +++ b/src/shell/components/ContentSearch/components/config.ts @@ -56,3 +56,12 @@ export const CUSTOM_DATES: CustomDate[] = [ value: "daterange", }, ]; + +interface ResourceType { + content: string; + schema: string; +} +export const RESOURCE_TYPES: ResourceType = { + content: "Content Items", + schema: "Models", +}; From 85d6fa5a284a828d064831549f3060b48bea9d23 Mon Sep 17 00:00:00 2001 From: Nar Cuenca Date: Thu, 11 May 2023 13:56:04 +0800 Subject: [PATCH 2/3] task: updated tooltip text --- .../components/ContentSearch/components/AdvancedSearch.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell/components/ContentSearch/components/AdvancedSearch.tsx b/src/shell/components/ContentSearch/components/AdvancedSearch.tsx index 60e12c28d0..3c5be3856c 100644 --- a/src/shell/components/ContentSearch/components/AdvancedSearch.tsx +++ b/src/shell/components/ContentSearch/components/AdvancedSearch.tsx @@ -324,7 +324,7 @@ export const AdvancedSearch: FC = ({ keyword, onClose }) => { Resource Type Date: Thu, 11 May 2023 14:23:42 +0800 Subject: [PATCH 3/3] task: add resource type filter component in search page --- .../SearchPage/Filters/ResourceTypeFilter.tsx | 71 +++++++++++++++++++ src/shell/views/SearchPage/Filters/index.tsx | 5 ++ 2 files changed, 76 insertions(+) create mode 100644 src/shell/views/SearchPage/Filters/ResourceTypeFilter.tsx diff --git a/src/shell/views/SearchPage/Filters/ResourceTypeFilter.tsx b/src/shell/views/SearchPage/Filters/ResourceTypeFilter.tsx new file mode 100644 index 0000000000..ae79654dc4 --- /dev/null +++ b/src/shell/views/SearchPage/Filters/ResourceTypeFilter.tsx @@ -0,0 +1,71 @@ +import React from "react"; +import { FC, useState } from "react"; +import { Menu, MenuItem } from "@mui/material"; + +import { FilterButton } from "../../../components/Filters"; + +interface ResourceTypeOptions { + content: string; + schema: string; +} +const RESOURCE_TYPE_OPTIONS: ResourceTypeOptions = { + content: "Content Items", + schema: "Models", +}; + +export type ResourceType = "content" | "schema" | ""; +interface ResourceTypeFilter { + onChange: (value: ResourceType | "") => void; + value?: ResourceType; +} +export const ResourceTypeFilter: FC = ({ + onChange, + value, +}) => { + const [anchorRef, setAnchorRef] = useState(null); + + return ( + <> + ] || + "Resource Type" + } + onOpenMenu={(e: React.MouseEvent) => + setAnchorRef(e.currentTarget) + } + onRemoveFilter={() => onChange("")} + /> + setAnchorRef(null)} + PaperProps={{ + sx: { + mt: 1, + }, + }} + > + {Object.entries(RESOURCE_TYPE_OPTIONS).map(([filter, text]) => ( + { + onChange(filter as ResourceType); + setAnchorRef(null); + }} + > + {text} + + ))} + + + ); +}; diff --git a/src/shell/views/SearchPage/Filters/index.tsx b/src/shell/views/SearchPage/Filters/index.tsx index 3fee784dea..2d609ba8f7 100644 --- a/src/shell/views/SearchPage/Filters/index.tsx +++ b/src/shell/views/SearchPage/Filters/index.tsx @@ -10,6 +10,7 @@ import { } from "../../../components/Filters/"; import { useGetUsersQuery } from "../../../services/accounts"; import { DateFilterValue } from "../../../components/Filters/DateFilter"; +import { ResourceTypeFilter, ResourceType } from "./ResourceTypeFilter"; export const Filters = () => { const [params, setParams] = useParams(); @@ -139,6 +140,10 @@ export const Filters = () => { value={(params.get("sort") as FilterValues) || "modified"} onChange={(value) => setParams(value, "sort")} /> + setParams(value, "resource")} + value={(params.get("resource") as ResourceType) || ""} + /> setParams(value, "user")}