From aa5b7e6e516934a1e1f72f2b2ffe246a7f88650a Mon Sep 17 00:00:00 2001 From: JORGE Date: Wed, 11 Dec 2024 17:59:57 -0400 Subject: [PATCH 01/24] [TM-1531] add job service url and script --- openapi-codegen.config.ts | 20 +- package.json | 1 + .../v3/jobService/jobServiceComponents.ts | 203 ++++++++++++++++++ .../v3/jobService/jobServiceFetcher.ts | 96 +++++++++ .../v3/jobService/jobServicePredicates.ts | 26 +++ .../v3/jobService/jobServiceSchemas.ts | 71 ++++++ 6 files changed, 411 insertions(+), 6 deletions(-) create mode 100644 src/generated/v3/jobService/jobServiceComponents.ts create mode 100644 src/generated/v3/jobService/jobServiceFetcher.ts create mode 100644 src/generated/v3/jobService/jobServicePredicates.ts create mode 100644 src/generated/v3/jobService/jobServiceSchemas.ts diff --git a/openapi-codegen.config.ts b/openapi-codegen.config.ts index 9d6e54a2f..66736957c 100644 --- a/openapi-codegen.config.ts +++ b/openapi-codegen.config.ts @@ -27,28 +27,34 @@ type EnvironmentName = (typeof ENVIRONMENT_NAMES)[number]; type Environment = { apiBaseUrl: string; userServiceUrl: string; + jobServiceUrl: string; }; const ENVIRONMENTS: { [Property in EnvironmentName]: Environment } = { local: { apiBaseUrl: "http://localhost:8080", - userServiceUrl: "http://localhost:4010" + userServiceUrl: "http://localhost:4010", + jobServiceUrl: "http://localhost:4020" }, dev: { apiBaseUrl: "https://api-dev.terramatch.org", - userServiceUrl: "https://api-dev.terramatch.org" + userServiceUrl: "https://api-dev.terramatch.org", + jobServiceUrl: "https://api-dev.terramatch.org" }, test: { apiBaseUrl: "https://api-test.terramatch.org", - userServiceUrl: "https://api-test.terramatch.org" + userServiceUrl: "https://api-test.terramatch.org", + jobServiceUrl: "https://api-test.terramatch.org" }, staging: { apiBaseUrl: "https://api-staging.terramatch.org", - userServiceUrl: "https://api-staging.terramatch.org" + userServiceUrl: "https://api-staging.terramatch.org", + jobServiceUrl: "https://api-staging.terramatch.org" }, prod: { apiBaseUrl: "https://api.terramatch.org", - userServiceUrl: "https://api.terramatch.org" + userServiceUrl: "https://api.terramatch.org", + jobServiceUrl: "https://api.terramatch.org" } }; @@ -60,13 +66,15 @@ if (!ENVIRONMENT_NAMES.includes(declaredEnv as EnvironmentName)) { const DEFAULTS = ENVIRONMENTS[declaredEnv]; const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL ?? DEFAULTS.apiBaseUrl; const userServiceUrl = process.env.NEXT_PUBLIC_USER_SERVICE_URL ?? DEFAULTS.userServiceUrl; +const jobServiceUrl = process.env.NEXT_PUBLIC_JOB_SERVICE_URL ?? DEFAULTS.jobServiceUrl; // The services defined in the v3 Node BE codebase. Although the URL path for APIs in the v3 space // are namespaced by feature set rather than service (a service may contain multiple namespaces), we // isolate the generated API integration by service to make it easier for a developer to find where // the associated BE code is for a given FE API integration. const SERVICES = { - "user-service": userServiceUrl + "user-service": userServiceUrl, + "job-service": jobServiceUrl }; const config: Record = { diff --git a/package.json b/package.json index a61cc42ed..b8bcf0a3d 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "storybook": "storybook dev -p 6006", "build-storybook": "storybook build", "generate:api": "openapi-codegen gen api", + "generate:jobService": "openapi-codegen gen jobService", "generate:userService": "openapi-codegen gen userService", "generate:services": "npm run generate:userService", "tx:push": "eval $(grep '^TRANSIFEX_TOKEN' .env) && eval $(grep '^TRANSIFEX_SECRET' .env) && txjs-cli push --key-generator=hash src/ --token=$TRANSIFEX_TOKEN --secret=$TRANSIFEX_SECRET", diff --git a/src/generated/v3/jobService/jobServiceComponents.ts b/src/generated/v3/jobService/jobServiceComponents.ts new file mode 100644 index 000000000..5eef6bc8c --- /dev/null +++ b/src/generated/v3/jobService/jobServiceComponents.ts @@ -0,0 +1,203 @@ +/** + * Generated by @openapi-codegen + * + * @version 1.0 + */ +import type * as Fetcher from "./jobServiceFetcher"; +import { jobServiceFetch } from "./jobServiceFetcher"; +import type * as Schemas from "./jobServiceSchemas"; + +export type ListDelayedJobsError = Fetcher.ErrorWrapper<{ + status: 401; + payload: { + /** + * @example 401 + */ + statusCode: number; + /** + * @example Unauthorized + */ + message: string; + /** + * @example Unauthorized + */ + error?: string; + }; +}>; + +export type ListDelayedJobsResponse = { + data?: { + /** + * @example delayedJobs + */ + type?: string; + /** + * @format uuid + */ + id?: string; + attributes?: Schemas.DelayedJobDto; + }; +}; + +/** + * Retrieve a list of all delayed jobs. + */ +export const listDelayedJobs = (signal?: AbortSignal) => + jobServiceFetch({ + url: "/jobs/v3/delayedJobs", + method: "get", + signal + }); + +export type DelayedJobsFindPathParams = { + uuid: string; +}; + +export type DelayedJobsFindError = Fetcher.ErrorWrapper< + | { + status: 401; + payload: { + /** + * @example 401 + */ + statusCode: number; + /** + * @example Unauthorized + */ + message: string; + /** + * @example Unauthorized + */ + error?: string; + }; + } + | { + status: 404; + payload: { + /** + * @example 404 + */ + statusCode: number; + /** + * @example Not Found + */ + message: string; + /** + * @example Not Found + */ + error?: string; + }; + } +>; + +export type DelayedJobsFindResponse = { + data?: { + /** + * @example delayedJobs + */ + type?: string; + /** + * @format uuid + */ + id?: string; + attributes?: Schemas.DelayedJobDto; + }; +}; + +export type DelayedJobsFindVariables = { + pathParams: DelayedJobsFindPathParams; +}; + +/** + * Get the current status and potentially payload or error from a delayed job. + */ +export const delayedJobsFind = (variables: DelayedJobsFindVariables, signal?: AbortSignal) => + jobServiceFetch({ + url: "/jobs/v3/delayedJobs/{uuid}", + method: "get", + ...variables, + signal + }); + +export type BulkClearJobsError = Fetcher.ErrorWrapper< + | { + status: 400; + payload: { + /** + * @example 400 + */ + statusCode: number; + /** + * @example Bad Request + */ + message: string; + /** + * @example Bad Request + */ + error?: string; + }; + } + | { + status: 401; + payload: { + /** + * @example 401 + */ + statusCode: number; + /** + * @example Unauthorized + */ + message: string; + /** + * @example Unauthorized + */ + error?: string; + }; + } + | { + status: 404; + payload: { + /** + * @example 404 + */ + statusCode: number; + /** + * @example Not Found + */ + message: string; + /** + * @example Not Found + */ + error?: string; + }; + } +>; + +export type BulkClearJobsResponse = { + data?: { + /** + * @example delayedJobs + */ + type?: string; + /** + * @format uuid + */ + id?: string; + attributes?: Schemas.DelayedJobDto; + }; +}; + +export type BulkClearJobsVariables = { + body: Schemas.DelayedJobBulkUpdateBodyDto; +}; + +/** + * Accepts a JSON:API-compliant payload to bulk update jobs, allowing each job's isAcknowledged attribute to be set to true or false. + */ +export const bulkClearJobs = (variables: BulkClearJobsVariables, signal?: AbortSignal) => + jobServiceFetch({ + url: "/jobs/v3/delayedJobs/bulk-clear", + method: "patch", + ...variables, + signal + }); diff --git a/src/generated/v3/jobService/jobServiceFetcher.ts b/src/generated/v3/jobService/jobServiceFetcher.ts new file mode 100644 index 000000000..83ccd35dd --- /dev/null +++ b/src/generated/v3/jobService/jobServiceFetcher.ts @@ -0,0 +1,96 @@ +export type JobServiceFetcherExtraProps = { + /** + * You can add some extra props to your generated fetchers. + * + * Note: You need to re-gen after adding the first property to + * have the `JobServiceFetcherExtraProps` injected in `JobServiceComponents.ts` + **/ +}; + +const baseUrl = ""; // TODO add your baseUrl + +export type ErrorWrapper = TError | { status: "unknown"; payload: string }; + +export type JobServiceFetcherOptions = { + url: string; + method: string; + body?: TBody; + headers?: THeaders; + queryParams?: TQueryParams; + pathParams?: TPathParams; + signal?: AbortSignal; +} & JobServiceFetcherExtraProps; + +export async function jobServiceFetch< + TData, + TError, + TBody extends {} | FormData | undefined | null, + THeaders extends {}, + TQueryParams extends {}, + TPathParams extends {} +>({ + url, + method, + body, + headers, + pathParams, + queryParams, + signal +}: JobServiceFetcherOptions): Promise { + try { + const requestHeaders: HeadersInit = { + "Content-Type": "application/json", + ...headers + }; + + /** + * As the fetch API is being used, when multipart/form-data is specified + * the Content-Type header must be deleted so that the browser can set + * the correct boundary. + * https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects#sending_files_using_a_formdata_object + */ + if (requestHeaders["Content-Type"].toLowerCase().includes("multipart/form-data")) { + delete requestHeaders["Content-Type"]; + } + + const response = await window.fetch(`${baseUrl}${resolveUrl(url, queryParams, pathParams)}`, { + signal, + method: method.toUpperCase(), + body: body ? (body instanceof FormData ? body : JSON.stringify(body)) : undefined, + headers: requestHeaders + }); + if (!response.ok) { + let error: ErrorWrapper; + try { + error = await response.json(); + } catch (e) { + error = { + status: "unknown" as const, + payload: e instanceof Error ? `Unexpected error (${e.message})` : "Unexpected error" + }; + } + + throw error; + } + + if (response.headers.get("content-type")?.includes("json")) { + return await response.json(); + } else { + // if it is not a json response, assume it is a blob and cast it to TData + return (await response.blob()) as unknown as TData; + } + } catch (e) { + let errorObject: Error = { + name: "unknown" as const, + message: e instanceof Error ? `Network error (${e.message})` : "Network error", + stack: e as string + }; + throw errorObject; + } +} + +const resolveUrl = (url: string, queryParams: Record = {}, pathParams: Record = {}) => { + let query = new URLSearchParams(queryParams).toString(); + if (query) query = `?${query}`; + return url.replace(/\{\w*\}/g, key => pathParams[key.slice(1, -1)]) + query; +}; diff --git a/src/generated/v3/jobService/jobServicePredicates.ts b/src/generated/v3/jobService/jobServicePredicates.ts new file mode 100644 index 000000000..2c10040e5 --- /dev/null +++ b/src/generated/v3/jobService/jobServicePredicates.ts @@ -0,0 +1,26 @@ +import { isFetching, fetchFailed } from "../utils"; +import { ApiDataStore } from "@/store/apiSlice"; +import { DelayedJobsFindPathParams, DelayedJobsFindVariables } from "./jobServiceComponents"; + +export const listDelayedJobsIsFetching = (store: ApiDataStore) => + isFetching<{}, {}>({ store, url: "/jobs/v3/delayedJobs", method: "get" }); + +export const listDelayedJobsFetchFailed = (store: ApiDataStore) => + fetchFailed<{}, {}>({ store, url: "/jobs/v3/delayedJobs", method: "get" }); + +export const delayedJobsFindIsFetching = (variables: DelayedJobsFindVariables) => (store: ApiDataStore) => + isFetching<{}, DelayedJobsFindPathParams>({ store, url: "/jobs/v3/delayedJobs/{uuid}", method: "get", ...variables }); + +export const delayedJobsFindFetchFailed = (variables: DelayedJobsFindVariables) => (store: ApiDataStore) => + fetchFailed<{}, DelayedJobsFindPathParams>({ + store, + url: "/jobs/v3/delayedJobs/{uuid}", + method: "get", + ...variables + }); + +export const bulkClearJobsIsFetching = (store: ApiDataStore) => + isFetching<{}, {}>({ store, url: "/jobs/v3/delayedJobs/bulk-clear", method: "patch" }); + +export const bulkClearJobsFetchFailed = (store: ApiDataStore) => + fetchFailed<{}, {}>({ store, url: "/jobs/v3/delayedJobs/bulk-clear", method: "patch" }); diff --git a/src/generated/v3/jobService/jobServiceSchemas.ts b/src/generated/v3/jobService/jobServiceSchemas.ts new file mode 100644 index 000000000..2261e5426 --- /dev/null +++ b/src/generated/v3/jobService/jobServiceSchemas.ts @@ -0,0 +1,71 @@ +/** + * Generated by @openapi-codegen + * + * @version 1.0 + */ +export type DelayedJobDto = { + /** + * The current status of the job. If the status is not pending, the payload and statusCode will be provided. + */ + status: "pending" | "failed" | "succeeded"; + /** + * If the job is out of pending state, this is the HTTP status code for the completed process + */ + statusCode: number | null; + /** + * If the job is out of pending state, this is the JSON payload for the completed process + */ + payload: Record | null; + /** + * If the job is in progress, this is the total content to process + */ + totalContent: number | null; + /** + * If the job is in progress, this is the total content processed + */ + processedContent: number | null; + /** + * If the job is in progress, this is the progress message + */ + progressMessage: string | null; + /** + * Indicates whether the jobs have been cleared + */ + isAcknowledged: boolean | null; +}; + +export type DelayedJobAttributes = { + /** + * Value to set for isAcknowledged + * + * @example true + */ + isAcknowledged: boolean; +}; + +export type DelayedJobData = { + /** + * Type of the resource + * + * @example delayedJobs + */ + type: "delayedJobs"; + /** + * UUID of the job + * + * @format uuid + * @example uuid-1 + */ + uuid: string; + /** + * Attributes to update for the job + */ + attributes: DelayedJobAttributes; +}; + +export type DelayedJobBulkUpdateBodyDto = { + /** + * List of jobs to update isAcknowledged + */ + data: DelayedJobData[]; +}; From 153050a0a4d82e813aa6bf425c698745baa011df Mon Sep 17 00:00:00 2001 From: JORGE Date: Thu, 12 Dec 2024 11:57:45 -0400 Subject: [PATCH 02/24] [TM-1531] apiSlice add job resource --- package.json | 2 +- .../v3/jobService/jobServiceFetcher.ts | 100 +----------------- src/store/apiSlice.ts | 4 +- 3 files changed, 9 insertions(+), 97 deletions(-) diff --git a/package.json b/package.json index b8bcf0a3d..602dceae6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "generate:api": "openapi-codegen gen api", "generate:jobService": "openapi-codegen gen jobService", "generate:userService": "openapi-codegen gen userService", - "generate:services": "npm run generate:userService", + "generate:services": "yarn generate:userService && yarn generate:jobService", "tx:push": "eval $(grep '^TRANSIFEX_TOKEN' .env) && eval $(grep '^TRANSIFEX_SECRET' .env) && txjs-cli push --key-generator=hash src/ --token=$TRANSIFEX_TOKEN --secret=$TRANSIFEX_SECRET", "tx:pull": "eval $(grep '^TRANSIFEX_TOKEN' .env) && eval $(grep '^TRANSIFEX_SECRET' .env) && txjs-cli pull --token=$TRANSIFEX_TOKEN --secret=$TRANSIFEX_SECRET" }, diff --git a/src/generated/v3/jobService/jobServiceFetcher.ts b/src/generated/v3/jobService/jobServiceFetcher.ts index 83ccd35dd..97ea202d3 100644 --- a/src/generated/v3/jobService/jobServiceFetcher.ts +++ b/src/generated/v3/jobService/jobServiceFetcher.ts @@ -1,96 +1,6 @@ -export type JobServiceFetcherExtraProps = { - /** - * You can add some extra props to your generated fetchers. - * - * Note: You need to re-gen after adding the first property to - * have the `JobServiceFetcherExtraProps` injected in `JobServiceComponents.ts` - **/ -}; +// This type is imported in the auto generated `jobServiceComponents` file, so it needs to be +// exported from this file. +export type { ErrorWrapper } from "../utils"; -const baseUrl = ""; // TODO add your baseUrl - -export type ErrorWrapper = TError | { status: "unknown"; payload: string }; - -export type JobServiceFetcherOptions = { - url: string; - method: string; - body?: TBody; - headers?: THeaders; - queryParams?: TQueryParams; - pathParams?: TPathParams; - signal?: AbortSignal; -} & JobServiceFetcherExtraProps; - -export async function jobServiceFetch< - TData, - TError, - TBody extends {} | FormData | undefined | null, - THeaders extends {}, - TQueryParams extends {}, - TPathParams extends {} ->({ - url, - method, - body, - headers, - pathParams, - queryParams, - signal -}: JobServiceFetcherOptions): Promise { - try { - const requestHeaders: HeadersInit = { - "Content-Type": "application/json", - ...headers - }; - - /** - * As the fetch API is being used, when multipart/form-data is specified - * the Content-Type header must be deleted so that the browser can set - * the correct boundary. - * https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects#sending_files_using_a_formdata_object - */ - if (requestHeaders["Content-Type"].toLowerCase().includes("multipart/form-data")) { - delete requestHeaders["Content-Type"]; - } - - const response = await window.fetch(`${baseUrl}${resolveUrl(url, queryParams, pathParams)}`, { - signal, - method: method.toUpperCase(), - body: body ? (body instanceof FormData ? body : JSON.stringify(body)) : undefined, - headers: requestHeaders - }); - if (!response.ok) { - let error: ErrorWrapper; - try { - error = await response.json(); - } catch (e) { - error = { - status: "unknown" as const, - payload: e instanceof Error ? `Unexpected error (${e.message})` : "Unexpected error" - }; - } - - throw error; - } - - if (response.headers.get("content-type")?.includes("json")) { - return await response.json(); - } else { - // if it is not a json response, assume it is a blob and cast it to TData - return (await response.blob()) as unknown as TData; - } - } catch (e) { - let errorObject: Error = { - name: "unknown" as const, - message: e instanceof Error ? `Network error (${e.message})` : "Network error", - stack: e as string - }; - throw errorObject; - } -} - -const resolveUrl = (url: string, queryParams: Record = {}, pathParams: Record = {}) => { - let query = new URLSearchParams(queryParams).toString(); - if (query) query = `?${query}`; - return url.replace(/\{\w*\}/g, key => pathParams[key.slice(1, -1)]) + query; -}; +// The serviceFetch method is the shared fetch method for all service fetchers. +export { serviceFetch as jobServiceFetch } from "../utils"; diff --git a/src/store/apiSlice.ts b/src/store/apiSlice.ts index b4bd732f8..be6362aa9 100644 --- a/src/store/apiSlice.ts +++ b/src/store/apiSlice.ts @@ -5,6 +5,7 @@ import { HYDRATE } from "next-redux-wrapper"; import { Store } from "redux"; import { setAccessToken } from "@/admin/apiProvider/utils/token"; +import { DelayedJobDto } from "@/generated/v3/jobService/jobServiceSchemas"; import { LoginDto, OrganisationDto, UserDto } from "@/generated/v3/userService/userServiceSchemas"; export type PendingErrorState = { @@ -53,12 +54,13 @@ type StoreResourceMap = Record; organisations: StoreResourceMap; users: StoreResourceMap; + delayedJobs: StoreResourceMap; }; export type JsonApiResource = { From fa4d2c44c0482a33214ed641bd95dacf29969617 Mon Sep 17 00:00:00 2001 From: JORGE Date: Thu, 12 Dec 2024 12:37:44 -0400 Subject: [PATCH 03/24] [TM-1531] updates for job service --- src/generated/v3/jobService/jobServiceComponents.ts | 12 ++++++------ src/generated/v3/jobService/jobServicePredicates.ts | 8 ++++---- src/generated/v3/jobService/jobServiceSchemas.ts | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/generated/v3/jobService/jobServiceComponents.ts b/src/generated/v3/jobService/jobServiceComponents.ts index 5eef6bc8c..bdece4f35 100644 --- a/src/generated/v3/jobService/jobServiceComponents.ts +++ b/src/generated/v3/jobService/jobServiceComponents.ts @@ -119,7 +119,7 @@ export const delayedJobsFind = (variables: DelayedJobsFindVariables, signal?: Ab signal }); -export type BulkClearJobsError = Fetcher.ErrorWrapper< +export type BulkUpdateJobsError = Fetcher.ErrorWrapper< | { status: 400; payload: { @@ -173,7 +173,7 @@ export type BulkClearJobsError = Fetcher.ErrorWrapper< } >; -export type BulkClearJobsResponse = { +export type BulkUpdateJobsResponse = { data?: { /** * @example delayedJobs @@ -187,16 +187,16 @@ export type BulkClearJobsResponse = { }; }; -export type BulkClearJobsVariables = { +export type BulkUpdateJobsVariables = { body: Schemas.DelayedJobBulkUpdateBodyDto; }; /** * Accepts a JSON:API-compliant payload to bulk update jobs, allowing each job's isAcknowledged attribute to be set to true or false. */ -export const bulkClearJobs = (variables: BulkClearJobsVariables, signal?: AbortSignal) => - jobServiceFetch({ - url: "/jobs/v3/delayedJobs/bulk-clear", +export const bulkUpdateJobs = (variables: BulkUpdateJobsVariables, signal?: AbortSignal) => + jobServiceFetch({ + url: "/jobs/v3/delayedJobs/bulk-update", method: "patch", ...variables, signal diff --git a/src/generated/v3/jobService/jobServicePredicates.ts b/src/generated/v3/jobService/jobServicePredicates.ts index 2c10040e5..fdac678cb 100644 --- a/src/generated/v3/jobService/jobServicePredicates.ts +++ b/src/generated/v3/jobService/jobServicePredicates.ts @@ -19,8 +19,8 @@ export const delayedJobsFindFetchFailed = (variables: DelayedJobsFindVariables) ...variables }); -export const bulkClearJobsIsFetching = (store: ApiDataStore) => - isFetching<{}, {}>({ store, url: "/jobs/v3/delayedJobs/bulk-clear", method: "patch" }); +export const bulkUpdateJobsIsFetching = (store: ApiDataStore) => + isFetching<{}, {}>({ store, url: "/jobs/v3/delayedJobs/bulk-update", method: "patch" }); -export const bulkClearJobsFetchFailed = (store: ApiDataStore) => - fetchFailed<{}, {}>({ store, url: "/jobs/v3/delayedJobs/bulk-clear", method: "patch" }); +export const bulkUpdateJobsFetchFailed = (store: ApiDataStore) => + fetchFailed<{}, {}>({ store, url: "/jobs/v3/delayedJobs/bulk-update", method: "patch" }); diff --git a/src/generated/v3/jobService/jobServiceSchemas.ts b/src/generated/v3/jobService/jobServiceSchemas.ts index 2261e5426..23a8612a7 100644 --- a/src/generated/v3/jobService/jobServiceSchemas.ts +++ b/src/generated/v3/jobService/jobServiceSchemas.ts @@ -29,7 +29,7 @@ export type DelayedJobDto = { */ progressMessage: string | null; /** - * Indicates whether the jobs have been cleared + * Indicates whether the jobs have been acknowledged (cleared) */ isAcknowledged: boolean | null; }; From 9fbece29c6df434832345a74744c48b4a0dab2c3 Mon Sep 17 00:00:00 2001 From: JORGE Date: Thu, 12 Dec 2024 13:18:57 -0400 Subject: [PATCH 04/24] [TM-1531] sort alphabetical --- src/store/apiSlice.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/apiSlice.ts b/src/store/apiSlice.ts index be6362aa9..123c603fa 100644 --- a/src/store/apiSlice.ts +++ b/src/store/apiSlice.ts @@ -54,13 +54,13 @@ type StoreResourceMap = Record; logins: StoreResourceMap; organisations: StoreResourceMap; users: StoreResourceMap; - delayedJobs: StoreResourceMap; }; export type JsonApiResource = { From 830387724195e30a34194d85c6afeeee27a8d3ef Mon Sep 17 00:00:00 2001 From: JORGE Date: Fri, 13 Dec 2024 15:25:17 -0400 Subject: [PATCH 05/24] [TM-1531] add connection for list the delayed jobs --- .../Notification/FloatNotification.tsx | 46 ++++++++------- src/connections/DelayedJob.ts | 57 +++++++++++++++++++ src/context/floatNotification.provider.tsx | 2 +- 3 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 src/connections/DelayedJob.ts diff --git a/src/components/elements/Notification/FloatNotification.tsx b/src/components/elements/Notification/FloatNotification.tsx index 45e6e2af9..df7769950 100644 --- a/src/components/elements/Notification/FloatNotification.tsx +++ b/src/components/elements/Notification/FloatNotification.tsx @@ -1,10 +1,10 @@ import classNames from "classnames"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { When } from "react-if"; import Icon, { IconNames } from "@/components/extensive/Icon/Icon"; +import { useDelayedJobs } from "@/connections/DelayedJob"; -import LinearProgressBar from "../ProgressBar/LinearProgressBar/LinearProgressBar"; import Text from "../Text/Text"; export interface FloatNotificationDataProps { @@ -17,9 +17,13 @@ export interface FloatNotificationProps { data: FloatNotificationDataProps[]; } -const FloatNotification = ({ data }: FloatNotificationProps) => { +const FloatNotification = () => { const [openModalNotification, setOpenModalNotification] = useState(false); + const [isLoaded, { delayedJobs }] = useDelayedJobs(); + useEffect(() => { + console.log("delayedJobs", delayedJobs); + }, [isLoaded, delayedJobs]); return (
@@ -43,31 +47,33 @@ const FloatNotification = ({ data }: FloatNotificationProps) => {
- {data.map((item, index) => ( -
-
-
- - {item.label} - -
- + {isLoaded && + delayedJobs && + delayedJobs.map((item, index) => ( +
+
+
+ + {item.processedContent} + +
+ {/* Site: {item.site} - -
+ */} + {/*
{item.value} +
*/}
-
- ))} + ))}
- 0}> + 0}>
- {data.length} + {delayedJobs?.length}