From 1b69f02b162a1fcc4560d2a8cc3708915d002ffb Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Wed, 25 Oct 2023 21:05:04 -0300 Subject: [PATCH] fix(StorePage): fix pagination bug where incorrect index and pageSize were passed to getStoreComponents function feat(StorePage): add support for dynamic pagination in StorePage by implementing handleChangePagination function feat(StorePage): add support for resetting filter in StorePage by implementing resetFilter function feat(StorePage): add support for displaying total rows count in StorePage feat(StorePage): add support for displaying loading message while fetching data in StorePage feat(StorePage): add support for displaying error message when there is an error fetching data in StorePage feat(StorePage): add support for displaying search input and search button in StorePage feat(StorePage): add support for filtering components by type in StorePage feat(StorePage): add support for displaying badges for each component type in StorePage feat(StorePage): add support for displaying market card components in StorePage feat(StorePage): add support for displaying paginator component in StorePage feat(StorePage): add support for displaying loading message while fetching data with API key in StorePage fix(types): add storeComponent property to PaginatorComponentType to differentiate between store and other components --- src/frontend/src/pages/StorePage/index.tsx | 225 ++++++++++++--------- src/frontend/src/types/components/index.ts | 1 + 2 files changed, 129 insertions(+), 97 deletions(-) diff --git a/src/frontend/src/pages/StorePage/index.tsx b/src/frontend/src/pages/StorePage/index.tsx index b8ef061fd..65d83d062 100644 --- a/src/frontend/src/pages/StorePage/index.tsx +++ b/src/frontend/src/pages/StorePage/index.tsx @@ -45,20 +45,19 @@ export default function StorePage(): JSX.Element { const [size, setPageSize] = useState(10); const [index, setPageIndex] = useState(1); - function handleChangePagination(pageIndex: number, pageSize: number) {} - useEffect(() => { handleGetComponents(); }, []); const handleGetComponents = () => { setLoading(true); - getStoreComponents(1, 10) + getStoreComponents(index - 1, 10000) .then((res) => { - setSearchData(res); + setSearchData(res.slice(0, 10)); setLoading(false); setErrorApiKey(false); setData(res); + setTotalRowsCount(res.length); }) .catch((err) => { setSearchData([]); @@ -84,6 +83,34 @@ export default function StorePage(): JSX.Element { ); }; + function handleChangePagination(pageIndex: number, pageSize: number) { + setLoading(true); + getStoreComponents(pageIndex, pageSize) + .then((res) => { + setPageIndex(pageIndex); + setPageSize(pageSize); + setSearchData(res); + setLoading(false); + setErrorApiKey(false); + setData(res); + }) + .catch((err) => { + setSearchData([]); + setLoading(false); + setErrorApiKey(true); + setErrorData({ + title: "Error to get components.", + list: [err["response"]["data"]["detail"]], + }); + }); + } + + function resetFilter() { + setPageIndex(1); + setPageSize(10); + handleGetComponents(); + } + const loadingWithApiKey = loading; const renderComponents = !loading; @@ -113,103 +140,108 @@ export default function StorePage(): JSX.Element { Search flows and components from the community. - {renderComponents && ( -
-
-
- Added Only -
-
- { - setInputText(e.target.value); - }} - onKeyDown={(e) => { - if (e.key === "Enter") { - handleSearch(inputText); - } - }} - value={inputText} - /> - -
-
- +
+
+ +
+
+
+ {Array.from(new Set(searchData.map((i) => i.is_component))).map( + (i, idx) => ( + { + filteredCategories.has(i) + ? setFilteredCategories((old) => { + let newFilteredCategories = cloneDeep(old); + newFilteredCategories.delete(i); + return newFilteredCategories; + }) + : setFilteredCategories((old) => { + let newFilteredCategories = cloneDeep(old); + newFilteredCategories.add(i); + return newFilteredCategories; + }); }} + variant="gray" + size="md" + className={cn( + "cursor-pointer border-none", + filteredCategories.has(i) + ? "bg-beta-foreground text-background hover:bg-beta-foreground" + : "" + )} > - Search - -
-
- -
-
-
- {Array.from(new Set(searchData.map((i) => i.is_component))).map( - (i, idx) => ( - { - filteredCategories.has(i) - ? setFilteredCategories((old) => { - let newFilteredCategories = cloneDeep(old); - newFilteredCategories.delete(i); - return newFilteredCategories; - }) - : setFilteredCategories((old) => { - let newFilteredCategories = cloneDeep(old); - newFilteredCategories.add(i); - return newFilteredCategories; - }); - }} - variant="gray" - size="md" - className={cn( - "cursor-pointer border-none", - filteredCategories.has(i) - ? "bg-beta-foreground text-background hover:bg-beta-foreground" - : "" - )} - > - - {i} - - ) - )} -
-
- {searchData - .filter( - (f) => - Array.from(filteredCategories).length === 0 || - filteredCategories.has(f.is_component) - ) - .map((item, idx) => ( - - ))} -
+ + {i} + + ) + )} + + {renderComponents && ( + <> +
+ {searchData + .filter( + (f) => + Array.from(filteredCategories).length === 0 || + filteredCategories.has(f.is_component) + ) + .map((item, idx) => ( + + ))} +
+ + )} + + {totalRowsCount > 0 && !loading && ( +
)} - {loadingWithApiKey && (
Loading...
)} diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 536253771..f444d4b98 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -271,6 +271,7 @@ export type PaginatorComponentType = { rowsCount?: number[]; totalRowsCount: number; paginate: (pageIndex: number, pageSize: number) => void; + storeComponent?: boolean; }; export type ConfirmationModalType = {