From d84744bfab899672a893c64612764b05452b0754 Mon Sep 17 00:00:00 2001 From: Lukasz Ostrowski Date: Wed, 7 Jun 2023 11:09:05 +0200 Subject: [PATCH] Cleanup --- apps/search/app.prod.Dockerfile | 6 +- .../components/ImportProductsToAlgolia.tsx | 4 - .../src/components/useQueryAllProducts.tsx | 81 ------------------- 3 files changed, 1 insertion(+), 90 deletions(-) delete mode 100644 apps/search/src/components/useQueryAllProducts.tsx diff --git a/apps/search/app.prod.Dockerfile b/apps/search/app.prod.Dockerfile index 218e4bc..e2c3733 100644 --- a/apps/search/app.prod.Dockerfile +++ b/apps/search/app.prod.Dockerfile @@ -21,15 +21,13 @@ RUN turbo prune --scope="saleor-app-search" --docker # Add lockfile and package.json's of isolated subworkspace FROM base AS installer -#RUN apk add --no-cache libc6-compat -#RUN apk update + WORKDIR /app RUN yarn global add pnpm@8.2.0 ARG DATABASE_URL ENV DATABASE_URL=${DATABASE_URL} -# First install the dependencies (as they change less often) COPY .gitignore .gitignore COPY --from=builder /app/out/full/ . #COPY --from=builder /app/out/json/ . @@ -38,8 +36,6 @@ COPY --from=builder /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml RUN pnpm install --frozen-lockfile -# Build the project -#COPY --from=builder /app/out/full/ . COPY turbo.json turbo.json RUN pnpm turbo run build:app --filter="saleor-app-search" diff --git a/apps/search/src/components/ImportProductsToAlgolia.tsx b/apps/search/src/components/ImportProductsToAlgolia.tsx index 9844f19..7031045 100644 --- a/apps/search/src/components/ImportProductsToAlgolia.tsx +++ b/apps/search/src/components/ImportProductsToAlgolia.tsx @@ -2,7 +2,6 @@ import { Box, Button, Text } from "@saleor/macaw-ui/next"; import React, { useEffect, useMemo, useState } from "react"; import { AlgoliaSearchProvider } from "../lib/algolia/algoliaSearchProvider"; import { useConfiguration } from "../lib/configuration"; -import { Products } from "./useQueryAllProducts"; import { useAuthenticatedFetch } from "@saleor/app-sdk/app-bridge"; export const ImportProductsToAlgolia = () => { @@ -73,6 +72,3 @@ export const ImportProductsToAlgolia = () => { ); }; - -const countVariants = (products: Products, index: number) => - products.slice(0, index).reduce((acc, p) => acc + (p.variants?.length ?? 0), 0); diff --git a/apps/search/src/components/useQueryAllProducts.tsx b/apps/search/src/components/useQueryAllProducts.tsx deleted file mode 100644 index 340a9b1..0000000 --- a/apps/search/src/components/useQueryAllProducts.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import { useAppBridge } from "@saleor/app-sdk/app-bridge"; -import { useEffect, useState } from "react"; -import { - ChannelsDocument, - ProductsDataForImportDocument, - ProductsDataForImportQuery, -} from "../../generated/graphql"; -import { nextClient } from "../lib/graphql"; - -const PER_PAGE = 100; - -export type Products = NonNullable< - ProductsDataForImportQuery["products"] ->["edges"][number]["node"][]; - -/** - * @deprecated - */ -export const useQueryAllProducts = (paused: boolean) => { - const { appBridgeState } = useAppBridge(); - const saleorApiUrl = appBridgeState?.saleorApiUrl!; - - const [products, setProducts] = useState([]); - - useEffect(() => { - if (paused) { - return; - } - - if (!appBridgeState?.token) { - return; - } - - const token = appBridgeState.token; - const client = nextClient(saleorApiUrl, () => Promise.resolve({ token })); - - if (!client) { - return; - } - - const getChannels = () => client.query(ChannelsDocument, {}).toPromise(); - - const getProducts = async (channelSlug: string, cursor: string): Promise => { - const response = await client - .query(ProductsDataForImportDocument, { - after: cursor, - first: PER_PAGE, - channel: channelSlug!, - }) - .toPromise(); - - const newProducts = response?.data?.products?.edges.map((e) => e.node) ?? []; - - if (newProducts.length > 0) { - setProducts((ps) => [...ps, ...newProducts]); - } - if ( - response?.data?.products?.pageInfo.hasNextPage && - response?.data?.products?.pageInfo.endCursor - ) { - // get next page of products - return getProducts(channelSlug, response.data.products?.pageInfo.endCursor); - } else { - // do nothing - return; - } - }; - - (async () => { - const channels = await getChannels(); - // get all products for each channel - - await channels.data?.channels?.reduce(async (acc, channel) => { - await acc; - await getProducts(channel.slug, ""); - }, Promise.resolve()); - })(); - }, [appBridgeState?.token, saleorApiUrl, paused]); - - return products; -};