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

Conversation

tplevko
Copy link
Contributor

@tplevko tplevko commented Jan 15, 2024

fixes #309

@lordrip I tried both - the <pre> with <code> and the PF CodeBlock - I believe using CodeBlock the yaml code gets more highlighted, but I can change to the originally proposed solution.

Also I wanted to ask, whether we should add some info, regarding the displayed block of code - I was thinking about, to be consistent - something like FieldLabelIcon qestionmark with popover, containing information, regarding the displayed yaml and some info, regarding the node itself - that the name is not correct and needs to be changed in source code, or replaced in the canvas.
Let me know, what do you think.

@lordrip
Copy link
Member

lordrip commented Jan 15, 2024

@tplevko looks good 👍

Comment on lines 127 to 132
<>
<Title headingLevel="h1">{componentName}</Title>
<CodeBlock>
<CodeBlockCode id="code-content">{stringify(model)}</CodeBlockCode>
</CodeBlock>
</>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 Maybe it would be nice to extract this into a dedicated component.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could look like this

<UnknownComponent componentName={componentName} } code={stringify(model)} />

Alternatively, we could reorder a bit the component to avoid duplicating the <Title> component:

  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>}>
      <Title headingLevel="h1">{componentName}</Title>
      {isUnknownComponent ? (
        <CodeBlock>
          <CodeBlockCode>{stringify(props.selectedNode.data?.vizNode?.getComponentSchema())}</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>
  );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint Ricardo, I updated the PR to remove the duplicate <Title> and also updated the failing tests.

@tplevko tplevko force-pushed the issue_309 branch 2 times, most recently from 8703aa3 to b4156a5 Compare January 16, 2024 08:47
@lordrip
Copy link
Member

lordrip commented Jan 16, 2024

@tplevko if I'm not mistaken, we shown the component's definition, but now we're showing an internal kaoto object, is this intended?
image

@lordrip lordrip merged commit cdd7541 into KaotoIO:main Jan 16, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show content of unrecognized nodes in the config form
2 participants