Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend/builder): add filters to blocks menu (#11654)

Abhimanyu Yadav103a62c9dae8
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/BlockMenuFilters.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/BlockMenuFilters.tsx
new file mode 100644
index 0000000000..ebcea9eee6
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/BlockMenuFilters.tsx
@@ -0,0 +1,57 @@
+import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore";
+import { FilterChip } from "../FilterChip";
+import { categories } from "./constants";
+import { FilterSheet } from "../FilterSheet/FilterSheet";
+import { GetV2BuilderSearchFilterAnyOfItem } from "@/app/api/__generated__/models/getV2BuilderSearchFilterAnyOfItem";
+
+export const BlockMenuFilters = () => {
+ const {
+ filters,
+ addFilter,
+ removeFilter,
+ categoryCounts,
+ creators,
+ addCreator,
+ removeCreator,
+ } = useBlockMenuStore();
+
+ const handleFilterClick = (filter: GetV2BuilderSearchFilterAnyOfItem) => {
+ if (filters.includes(filter)) {
+ removeFilter(filter);
+ } else {
+ addFilter(filter);
+ }
+ };
+
+ const handleCreatorClick = (creator: string) => {
+ if (creators.includes(creator)) {
+ removeCreator(creator);
+ } else {
+ addCreator(creator);
+ }
+ };
+
+ return (
+ <div className="flex flex-wrap gap-2">
+ <FilterSheet categories={categories} />
+ {creators.length > 0 &&
+ creators.map((creator) => (
+ <FilterChip
+ key={creator}
+ name={"Created by " + creator.slice(0, 10) + "..."}
+ selected={creators.includes(creator)}
+ onClick={() => handleCreatorClick(creator)}
+ />
+ ))}
+ {categories.map((category) => (
+ <FilterChip
+ key={category.key}
+ name={category.name}
+ selected={filters.includes(category.key)}
+ onClick={() => handleFilterClick(category.key)}
+ number={categoryCounts[category.key] ?? 0}
+ />
+ ))}
+ </div>
+ );
+};
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/constants.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/constants.ts
new file mode 100644
index 0000000000..b438aae91b
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/constants.ts
@@ -0,0 +1,15 @@
+import { GetV2BuilderSearchFilterAnyOfItem } from "@/app/api/__generated__/models/getV2BuilderSearchFilterAnyOfItem";
+import { CategoryKey } from "./types";
+
+export const categories: Array<{ key: CategoryKey; name: string }> = [
+ { key: GetV2BuilderSearchFilterAnyOfItem.blocks, name: "Blocks" },
+ {
+ key: GetV2BuilderSearchFilterAnyOfItem.integrations,
+ name: "Integrations",
+ },
+ {
+ key: GetV2BuilderSearchFilterAnyOfItem.marketplace_agents,
+ name: "Marketplace agents",
+ },
+ { key: GetV2BuilderSearchFilterAnyOfItem.my_agents, name: "My agents" },
+];
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/types.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/types.ts
new file mode 100644
index 0000000000..8fec9ef64d
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/types.ts
@@ -0,0 +1,26 @@
+import { GetV2BuilderSearchFilterAnyOfItem } from "@/app/api/__generated__/models/getV2BuilderSearchFilterAnyOfItem";
+
+export type DefaultStateType =
+ | "suggestion"
+ | "all_blocks"
+ | "input_blocks"
+ | "action_blocks"
+ | "output_blocks"
+ | "integrations"
+ | "marketplace_agents"
+ | "my_agents";
+
+export type CategoryKey = GetV2BuilderSearchFilterAnyOfItem;
+
+export interface Filters {
+ categories: {
+ blocks: boolean;
+ integrations: boolean;
+ marketplace_agents: boolean;
+ my_agents: boolean;
+ providers: boolean;
+ };
+ createdBy: string[];
+}
+
+export type CategoryCounts = Record<CategoryKey, number>;
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/BlockMenuSearch.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/BlockMenuSearch.tsx
index de339431e8..26723eebcc 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/BlockMenuSearch.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/BlockMenuSearch.tsx
@@ -1,111 +1,14 @@
import { Text } from "@/components/atoms/Text/Text";
-import { useBlockMenuSearch } from "./useBlockMenuSearch";
-import { InfiniteScroll } from "@/components/contextual/InfiniteScroll/InfiniteScroll";
-import { LoadingSpinner } from "@/components/__legacy__/ui/loading";
-import { SearchResponseItemsItem } from "@/app/api/__generated__/models/searchResponseItemsItem";
-import { MarketplaceAgentBlock } from "../MarketplaceAgentBlock";
-import { Block } from "../Block";
-import { UGCAgentBlock } from "../UGCAgentBlock";
-import { getSearchItemType } from "./helper";
-import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
import { blockMenuContainerStyle } from "../style";
-import { cn } from "@/lib/utils";
-import { NoSearchResult } from "../NoSearchResult";
+import { BlockMenuFilters } from "../BlockMenuFilters/BlockMenuFilters";
+import { BlockMenuSearchContent } from "../BlockMenuSearchContent/BlockMenuSearchContent";
export const BlockMenuSearch = () => {
- const {
- searchResults,
- isFetchingNextPage,
- fetchNextPage,
- hasNextPage,
- searchLoading,
- handleAddLibraryAgent,
- handleAddMarketplaceAgent,
- addingLibraryAgentId,
- addingMarketplaceAgentSlug,
- } = useBlockMenuSearch();
- const { searchQuery } = useBlockMenuStore();
-
- if (searchLoading) {
- return (
- <div
- className={cn(
- blockMenuContainerStyle,
- "flex items-center justify-center",
- )}
- >
- <LoadingSpinner className="size-13" />
- </div>
- );
- }
-
- if (searchResults.length === 0) {
- return <NoSearchResult />;
- }
-
return (
<div className={blockMenuContainerStyle}>
+ <BlockMenuFilters />
<Text variant="body-medium">Search results</Text>
- <InfiniteScroll
- isFetchingNextPage={isFetchingNextPage}
- fetchNextPage={fetchNextPage}
- hasNextPage={hasNextPage}
- loader={<LoadingSpinner className="size-13" />}
- className="space-y-2.5"
- >
- {searchResults.map((item: SearchResponseItemsItem, index: number) => {
- const { type, data } = getSearchItemType(item);
- // backend give support to these 3 types only [right now] - we need to give support to integration and ai agent types in follow up PRs
- switch (type) {
- case "store_agent":
- return (
- <MarketplaceAgentBlock
- key={index}
- slug={data.slug}
- highlightedText={searchQuery}
- title={data.agent_name}
- image_url={data.agent_image}
- creator_name={data.creator}
- number_of_runs={data.runs}
- loading={addingMarketplaceAgentSlug === data.slug}
- onClick={() =>
- handleAddMarketplaceAgent({
- creator_name: data.creator,
- slug: data.slug,
- })
- }
- />
- );
- case "block":
- return (
- <Block
- key={index}
- title={data.name}
- highlightedText={searchQuery}
- description={data.description}
- blockData={data}
- />
- );
-
- case "library_agent":
- return (
- <UGCAgentBlock
- key={index}
- title={data.name}
- highlightedText={searchQuery}
- image_url={data.image_url}
- version={data.graph_version}
- edited_time={data.updated_at}
- isLoading={addingLibraryAgentId === data.id}
- onClick={() => handleAddLibraryAgent(data)}
- />
- );
-
- default:
- return null;
- }
- })}
- </InfiniteScroll>
+ <BlockMenuSearchContent />
</div>
);
};
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/BlockMenuSearchContent.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/BlockMenuSearchContent.tsx
new file mode 100644
index 0000000000..7229c44ed7
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/BlockMenuSearchContent.tsx
@@ -0,0 +1,108 @@
+import { SearchResponseItemsItem } from "@/app/api/__generated__/models/searchResponseItemsItem";
+import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";
+import { InfiniteScroll } from "@/components/contextual/InfiniteScroll/InfiniteScroll";
+import { getSearchItemType } from "./helper";
+import { MarketplaceAgentBlock } from "../MarketplaceAgentBlock";
+import { Block } from "../Block";
+import { UGCAgentBlock } from "../UGCAgentBlock";
+import { useBlockMenuSearchContent } from "./useBlockMenuSearchContent";
+import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore";
+import { cn } from "@/lib/utils";
+import { blockMenuContainerStyle } from "../style";
+import { NoSearchResult } from "../NoSearchResult";
+
+export const BlockMenuSearchContent = () => {
+ const {
+ searchResults,
+ isFetchingNextPage,
+ fetchNextPage,
+ hasNextPage,
+ searchLoading,
+ handleAddLibraryAgent,
+ handleAddMarketplaceAgent,
+ addingLibraryAgentId,
+ addingMarketplaceAgentSlug,
+ } = useBlockMenuSearchContent();
+
+ const { searchQuery } = useBlockMenuStore();
+
+ if (searchLoading) {
+ return (
+ <div
+ className={cn(
+ blockMenuContainerStyle,
+ "flex items-center justify-center",
+ )}
+ >
+ <LoadingSpinner className="size-13" />
+ </div>
+ );
+ }
+
+ if (searchResults.length === 0) {
+ return <NoSearchResult />;
+ }
+
+ return (
+ <InfiniteScroll
+ isFetchingNextPage={isFetchingNextPage}
+ fetchNextPage={fetchNextPage}
+ hasNextPage={hasNextPage}
+ loader={<LoadingSpinner className="size-13" />}
+ className="space-y-2.5"
+ >
+ {searchResults.map((item: SearchResponseItemsItem, index: number) => {
+ const { type, data } = getSearchItemType(item);
+ // backend give support to these 3 types only [right now] - we need to give support to integration and ai agent types in follow up PRs
+ switch (type) {
+ case "store_agent":
+ return (
+ <MarketplaceAgentBlock
+ key={index}
+ slug={data.slug}
+ highlightedText={searchQuery}
+ title={data.agent_name}
+ image_url={data.agent_image}
+ creator_name={data.creator}
+ number_of_runs={data.runs}
+ loading={addingMarketplaceAgentSlug === data.slug}
+ onClick={() =>
+ handleAddMarketplaceAgent({
+ creator_name: data.creator,
+ slug: data.slug,
+ })
+ }
+ />
+ );
+ case "block":
+ return (
+ <Block
+ key={index}
+ title={data.name}
+ highlightedText={searchQuery}
+ description={data.description}
+ blockData={data}
+ />
+ );
+
+ case "library_agent":
+ return (
+ <UGCAgentBlock
+ key={index}
+ title={data.name}
+ highlightedText={searchQuery}
+ image_url={data.image_url}
+ version={data.graph_version}
+ edited_time={data.updated_at}
+ isLoading={addingLibraryAgentId === data.id}
+ onClick={() => handleAddLibraryAgent(data)}
+ />
+ );
+
+ default:
+ return null;
+ }
+ })}
+ </InfiniteScroll>
+ );
+};
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/helper.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/helper.ts
similarity index 100%
rename from autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/helper.ts
rename to autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/helper.ts
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/useBlockMenuSearch.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/useBlockMenuSearchContent.tsx
similarity index 83%
rename from autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/useBlockMenuSearch.ts
rename to autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/useBlockMenuSearchContent.tsx
index beff80a984..9da9cb4cbc 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearch/useBlockMenuSearch.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/useBlockMenuSearchContent.tsx
@@ -23,9 +23,19 @@ import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
import { getQueryClient } from "@/lib/react-query/queryClient";
import { useToast } from "@/components/molecules/Toast/use-toast";
import * as Sentry from "@sentry/nextjs";
+import { GetV2BuilderSearchFilterAnyOfItem } from "@/app/api/__generated__/models/getV2BuilderSearchFilterAnyOfItem";
+
+export const useBlockMenuSearchContent = () => {
+ const {
+ searchQuery,
+ searchId,
+ setSearchId,
+ filters,
+ setCreatorsList,
+ creators,
+ setCategoryCounts,
+ } = useBlockMenuStore();
-export const useBlockMenuSearch = () => {
- const { searchQuery, searchId, setSearchId } = useBlockMenuStore();
const { toast } = useToast();
const { addAgentToBuilder, addLibraryAgentToBuilder } =
useAddAgentToBuilder();
@@ -57,6 +67,8 @@ export const useBlockMenuSearch = () => {
page_size: 8,
search_query: searchQuery,
search_id: searchId,
+ filter: filters.length > 0 ? filters : undefined,
+ by_creator: creators.length > 0 ? creators : undefined,
},
{
query: { getNextPageParam: getPaginationNextPageNumber },
@@ -98,6 +110,26 @@ export const useBlockMenuSearch = () => {
}
}, [searchQueryData, searchId, setSearchId]);
+ // from all the results, we need to get all the unique creators
+ useEffect(() => {
+ if (!searchQueryData?.pages?.length) {
+ return;
+ }
+ const latestData = okData(searchQueryData.pages.at(-1));
+ setCategoryCounts(
+ (latestData?.total_items as Record<
+ GetV2BuilderSearchFilterAnyOfItem,
+ number
+ >) || {
+ blocks: 0,
+ integrations: 0,
+ marketplace_agents: 0,
+ my_agents: 0,
+ },
+ );
+ setCreatorsList(latestData?.items || []);
+ }, [searchQueryData]);
+
useEffect(() => {
if (searchId && !searchQuery) {
resetSearchSession();
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterChip.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterChip.tsx
index 69931958b3..23197ab612 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterChip.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterChip.tsx
@@ -1,7 +1,9 @@
import { Button } from "@/components/__legacy__/ui/button";
import { cn } from "@/lib/utils";
-import { X } from "lucide-react";
-import React, { ButtonHTMLAttributes } from "react";
+import { XIcon } from "@phosphor-icons/react";
+import { AnimatePresence, motion } from "framer-motion";
+
+import React, { ButtonHTMLAttributes, useState } from "react";
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
selected?: boolean;
@@ -16,39 +18,51 @@ export const FilterChip: React.FC<Props> = ({
className,
...rest
}) => {
+ const [isHovered, setIsHovered] = useState(false);
return (
- <Button
- className={cn(
- "group w-fit space-x-1 rounded-[1.5rem] border border-zinc-300 bg-transparent px-[0.625rem] py-[0.375rem] shadow-none transition-transform duration-300 ease-in-out",
- "hover:border-violet-500 hover:bg-transparent focus:ring-0 disabled:cursor-not-allowed",
- selected && "border-0 bg-violet-700 hover:border",
- className,
- )}
- {...rest}
- >
- <span
+ <AnimatePresence mode="wait">
+ <Button
+ onMouseEnter={() => setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
className={cn(
- "font-sans text-sm font-medium leading-[1.375rem] text-zinc-600 group-hover:text-zinc-600 group-disabled:text-zinc-400",
- selected && "text-zinc-50",
+ "group w-fit space-x-1 rounded-[1.5rem] border border-zinc-300 bg-transparent px-[0.625rem] py-[0.375rem] shadow-none",
+ "hover:border-violet-500 hover:bg-transparent focus:ring-0 disabled:cursor-not-allowed",
+ selected && "border-0 bg-violet-700 hover:border",
+ className,
)}
+ {...rest}
>
- {name}
- </span>
- {selected && (
- <>
- <span className="flex h-4 w-4 items-center justify-center rounded-full bg-zinc-50 transition-all duration-300 ease-in-out group-hover:hidden">
- <X
- className="h-3 w-3 rounded-full text-violet-700"
- strokeWidth={2}
- />
- </span>
- {number !== undefined && (
- <span className="hidden h-[1.375rem] items-center rounded-[1.25rem] bg-violet-700 p-[0.375rem] text-zinc-50 transition-all duration-300 ease-in-out animate-in fade-in zoom-in group-hover:flex">
- {number > 100 ? "100+" : number}
- </span>
+ <span
+ className={cn(
+ "font-sans text-sm font-medium leading-[1.375rem] text-zinc-600 group-hover:text-zinc-600 group-disabled:text-zinc-400",
+ selected && "text-zinc-50",
)}
- </>
- )}
- </Button>
+ >
+ {name}
+ </span>
+ {selected && !isHovered && (
+ <motion.span
+ initial={{ opacity: 0.5, scale: 0.5, filter: "blur(20px)" }}
+ animate={{ opacity: 1, scale: 1, filter: "blur(0px)" }}
+ exit={{ opacity: 0.5, scale: 0.5, filter: "blur(20px)" }}
+ transition={{ duration: 0.3, type: "spring", bounce: 0.2 }}
+ className="flex h-4 w-4 items-center justify-center rounded-full bg-zinc-50"
+ >
+ <XIcon size={12} weight="bold" className="text-violet-700" />
+ </motion.span>
+ )}
+ {number !== undefined && isHovered && (
+ <motion.span
+ initial={{ opacity: 0.5, scale: 0.5, filter: "blur(10px)" }}
+ animate={{ opacity: 1, scale: 1, filter: "blur(0px)" }}
+ exit={{ opacity: 0.5, scale: 0.5, filter: "blur(10px)" }}
+ transition={{ duration: 0.3, type: "spring", bounce: 0.2 }}
+ className="flex h-[1.375rem] items-center rounded-[1.25rem] bg-violet-700 p-[0.375rem] text-zinc-50"
+ >
+ {number > 100 ? "100+" : number}
+ </motion.span>
+ )}
+ </Button>
+ </AnimatePresence>
);
};
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/FilterSheet.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/FilterSheet.tsx
new file mode 100644
index 0000000000..dc7c428245
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/FilterSheet.tsx
@@ -0,0 +1,156 @@
+import { FilterChip } from "../FilterChip";
+import { cn } from "@/lib/utils";
+import { CategoryKey } from "../BlockMenuFilters/types";
+import { AnimatePresence, motion } from "framer-motion";
+import { XIcon } from "@phosphor-icons/react";
+import { Button } from "@/components/atoms/Button/Button";
+import { Text } from "@/components/atoms/Text/Text";
+import { Separator } from "@/components/__legacy__/ui/separator";
+import { Checkbox } from "@/components/__legacy__/ui/checkbox";
+import { useFilterSheet } from "./useFilterSheet";
+import { INITIAL_CREATORS_TO_SHOW } from "./constant";
+
+export function FilterSheet({
+ categories,
+}: {
+ categories: Array<{ key: CategoryKey; name: string }>;
+}) {
+ const {
+ isOpen,
+ localCategories,
+ localCreators,
+ displayedCreatorsCount,
+ handleLocalCategoryChange,
+ handleToggleShowMoreCreators,
+ handleLocalCreatorChange,
+ handleClearFilters,
+ handleCloseButton,
+ handleApplyFilters,
+ hasLocalActiveFilters,
+ visibleCreators,
+ creators,
+ handleOpenFilters,
+ hasActiveFilters,
+ } = useFilterSheet();
+
+ return (
+ <div className="m-0 inline w-fit p-0">
+ <FilterChip
+ name={hasActiveFilters() ? "Edit filters" : "All filters"}
+ onClick={handleOpenFilters}
+ />
+
+ <AnimatePresence>
+ {isOpen && (
+ <motion.div
+ className={cn(
+ "absolute bottom-2 left-2 top-2 z-20 w-3/4 max-w-[22.5rem] space-y-4 overflow-hidden rounded-[0.75rem] bg-white pb-4 shadow-[0_4px_12px_2px_rgba(0,0,0,0.1)]",
+ )}
+ initial={{ x: "-100%", filter: "blur(10px)" }}
+ animate={{ x: 0, filter: "blur(0px)" }}
+ exit={{ x: "-110%", filter: "blur(10px)" }}
+ transition={{ duration: 0.4, type: "spring", bounce: 0.2 }}
+ >
+ {/* Top section */}
+ <div className="flex items-center justify-between px-5 pt-4">
+ <Text variant="body">Filters</Text>
+ <Button
+ className="p-0"
+ variant="ghost"
+ size="icon"
+ onClick={handleCloseButton}
+ >
+ <XIcon size={20} />
+ </Button>
+ </div>
+
+ <Separator className="h-[1px] w-full text-zinc-300" />
+
+ {/* Category section */}
+ <div className="space-y-4 px-5">
+ <Text variant="large">Categories</Text>
+ <div className="space-y-2">
+ {categories.map((category) => (
+ <div
+ key={category.key}
+ className="flex items-center space-x-2"
+ >
+ <Checkbox
+ id={category.key}
+ checked={localCategories.includes(category.key)}
+ onCheckedChange={() =>
+ handleLocalCategoryChange(category.key)
+ }
+ className="border border-[#D4D4D4] shadow-none data-[state=checked]:border-none data-[state=checked]:bg-violet-700 data-[state=checked]:text-white"
+ />
+ <label
+ htmlFor={category.key}
+ className="font-sans text-sm leading-[1.375rem] text-zinc-600"
+ >
+ {category.name}
+ </label>
+ </div>
+ ))}
+ </div>
+ </div>
+
+ {/* Created by section */}
+ <div className="space-y-4 px-5">
+ <p className="font-sans text-base font-medium text-zinc-800">
+ Created by
+ </p>
+ <div className="space-y-2">
+ {visibleCreators.map((creator, i) => (
+ <div key={i} className="flex items-center space-x-2">
+ <Checkbox
+ id={`creator-${creator}`}
+ checked={localCreators.includes(creator)}
+ onCheckedChange={() => handleLocalCreatorChange(creator)}
+ className="border border-[#D4D4D4] shadow-none data-[state=checked]:border-none data-[state=checked]:bg-violet-700 data-[state=checked]:text-white"
+ />
+ <label
+ htmlFor={`creator-${creator}`}
+ className="font-sans text-sm leading-[1.375rem] text-zinc-600"
+ >
+ {creator}
+ </label>
+ </div>
+ ))}
+ </div>
+ {creators.length > INITIAL_CREATORS_TO_SHOW && (
+ <Button
+ variant={"link"}
+ className="m-0 p-0 font-sans text-sm font-medium leading-[1.375rem] text-zinc-800 underline hover:text-zinc-600"
+ onClick={handleToggleShowMoreCreators}
+ >
+ {displayedCreatorsCount < creators.length ? "More" : "Less"}
+ </Button>
+ )}
+ </div>
+
+ {/* Footer section */}
+ <div className="fixed bottom-0 flex w-full justify-between gap-3 border-t border-zinc-200 bg-white px-5 py-3">
+ <Button
+ size="small"
+ variant={"outline"}
+ onClick={handleClearFilters}
+ className="rounded-[8px] px-2 py-1.5"
+ >
+ Clear
+ </Button>
+
+ <Button
+ size="small"
+ onClick={handleApplyFilters}
+ disabled={!hasLocalActiveFilters()}
+ className="rounded-[8px] px-2 py-1.5"
+ >
+ Apply filters
+ </Button>
+ </div>
+ </motion.div>
+ )}
+ </AnimatePresence>
+ </div>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/constant.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/constant.ts
new file mode 100644
index 0000000000..8e05dc1037
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/constant.ts
@@ -0,0 +1 @@
+export const INITIAL_CREATORS_TO_SHOW = 5;
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/useFilterSheet.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/useFilterSheet.ts
new file mode 100644
index 0000000000..200671f4e7
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/useFilterSheet.ts
@@ -0,0 +1,100 @@
+import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore";
+import { useState } from "react";
+import { INITIAL_CREATORS_TO_SHOW } from "./constant";
+import { GetV2BuilderSearchFilterAnyOfItem } from "@/app/api/__generated__/models/getV2BuilderSearchFilterAnyOfItem";
+
+export const useFilterSheet = () => {
+ const { filters, creators_list, creators, setFilters, setCreators } =
+ useBlockMenuStore();
+
+ const [isOpen, setIsOpen] = useState(false);
+ const [localCategories, setLocalCategories] =
+ useState<GetV2BuilderSearchFilterAnyOfItem[]>(filters);
+ const [localCreators, setLocalCreators] = useState<string[]>(creators);
+ const [displayedCreatorsCount, setDisplayedCreatorsCount] = useState(
+ INITIAL_CREATORS_TO_SHOW,
+ );
+
+ const handleLocalCategoryChange = (
+ category: GetV2BuilderSearchFilterAnyOfItem,
+ ) => {
+ setLocalCategories((prev) => {
+ if (prev.includes(category)) {
+ return prev.filter((c) => c !== category);
+ }
+ return [...prev, category];
+ });
+ };
+
+ const hasActiveFilters = () => {
+ return filters.length > 0 || creators.length > 0;
+ };
+
+ const handleToggleShowMoreCreators = () => {
+ if (displayedCreatorsCount < creators.length) {
+ setDisplayedCreatorsCount(creators.length);
+ } else {
+ setDisplayedCreatorsCount(INITIAL_CREATORS_TO_SHOW);
+ }
+ };
+
+ const handleLocalCreatorChange = (creator: string) => {
+ setLocalCreators((prev) => {
+ if (prev.includes(creator)) {
+ return prev.filter((c) => c !== creator);
+ }
+ return [...prev, creator];
+ });
+ };
+
+ const handleClearFilters = () => {
+ setLocalCategories([]);
+ setLocalCreators([]);
+ setDisplayedCreatorsCount(INITIAL_CREATORS_TO_SHOW);
+ };
+
+ const handleCloseButton = () => {
+ setIsOpen(false);
+ setLocalCategories(filters);
+ setLocalCreators(creators);
+ setDisplayedCreatorsCount(INITIAL_CREATORS_TO_SHOW);
+ };
+
+ const handleApplyFilters = () => {
+ setFilters(localCategories);
+ setCreators(localCreators);
+ setIsOpen(false);
+ };
+
+ const handleOpenFilters = () => {
+ setIsOpen(true);
+ setLocalCategories(filters);
+ setLocalCreators(creators);
+ };
+
+ const hasLocalActiveFilters = () => {
+ return localCategories.length > 0 || localCreators.length > 0;
+ };
+
+ const visibleCreators = creators_list.slice(0, displayedCreatorsCount);
+
+ return {
+ creators,
+ isOpen,
+ setIsOpen,
+ localCategories,
+ localCreators,
+ displayedCreatorsCount,
+ setDisplayedCreatorsCount,
+ handleLocalCategoryChange,
+ handleToggleShowMoreCreators,
+ handleLocalCreatorChange,
+ handleClearFilters,
+ handleCloseButton,
+ handleOpenFilters,
+ handleApplyFilters,
+ hasLocalActiveFilters,
+ visibleCreators,
+ hasActiveFilters,
+ };
+};
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/stores/blockMenuStore.ts b/autogpt_platform/frontend/src/app/(platform)/build/stores/blockMenuStore.ts
index ea50a03979..31b9eda338 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/stores/blockMenuStore.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/stores/blockMenuStore.ts
@@ -1,12 +1,30 @@
import { create } from "zustand";
import { DefaultStateType } from "../components/NewControlPanel/NewBlockMenu/types";
+import { SearchResponseItemsItem } from "@/app/api/__generated__/models/searchResponseItemsItem";
+import { getSearchItemType } from "../components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/helper";
+import { StoreAgent } from "@/app/api/__generated__/models/storeAgent";
+import { GetV2BuilderSearchFilterAnyOfItem } from "@/app/api/__generated__/models/getV2BuilderSearchFilterAnyOfItem";
type BlockMenuStore = {
searchQuery: string;
searchId: string | undefined;
defaultState: DefaultStateType;
integration: string | undefined;
+ filters: GetV2BuilderSearchFilterAnyOfItem[];
+ creators: string[];
+ creators_list: string[];
+ categoryCounts: Record<GetV2BuilderSearchFilterAnyOfItem, number>;
+ setCategoryCounts: (
+ counts: Record<GetV2BuilderSearchFilterAnyOfItem, number>,
+ ) => void;
+ setCreatorsList: (searchData: SearchResponseItemsItem[]) => void;
+ addCreator: (creator: string) => void;
+ setCreators: (creators: string[]) => void;
+ removeCreator: (creator: string) => void;
+ addFilter: (filter: GetV2BuilderSearchFilterAnyOfItem) => void;
+ setFilters: (filters: GetV2BuilderSearchFilterAnyOfItem[]) => void;
+ removeFilter: (filter: GetV2BuilderSearchFilterAnyOfItem) => void;
setSearchQuery: (query: string) => void;
setSearchId: (id: string | undefined) => void;
setDefaultState: (state: DefaultStateType) => void;
@@ -19,11 +37,44 @@ export const useBlockMenuStore = create<BlockMenuStore>((set) => ({
searchId: undefined,
defaultState: DefaultStateType.SUGGESTION,
integration: undefined,
+ filters: [],
+ creators: [], // creator filters that are applied to the search results
+ creators_list: [], // all creators that are available to filter by
+ categoryCounts: {
+ blocks: 0,
+ integrations: 0,
+ marketplace_agents: 0,
+ my_agents: 0,
+ },
+ setCategoryCounts: (counts) => set({ categoryCounts: counts }),
+ setCreatorsList: (searchData) => {
+ const marketplaceAgents = searchData.filter((item) => {
+ return getSearchItemType(item).type === "store_agent";
+ }) as StoreAgent[];
+
+ const newCreators = marketplaceAgents.map((agent) => agent.creator);
+
+ set((state) => ({
+ creators_list: Array.from(
+ new Set([...state.creators_list, ...newCreators]),
+ ),
+ }));
+ },
+ setCreators: (creators) => set({ creators }),
+ setFilters: (filters) => set({ filters }),
setSearchQuery: (query) => set({ searchQuery: query }),
setSearchId: (id) => set({ searchId: id }),
setDefaultState: (state) => set({ defaultState: state }),
setIntegration: (integration) => set({ integration }),
+ addFilter: (filter) =>
+ set((state) => ({ filters: [...state.filters, filter] })),
+ removeFilter: (filter) =>
+ set((state) => ({ filters: state.filters.filter((f) => f !== filter) })),
+ addCreator: (creator) =>
+ set((state) => ({ creators: [...state.creators, creator] })),
+ removeCreator: (creator) =>
+ set((state) => ({ creators: state.creators.filter((c) => c !== creator) })),
reset: () =>
set({
searchQuery: "",
diff --git a/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts b/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts
index 315b68ab87..4578ac03fe 100644
--- a/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts
+++ b/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts
@@ -41,11 +41,9 @@ export const customMutator = async <
T extends { data: any; status: number; headers: Headers },
>(
url: string,
- options: RequestInit & {
- params?: any;
- } = {},
+ options: RequestInit,
): Promise<T> => {
- const { params, ...requestOptions } = options;
+ const requestOptions = options;
const method = (requestOptions.method || "GET") as
| "GET"
| "POST"
@@ -87,14 +85,11 @@ export const customMutator = async <
headers["Content-Type"] = "application/json";
}
- const queryString = params
- ? "?" + new URLSearchParams(params).toString()
- : "";
-
const baseUrl = getBaseUrl();
// The caching in React Query in our system depends on the url, so the base_url could be different for the server and client sides.
- const fullUrl = `${baseUrl}${url}${queryString}`;
+ // here url also contains encoded query params
+ const fullUrl = `${baseUrl}${url}`;
if (environment.isServerSide()) {
try {