Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
MGDOBR-985: Display the Error Handling configuration of a bridge (#145)
Browse files Browse the repository at this point in the history
* Prepare handler to manage error handler configuration data

* Error handling methods - hardcoded and types

* Selector for the error handling method

* Error handling configuration: happy path

* Validation + disabling form while submitting

* Testing error handling config

* Refactoring

* Renaming id

* Fixing tests after renaming

* Setting error handling strategy for a couple of mocked instances (+ removing endpoint url for not-ready instances)

* Adding error handling method tab to instance page

* Managing conflict after rebase

* Validate both name and params

* Scrolling to the error, also in case of nameError triggered by API response

* Updating test case

* Fixing conflicts

* Externalizing processors tab content from InstancePage

* Externalizing error handling tab content from InstancePage

* Load tab content only when accessing to it. Detaching DOM element related to left tab

* Each tab should have a specific route

* Merging main conflicts

* Fixing mocked data

* Fixing page layout

* Remove usage of `location.pathname`

* Listening to tab parameter changes for updating active tab

* Fixing white space below tab content

* Giving min height to the EH section

* Skeleton for tab titles while loading

* Renaming useMemo function
  • Loading branch information
Valentino Pellegrino authored Sep 5, 2022
1 parent 11367d7 commit ad15c45
Show file tree
Hide file tree
Showing 9 changed files with 601 additions and 362 deletions.
6 changes: 6 additions & 0 deletions locales/en/openbridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
"value": "Value",
"yes": "Yes"
},
"errorHandling": {
"errors": {
"cantFindSchema": "The information related to the error handling strategy for this Smart Events instance is currently missing.",
"schemaGenericError": "Error while retrieving the information related to the error handling strategy for this Smart Events instance."
}
},
"instance": {
"createASEInstance": "Create a Smart Events instance",
"createSEInstance": "Create Smart Events instance",
Expand Down
12 changes: 8 additions & 4 deletions mocked-api/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const instancesData = [
published_at: "2022-02-24T13:35:00Z",
endpoint:
"https://3543edaa-1851-4ad7-96be-ebde7d20d717.apps.openbridge-dev.fdvn.p1.openshiftapps.com/events",
error_handler: {
type: "webhook_sink_0.1",
parameters: `{"endpoint":"http://google.com","basic_auth_password":"my-password","basic_auth_username":"user","ssl_verification_disabled":false}`,
},
},
{
kind: "Bridge",
Expand All @@ -22,6 +26,10 @@ export const instancesData = [
published_at: "2022-02-20T11:24:00Z",
endpoint:
"https://830c8f0d-c677-492f-8d7e-0f81893fbba6.apps.openbridge-dev.fdvn.p1.openshiftapps.com/events",
error_handler: {
type: "kafka_topic_sink_0.1",
parameters: `{"topic":"my-topic","kafka_client_id":"my-client","kafka_broker_url":"username-c--hj---mhlksdfss-p--a.bf2.kafka.rhcloud.com:443","kafka_client_secret":"my-secret"}`,
},
},
{
kind: "Bridge",
Expand All @@ -32,8 +40,6 @@ export const instancesData = [
status: "accepted",
submitted_at: "2022-02-15T12:03:00Z",
published_at: "2022-02-15T12:04:00Z",
endpoint:
"https://ee22ce62-1f23-4dd7-b106-e4158baf8228.apps.openbridge-dev.fdvn.p1.openshiftapps.com/events",
},
{
kind: "Bridge",
Expand All @@ -44,8 +50,6 @@ export const instancesData = [
status: "provisioning",
submitted_at: "2022-02-10T16:34:00Z",
published_at: "2022-02-10T16:35:00Z",
endpoint:
"https://21ac90ba-76d2-4f88-b08b-2547ef359bae.apps.openbridge-dev.fdvn.p1.openshiftapps.com/events",
},
{
kind: "Bridge",
Expand Down
153 changes: 153 additions & 0 deletions src/app/Instance/InstancePage/ErrorHandlingTabContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import {
Alert,
DescriptionList,
DescriptionListDescription,
DescriptionListGroup,
DescriptionListTerm,
PageSection,
PageSectionVariants,
Skeleton,
Stack,
StackItem,
Text,
TextContent,
TextVariants,
} from "@patternfly/react-core";
import {
ERROR_HANDLING_METHODS,
getErrorHandlingMethodByType,
} from "../../../types/ErrorHandlingMethods";
import ProcessorDetailConfigParameters from "@app/Processor/ProcessorDetail/ProcessorDetailConfigParameters";
import React, { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useGetSchemaApi } from "../../../hooks/useSchemasApi/useGetSchemaApi";
import { ProcessorSchemaType } from "../../../types/Processor";
import axios from "axios";
import {
getErrorCode,
isServiceApiError,
} from "@openapi/generated/errorHelpers";
import { APIErrorCodes } from "@openapi/generated/errors";

interface ErrorHandlingTabContentProps {
errorHandlingType?: string;
errorHandlingParameters?: { [p: string]: unknown };
isBridgeLoading: boolean;
}

export const ErrorHandlingTabContent = ({
errorHandlingType,
errorHandlingParameters,
isBridgeLoading,
}: ErrorHandlingTabContentProps): JSX.Element => {
const { t } = useTranslation(["openbridgeTempDictionary"]);

const [schema, setSchema] = useState<object>();
const [schemaError, setSchemaError] = useState<string | undefined>();
const [schemaLoading, setSchemaLoading] = useState(false);

const { getSchema } = useGetSchemaApi();

useEffect(() => {
if (errorHandlingType) {
setSchemaLoading(true);
setSchema(undefined);
setSchemaError(undefined);
getSchema(errorHandlingType, ProcessorSchemaType.ACTION)
.then((data) => setSchema(data))
.catch((error) => {
if (error && axios.isAxiosError(error)) {
if (
isServiceApiError(error) &&
getErrorCode(error) === APIErrorCodes.ERROR_4
) {
setSchemaError(t("errorHandling.errors.cantFindSchema"));
} else {
setSchemaError(t("errorHandling.errors.schemaGenericError"));
}
}
})
.finally(() => setSchemaLoading(false));
}
}, [errorHandlingType, getSchema, t]);

const errorHandlingParametersSkeleton = useMemo(() => {
const parametersLength = errorHandlingParameters
? Object.keys(errorHandlingParameters).length
: 1;
return (
<DescriptionListGroup key="error-handling-loading-skeletons">
{[...(Array(parametersLength) as unknown[])].map((_, index) => (
<React.Fragment key={index}>
<DescriptionListTerm>
<Skeleton fontSize="2xl" width={"60px"} />
</DescriptionListTerm>
<DescriptionListDescription>
<Skeleton fontSize="2xl" width={"100px"} />
</DescriptionListDescription>
</React.Fragment>
))}
</DescriptionListGroup>
);
}, [errorHandlingParameters]);

const errorHandlingMethodLabel = useMemo(() => {
if (errorHandlingType) {
return getErrorHandlingMethodByType(errorHandlingType).label;
}
if (isBridgeLoading) {
return <Skeleton fontSize="2xl" width={"60px"} />;
}
return ERROR_HANDLING_METHODS.default.label;
}, [errorHandlingType, isBridgeLoading]);

return (
<PageSection
className="instance-page__tabs-error-handling__section"
variant={PageSectionVariants.light}
isFilled
>
<Stack hasGutter>
<StackItem>
<TextContent>
<Text component={TextVariants.h2} ouiaId="error-handling-section">
{t("common.errorHandlingMethod")}
</Text>
</TextContent>
</StackItem>
<StackItem>
<DescriptionList>
<DescriptionListGroup key="error-handling-method">
<DescriptionListTerm>
{t("common.errorHandlingMethod")}
</DescriptionListTerm>
<DescriptionListDescription>
{errorHandlingMethodLabel}
</DescriptionListDescription>
</DescriptionListGroup>
{errorHandlingParameters &&
schema &&
!schemaLoading &&
!schemaError && (
<ProcessorDetailConfigParameters
schema={schema}
parameters={errorHandlingParameters}
/>
)}
{schemaLoading && errorHandlingParametersSkeleton}
{schemaError && (
<Alert
className="instance-page__tabs-error-handling__alert"
ouiaId="error-schema"
variant="danger"
title={schemaError}
aria-live="polite"
isInline
/>
)}
</DescriptionList>
</StackItem>
</Stack>
</PageSection>
);
};
4 changes: 4 additions & 0 deletions src/app/Instance/InstancePage/InstancePage.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
.instance-page__actions .pf-c-dropdown__menu {
min-width: 13rem;
}

.instance-page__tabs-error-handling__section {
min-height: 37rem;
}
Loading

0 comments on commit ad15c45

Please sign in to comment.