From 1d2079b89dbbd8da974209e36c9ceb9389fd7c9c Mon Sep 17 00:00:00 2001 From: Abbie Sims Date: Tue, 12 Nov 2024 15:42:23 +0400 Subject: [PATCH] chore: move store directory and fix lint errors --- .../js/{ => src}/store/components/App/App.tsx | 0 .../components/App/__tests__/App.test.tsx | 0 .../{ => src}/store/components/App/index.ts | 0 .../store/components/Banner/Banner.tsx | 0 .../Banner/__tests__/Banner.test.tsx | 0 .../store/components/Banner/index.ts | 0 .../store/components/Packages/Packages.tsx | 42 ++++++++++++------- .../Packages/__tests__/Packages.test.tsx | 14 ++++--- .../store/components/Packages/index.ts | 0 .../store/components/Topics/Topics.tsx | 0 .../Topics/__tests__/Topics.test.tsx | 6 +-- .../store/components/Topics/index.ts | 0 .../js/{ => src}/store/data/package-types.js | 0 static/js/{ => src}/store/data/platforms.js | 0 static/js/{ => src}/store/index.tsx | 0 static/js/{ => src}/store/types/index.ts | 0 webpack.config.entry.js | 2 +- 17 files changed, 40 insertions(+), 24 deletions(-) rename static/js/{ => src}/store/components/App/App.tsx (100%) rename static/js/{ => src}/store/components/App/__tests__/App.test.tsx (100%) rename static/js/{ => src}/store/components/App/index.ts (100%) rename static/js/{ => src}/store/components/Banner/Banner.tsx (100%) rename static/js/{ => src}/store/components/Banner/__tests__/Banner.test.tsx (100%) rename static/js/{ => src}/store/components/Banner/index.ts (100%) rename static/js/{ => src}/store/components/Packages/Packages.tsx (86%) rename static/js/{ => src}/store/components/Packages/__tests__/Packages.test.tsx (83%) rename static/js/{ => src}/store/components/Packages/index.ts (100%) rename static/js/{ => src}/store/components/Topics/Topics.tsx (100%) rename static/js/{ => src}/store/components/Topics/__tests__/Topics.test.tsx (94%) rename static/js/{ => src}/store/components/Topics/index.ts (100%) rename static/js/{ => src}/store/data/package-types.js (100%) rename static/js/{ => src}/store/data/platforms.js (100%) rename static/js/{ => src}/store/index.tsx (100%) rename static/js/{ => src}/store/types/index.ts (100%) diff --git a/static/js/store/components/App/App.tsx b/static/js/src/store/components/App/App.tsx similarity index 100% rename from static/js/store/components/App/App.tsx rename to static/js/src/store/components/App/App.tsx diff --git a/static/js/store/components/App/__tests__/App.test.tsx b/static/js/src/store/components/App/__tests__/App.test.tsx similarity index 100% rename from static/js/store/components/App/__tests__/App.test.tsx rename to static/js/src/store/components/App/__tests__/App.test.tsx diff --git a/static/js/store/components/App/index.ts b/static/js/src/store/components/App/index.ts similarity index 100% rename from static/js/store/components/App/index.ts rename to static/js/src/store/components/App/index.ts diff --git a/static/js/store/components/Banner/Banner.tsx b/static/js/src/store/components/Banner/Banner.tsx similarity index 100% rename from static/js/store/components/Banner/Banner.tsx rename to static/js/src/store/components/Banner/Banner.tsx diff --git a/static/js/store/components/Banner/__tests__/Banner.test.tsx b/static/js/src/store/components/Banner/__tests__/Banner.test.tsx similarity index 100% rename from static/js/store/components/Banner/__tests__/Banner.test.tsx rename to static/js/src/store/components/Banner/__tests__/Banner.test.tsx diff --git a/static/js/store/components/Banner/index.ts b/static/js/src/store/components/Banner/index.ts similarity index 100% rename from static/js/store/components/Banner/index.ts rename to static/js/src/store/components/Banner/index.ts diff --git a/static/js/store/components/Packages/Packages.tsx b/static/js/src/store/components/Packages/Packages.tsx similarity index 86% rename from static/js/store/components/Packages/Packages.tsx rename to static/js/src/store/components/Packages/Packages.tsx index 6a2e0bc6c..f4b761555 100644 --- a/static/js/store/components/Packages/Packages.tsx +++ b/static/js/src/store/components/Packages/Packages.tsx @@ -20,6 +20,8 @@ import Topics from "../Topics"; import platforms from "../../data/platforms"; import packageTypes from "../../data/package-types"; +import { Category } from "../../types"; +import { Package, Publisher } from "../../../publisher-admin/types"; function Packages() { const ITEMS_PER_PAGE = 12; @@ -27,7 +29,7 @@ function Packages() { const getData = async () => { const response = await fetch(`/store.json${search}`); const data = await response.json(); - const packagesWithId = data.packages.map((item: any) => { + const packagesWithId = data.packages.map((item: string[]) => { return { ...item, id: crypto.randomUUID(), @@ -48,6 +50,8 @@ function Packages() { const [hideFilters, setHideFilters] = useState(true); const currentPage = searchParams.get("page") || "1"; const { data, status, refetch, isFetching } = useQuery("data", getData); + console.log(data); + console.log(typeof data); const topicsQuery = searchParams ? searchParams.get("categories") : null; @@ -110,7 +114,7 @@ function Packages() { selectedCategories={ searchParams.get("categories")?.split(",") || [] } - setSelectedCategories={(items: any) => { + setSelectedCategories={(items: string[]) => { if (items.length > 0) { searchParams.set("categories", items.join(",")); } else { @@ -182,19 +186,27 @@ function Packages() { {!isFetching && status === "success" && data.packages.length > 0 && - data.packages.map((packageData: any) => ( - - {packageData.package.type === "bundle" ? ( - - ) : ( - - )} - - ))} + data.packages.map( + (packageData: { + categories: Category[]; + package: Package; + publisher: Publisher; + ratings: { count: string; value: string }; + id: string; + }) => ( + + {packageData.package.type === "bundle" ? ( + + ) : ( + + )} + + ) + )} {status === "success" && data.packages.length === 0 && (

No packages match this filter

diff --git a/static/js/store/components/Packages/__tests__/Packages.test.tsx b/static/js/src/store/components/Packages/__tests__/Packages.test.tsx similarity index 83% rename from static/js/store/components/Packages/__tests__/Packages.test.tsx rename to static/js/src/store/components/Packages/__tests__/Packages.test.tsx index ab5a15b98..5ca1f4319 100644 --- a/static/js/store/components/Packages/__tests__/Packages.test.tsx +++ b/static/js/src/store/components/Packages/__tests__/Packages.test.tsx @@ -6,13 +6,17 @@ import Packages from "../Packages"; import "@testing-library/jest-dom"; jest.mock("@canonical/store-components", () => ({ - CharmCard: ({ data }: { data: any }) =>
{data.name}
, - BundleCard: ({ data }: { data: any }) =>
{data.name}
, + CharmCard: ({ data }: { data: { name: string } }) =>
{data.name}
, + BundleCard: ({ data }: { data: { name: string } }) =>
{data.name}
, Filters: ({ setSelectedCategories, setSelectedPlatform, setSelectedPackageType, - }: any) => ( + }: { + setSelectedCategories: (categories: string[]) => void; + setSelectedPlatform: (platform: string) => void; + setSelectedPackageType: (packageType: string) => void; + }) => (