Cleanup
This commit is contained in:
parent
7240f6efa7
commit
d84744bfab
3 changed files with 1 additions and 90 deletions
|
@ -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"
|
||||
|
|
|
@ -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 = () => {
|
|||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
const countVariants = (products: Products, index: number) =>
|
||||
products.slice(0, index).reduce((acc, p) => acc + (p.variants?.length ?? 0), 0);
|
||||
|
|
|
@ -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<Products>([]);
|
||||
|
||||
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<void> => {
|
||||
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;
|
||||
};
|
Loading…
Reference in a new issue