Skip to content

Commit

Permalink
Add hint for unknown node type
Browse files Browse the repository at this point in the history
  • Loading branch information
tplevko committed Feb 7, 2024
1 parent 91aafaa commit 3e19aeb
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 23 deletions.
10 changes: 4 additions & 6 deletions packages/ui/src/components/Visualization/Canvas/CanvasForm.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { AutoField, AutoFields, AutoForm, ErrorsField } from '@kaoto-next/uniforms-patternfly';
import { CodeBlock, CodeBlockCode, Title } from '@patternfly/react-core';
import { Title } from '@patternfly/react-core';
import set from 'lodash.set';
import { FunctionComponent, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
import { stringify } from 'yaml';
import { EntitiesContext } from '../../../providers/entities.provider';
import { ErrorBoundary } from '../../ErrorBoundary';
import { SchemaService } from '../../Form';
import { CustomAutoFieldDetector } from '../../Form/CustomAutoField';
import './CanvasForm.scss';
import { DataFormatEditor } from '../../Form/dataFormat/DataFormatEditor';
import { LoadBalancerEditor } from '../../Form/loadBalancer/LoadBalancerEditor';
import { StepExpressionEditor } from '../../Form/stepExpression/StepExpressionEditor';
import { UnknownNode } from '../Custom/UnknownNode';
import './CanvasForm.scss';
import { CanvasNode } from './canvas.models';

interface CanvasFormProps {
Expand Down Expand Up @@ -75,9 +75,7 @@ export const CanvasForm: FunctionComponent<CanvasFormProps> = (props) => {
<Title headingLevel="h1">{componentName}</Title>
<div className="canvas-form">
{isUnknownComponent ? (
<CodeBlock>
<CodeBlockCode>{stringify(model)}</CodeBlockCode>
</CodeBlock>
<UnknownNode model={model} />
) : (
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
{isExpressionAwareStep && <StepExpressionEditor selectedNode={props.selectedNode} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,93 @@ exports[`CanvasForm should render nothing if no schema and no definition is avai
class="canvas-form"
>
<div
class="pf-v5-c-code-block"
class="pf-v5-c-card"
data-ouia-component-id="OUIA-Generated-Card-2"
data-ouia-component-type="PF5/Card"
data-ouia-safe="true"
id=""
>
<div
class="pf-v5-c-code-block__content"
class="pf-v5-c-card__header"
>
<pre
class="pf-v5-c-code-block__pre"
<div
class="pf-v5-c-card__header-main"
>
<code
class="pf-v5-c-code-block__code"
<div
class="pf-v5-c-card__title"
>
null
<div
class="pf-v5-c-card__title-text"
>
Node source
</div>
</div>
</div>
</div>
<div
class="pf-v5-c-card__body"
>
<div
class="pf-v5-c-code-block"
>
<div
class="pf-v5-c-code-block__content"
>
<pre
class="pf-v5-c-code-block__pre"
>
<code
class="pf-v5-c-code-block__code"
>
null
</code>
</pre>
</code>
</pre>
</div>
</div>
</div>
<div
class="pf-v5-c-card__footer"
>
<div
class="pf-v5-c-alert pf-m-warning"
data-ouia-component-id="OUIA-Generated-Alert-warning-2"
data-ouia-component-type="PF5/Alert"
data-ouia-safe="true"
>
<div
class="pf-v5-c-alert__icon"
>
<svg
aria-hidden="true"
class="pf-v5-svg"
fill="currentColor"
height="1em"
role="img"
viewBox="0 0 576 512"
width="1em"
>
<path
d="M569.517 440.013C587.975 472.007 564.806 512 527.94 512H48.054c-36.937 0-59.999-40.055-41.577-71.987L246.423 23.985c18.467-32.009 64.72-31.951 83.154 0l239.94 416.028zM288 354c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"
/>
</svg>
</div>
<h4
class="pf-v5-c-alert__title"
>
<span
class="pf-v5-screen-reader"
>
Warning alert:
</span>
Node is not a known type
</h4>
<div
class="pf-v5-c-alert__description"
>
The configuration for an unknown node cannot be changed in the configuration form. Please switch to the source code and correct the node type. Another option is to replace the step in the graphical editor but in that case you will probably lose the existing configuration.
</div>
</div>
</div>
</div>
</div>
Expand All @@ -129,18 +201,90 @@ exports[`CanvasForm should render nothing if no schema is available 1`] = `
class="canvas-form"
>
<div
class="pf-v5-c-code-block"
class="pf-v5-c-card"
data-ouia-component-id="OUIA-Generated-Card-1"
data-ouia-component-type="PF5/Card"
data-ouia-safe="true"
id=""
>
<div
class="pf-v5-c-code-block__content"
class="pf-v5-c-card__header"
>
<pre
class="pf-v5-c-code-block__pre"
<div
class="pf-v5-c-card__header-main"
>
<code
class="pf-v5-c-code-block__code"
/>
</pre>
<div
class="pf-v5-c-card__title"
>
<div
class="pf-v5-c-card__title-text"
>
Node source
</div>
</div>
</div>
</div>
<div
class="pf-v5-c-card__body"
>
<div
class="pf-v5-c-code-block"
>
<div
class="pf-v5-c-code-block__content"
>
<pre
class="pf-v5-c-code-block__pre"
>
<code
class="pf-v5-c-code-block__code"
/>
</pre>
</div>
</div>
</div>
<div
class="pf-v5-c-card__footer"
>
<div
class="pf-v5-c-alert pf-m-warning"
data-ouia-component-id="OUIA-Generated-Alert-warning-1"
data-ouia-component-type="PF5/Alert"
data-ouia-safe="true"
>
<div
class="pf-v5-c-alert__icon"
>
<svg
aria-hidden="true"
class="pf-v5-svg"
fill="currentColor"
height="1em"
role="img"
viewBox="0 0 576 512"
width="1em"
>
<path
d="M569.517 440.013C587.975 472.007 564.806 512 527.94 512H48.054c-36.937 0-59.999-40.055-41.577-71.987L246.423 23.985c18.467-32.009 64.72-31.951 83.154 0l239.94 416.028zM288 354c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"
/>
</svg>
</div>
<h4
class="pf-v5-c-alert__title"
>
<span
class="pf-v5-screen-reader"
>
Warning alert:
</span>
Node is not a known type
</h4>
<div
class="pf-v5-c-alert__description"
>
The configuration for an unknown node cannot be changed in the configuration form. Please switch to the source code and correct the node type. Another option is to replace the step in the graphical editor but in that case you will probably lose the existing configuration.
</div>
</div>
</div>
</div>
</div>
Expand Down
39 changes: 39 additions & 0 deletions packages/ui/src/components/Visualization/Custom/UnknownNode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Alert,
Card,
CardBody,
CardFooter,
CardHeader,
CardTitle,
CodeBlock,
CodeBlockCode,
} from '@patternfly/react-core';
import { stringify } from 'yaml';
import { FunctionComponent } from 'react';

interface UnknownNodeProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
model: any;
}

export const UnknownNode: FunctionComponent<UnknownNodeProps> = (props) => {
return (
<Card>
<CardHeader>
<CardTitle>Node source</CardTitle>
</CardHeader>
<CardBody>
<CodeBlock>
<CodeBlockCode>{stringify(props.model)}</CodeBlockCode>
</CodeBlock>
</CardBody>
<CardFooter>
<Alert variant="warning" title="Node is not a known type">
The configuration for an unknown node cannot be changed in the configuration form. Please switch to the source
code and correct the node type. Another option is to replace the step in the graphical editor but in that case
you will probably lose the existing configuration.
</Alert>
</CardFooter>
</Card>
);
};

0 comments on commit 3e19aeb

Please sign in to comment.