Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(309): Add codeblock to unknown node #644

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions packages/ui/src/components/Visualization/Canvas/CanvasForm.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { AutoField, AutoFields, AutoForm, ErrorsField } from '@kaoto-next/uniforms-patternfly';
import { Title } from '@patternfly/react-core';
import { CodeBlock, CodeBlockCode, Title } from '@patternfly/react-core';
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 './DataFormatEditor';
import { LoadBalancerEditor } from './LoadBalancerEditor';
import { StepExpressionEditor } from './StepExpressionEditor';
import { CanvasNode } from './canvas.models';
import { LoadBalancerEditor } from './LoadBalancerEditor';
import './CanvasForm.scss';

interface CanvasFormProps {
selectedNode: CanvasNode;
Expand Down Expand Up @@ -70,18 +71,28 @@ export const CanvasForm: FunctionComponent<CanvasFormProps> = (props) => {
return schema?.schema && schema.schema['$comment']?.includes('loadbalance');
}, [schema]);

return schema?.schema === undefined ? null : (
const isUnknownComponent = useMemo(() => {
return schema?.schema === undefined || Object.keys(schema?.schema).length === 0;
}, [schema]);

return (
<ErrorBoundary key={props.selectedNode.id} fallback={<p>This node cannot be configured yet</p>}>
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<Title headingLevel="h1">{componentName}</Title>
{isExpressionAwareStep && <StepExpressionEditor selectedNode={props.selectedNode} />}
{isDataFormatAwareStep && <DataFormatEditor selectedNode={props.selectedNode} />}
{isLoadBalanceAwareStep && <LoadBalancerEditor selectedNode={props.selectedNode} />}
<AutoForm ref={formRef} schema={schema} model={model} onChangeModel={handleOnChange} data-testid="autoform">
<AutoFields omitFields={omitFields} />
<ErrorsField />
</AutoForm>
</AutoField.componentDetectorContext.Provider>
<Title headingLevel="h1">{componentName}</Title>
{isUnknownComponent ? (
<CodeBlock>
<CodeBlockCode>{stringify(model)}</CodeBlockCode>
</CodeBlock>
) : (
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
{isExpressionAwareStep && <StepExpressionEditor selectedNode={props.selectedNode} />}
{isDataFormatAwareStep && <DataFormatEditor selectedNode={props.selectedNode} />}
{isLoadBalanceAwareStep && <LoadBalancerEditor selectedNode={props.selectedNode} />}
<AutoForm ref={formRef} schema={schema} model={model} onChangeModel={handleOnChange} data-testid="autoform">
<AutoFields omitFields={omitFields} />
<ErrorsField />
</AutoForm>
</AutoField.componentDetectorContext.Provider>
)}
</ErrorBoundary>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,59 @@ exports[`CanvasForm should render 1`] = `
</div>
`;

exports[`CanvasForm should render nothing if no schema and no definition is available 1`] = `<div />`;
exports[`CanvasForm should render nothing if no schema and no definition is available 1`] = `
<div>
<h1
class="pf-v5-c-title pf-m-2xl"
data-ouia-component-id="OUIA-Generated-Title-3"
data-ouia-component-type="PF5/Title"
data-ouia-safe="true"
>
My Node
</h1>
<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

exports[`CanvasForm should render nothing if no schema is available 1`] = `<div />`;
</code>
</pre>
</div>
</div>
</div>
`;

exports[`CanvasForm should render nothing if no schema is available 1`] = `
<div>
<h1
class="pf-v5-c-title pf-m-2xl"
data-ouia-component-id="OUIA-Generated-Title-2"
data-ouia-component-type="PF5/Title"
data-ouia-safe="true"
/>
<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>
`;
Loading