display history of indexed jobs

This commit is contained in:
Lukasz Ostrowski 2023-07-03 16:37:55 +02:00
parent f6a98e0e7e
commit 51de258d6e
17 changed files with 658 additions and 190 deletions

View file

@ -17,7 +17,7 @@
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "4.0.0-alpha.61",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/macaw-ui": "^0.7.2",
"@sentry/nextjs": "^7.43.0",

View file

@ -13,7 +13,7 @@
},
"dependencies": {
"@mailchimp/mailchimp_marketing": "^3.0.80",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/macaw-ui": "0.8.0-pre.84",
"@sentry/nextjs": "^7.52.1",

View file

@ -15,7 +15,7 @@
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "4.0.0-alpha.61",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/macaw-ui": "^0.7.2",
"@sentry/nextjs": "^7.39.0",

View file

@ -14,7 +14,7 @@
"dependencies": {
"@hookform/resolvers": "^3.1.0",
"@monaco-editor/react": "^4.4.6",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/apps-ui": "workspace:*",
"@saleor/macaw-ui": "0.8.0-pre.84",

View file

@ -13,7 +13,7 @@
},
"dependencies": {
"@hookform/resolvers": "^3.1.0",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/macaw-ui": "0.8.0-pre.84",
"@sentry/nextjs": "^7.36.0",

View file

@ -14,7 +14,7 @@
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "4.0.0-alpha.61",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/macaw-ui": "^0.7.2",
"@sentry/nextjs": "^7.36.0",

View file

@ -14,7 +14,7 @@
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "4.0.0-alpha.61",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/macaw-ui": "^0.7.2",
"@urql/exchange-auth": "^1.0.0",

View file

@ -14,7 +14,7 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.332.0",
"@hookform/resolvers": "^3.1.0",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/apps-ui": "workspace:*",
"@saleor/macaw-ui": "0.8.0-pre.84",

View file

@ -20,7 +20,7 @@
"dependencies": {
"@hookform/resolvers": "^3.1.0",
"@prisma/client": "^4.15.0",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/apps-ui": "workspace:*",
"@saleor/macaw-ui": "^0.8.0-pre.84",

View file

@ -0,0 +1,52 @@
import React from "react";
import { Prisma } from "@prisma/client";
import { useAuthenticatedFetch } from "@saleor/app-sdk/app-bridge";
import { useQuery } from "react-query";
import { Box, Text } from "@saleor/macaw-ui/next";
const fetchJobs = (fetch: typeof window.fetch) =>
fetch("/api/jobs").then((r: any) => r.json() as Prisma.IndexJob[]);
export const ImportHistory = () => {
const fetch = useAuthenticatedFetch();
const { data } = useQuery<Prisma.IndexJob[]>({
queryFn: () => fetchJobs(fetch),
refetchInterval: 5000,
});
if (!data) {
return null;
}
return (
<Box marginTop={8} as={"table"} width={"100%"}>
<Box as={"thead"}>
<td>
<Text>Job ID</Text>
</td>
<td>
<Text>Created at</Text>
</td>
<td>
<Text>Createdy by</Text>
</td>
<td>
<Text>Status</Text>
</td>
</Box>
{data.map((job) => (
<tr key={job.jobId}>
<td>{job.jobId}</td>
<td>
{Intl.DateTimeFormat(["en"], { timeStyle: "medium", dateStyle: "medium" }).format(
new Date(job.createdAt)
)}
</td>
<td>{job.createdBy}</td>
<td>{job.status}</td>
</tr>
))}
</Box>
);
};

View file

@ -3,6 +3,7 @@ import React, { useEffect, useMemo, useState } from "react";
import { AlgoliaSearchProvider } from "../lib/algolia/algoliaSearchProvider";
import { useConfiguration } from "../lib/configuration";
import { useAuthenticatedFetch } from "@saleor/app-sdk/app-bridge";
import { ImportHistory } from "./ImportHistory";
export const ImportProductsToAlgolia = () => {
const fetch = useAuthenticatedFetch();
@ -48,17 +49,6 @@ export const ImportProductsToAlgolia = () => {
</Text>
<Box display={"flex"} justifyContent={"flex-end"} marginTop={13}>
<Button onClick={() => fetch("/api/index-products")}>Start importing</Button>
<Button
onClick={() =>
fetch("/api/jobs")
.then((r: any) => r.json())
.then((jobs: unknown) => {
console.log(jobs);
})
}
>
Check status
</Button>
</Box>
</Box>
) : (
@ -69,6 +59,7 @@ export const ImportProductsToAlgolia = () => {
<Text>Configure Algolia first</Text>
</Box>
)}
<ImportHistory />
</Box>
);
};

View file

@ -14,7 +14,7 @@ export default createProtectedHandler(
await indexingJobRepository.createPendingJob(ctx.authData.saleorApiUrl, {
jobId: Number(job.id),
createdByEmail: "some-name-todo", // todo add to sdk
createdByEmail: ctx.user.email,
});
return res.status(200).end();

View file

@ -14,7 +14,7 @@
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "4.0.0-alpha.61",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/macaw-ui": "^0.7.2",
"@sentry/nextjs": "^7.30.0",

View file

@ -16,7 +16,7 @@
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "4.0.0-alpha.61",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/apps-ui": "workspace:*",
"@saleor/macaw-ui": "^0.7.2",

View file

@ -15,7 +15,7 @@
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "4.0.0-alpha.61",
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/macaw-ui": "^0.7.2",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",

View file

@ -9,7 +9,7 @@
"typescript": "5.1.3"
},
"devDependencies": {
"@saleor/app-sdk": "0.39.1",
"@saleor/app-sdk": "0.41.0",
"@saleor/macaw-ui": "0.8.0-pre.84",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",

File diff suppressed because it is too large Load diff