Skip to content

Commit 2023e80

Browse files
committed
feat(ui): add custom entity support
1 parent e7b5822 commit 2023e80

28 files changed

+820
-59
lines changed

ui/genApiFromSchema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import path from "node:path"
1010
// TODO: Use git tags instead of commit hashes
1111
// To use an updated source schema, change this to point to the desired version.
1212

13-
const COMMIT_HASH = "9ccbe6e4f960451e36476572df05aa2bad375d4e"
13+
const COMMIT_HASH = "47b4b770e33f576da45ec1b5156d3b94d744d2ee"
1414

1515
const SCHEMAS = ["eipComponentDef.schema.json", "eipFlow.schema.json"]
1616

ui/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"react-dnd-html5-backend": "^16.0.1",
3535
"react-dom": "^18.3.1",
3636
"react-is": "^18.3.1",
37+
"react-resizable-panels": "^3.0.4",
3738
"react-simple-code-editor": "^0.14.1",
3839
"zundo": "^2.3.0",
3940
"zustand": "^4.5.7"

ui/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "./styles.scss"
1010

1111
import FlowCanvas from "./components/canvas/FlowCanvas"
1212
import EipConfigSidePanel from "./components/config-panel/EipConfigSidePanel"
13-
import NodeChooserPanel from "./components/draggable-panel/NodeChooserPanel"
13+
import Palette from "./components/palette/Palette"
1414
import OptionsMenu from "./components/options-menu/OptionsMenu"
1515
import ToolbarMenu from "./components/toolbar/ToolbarMenu"
1616

@@ -29,7 +29,7 @@ const App = () => (
2929
</Column>
3030

3131
<Column>
32-
<NodeChooserPanel />
32+
<Palette />
3333
</Column>
3434

3535
<Column>

ui/src/api/generated/eipFlow.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export type AttributeType = string | number | boolean;
3131
export interface EipFlow {
3232
nodes?: EipNode[];
3333
edges?: FlowEdge[];
34+
/**
35+
* Custom entities do not appear on the flow diagram, but can be referenced by flow node attributes.
36+
*/
37+
customEntities?: {
38+
[k: string]: string;
39+
};
3440
}
3541
/**
3642
* An instance of an 'EipComponent' as a node in the flow diagram

ui/src/carbon-themes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
declare module "@carbon/themes" {
99
export const interactive: string
1010
export const layer01: string
11+
export const supportError: string
1112
}

ui/src/components/canvas/FlowCanvas.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
onEdgesChange,
4141
onNodesChange,
4242
} from "../../singletons/store/reactFlowActions"
43-
import { DragTypes } from "../draggable-panel/dragTypes"
43+
import { DragTypes } from "../palette/dragTypes"
4444
import DynamicEdge from "./DynamicEdge"
4545
import { EipNode, FollowerNode } from "./EipNode"
4646

@@ -235,6 +235,7 @@ const FlowCanvas = () => {
235235
showZoom={false}
236236
>
237237
<ControlButton title="clear" onClick={clearFlow}>
238+
{/* TODO: style this button as a dangerous action */}
238239
<TrashCan />
239240
</ControlButton>
240241
</Controls>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Stack } from "@carbon/react"
2+
import { supportError } from "@carbon/themes"
3+
import hljs from "highlight.js/lib/core"
4+
import json from "highlight.js/lib/languages/json"
5+
import xml from "highlight.js/lib/languages/xml"
6+
import Editor from "react-simple-code-editor"
7+
8+
hljs.registerLanguage("json", json)
9+
hljs.registerLanguage("xml", xml)
10+
11+
interface ModalCodeEditorProps {
12+
content: string
13+
setContent: (content: string) => void
14+
language: "json" | "xml"
15+
helperText?: string
16+
invalid?: boolean
17+
invalidText?: string
18+
}
19+
20+
export const ModalCodeEditor = ({
21+
content,
22+
setContent,
23+
language,
24+
helperText,
25+
invalid,
26+
invalidText,
27+
}: ModalCodeEditorProps) => {
28+
const errorOutline = invalid ? { outline: `2px solid ${supportError}` } : {}
29+
30+
return (
31+
<Stack gap={3}>
32+
<div className="modal__code-editor" style={errorOutline}>
33+
<Editor
34+
value={content}
35+
onValueChange={(code) => setContent(code)}
36+
highlight={(code) => hljs.highlight(code, { language }).value}
37+
padding={16}
38+
textareaClassName="modal__code-editor-textarea"
39+
/>
40+
</div>
41+
{invalid && <p className="modal__error-message">{invalidText}</p>}
42+
{!invalid && helperText && (
43+
<p className="modal__helper-text">{helperText}</p>
44+
)}
45+
</Stack>
46+
)
47+
}

ui/src/components/options-menu/modals/ImportFlowModal.tsx

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
import { Modal } from "@carbon/react"
22
import { InlineLoadingStatus } from "@carbon/react/lib/components/InlineLoading/InlineLoading"
3-
import hljs from "highlight.js/lib/core"
4-
import json from "highlight.js/lib/languages/json"
53
import { useState } from "react"
64
import { createPortal } from "react-dom"
7-
import Editor from "react-simple-code-editor"
85
import { importFlowFromJson } from "../../../singletons/store/appActions"
9-
10-
hljs.registerLanguage("json", json)
6+
import { ModalCodeEditor } from "../../editor/ModalCodeEditor"
117

128
interface ImportFlowModalProps {
139
open: boolean
1410
setOpen: (open: boolean) => void
1511
}
1612

17-
interface JsonEditorProps {
18-
content: string
19-
setContent: (content: string) => void
20-
}
21-
2213
const getLoadingDescription = (status: InlineLoadingStatus) => {
2314
switch (status) {
2415
case "active":
@@ -31,20 +22,6 @@ const getLoadingDescription = (status: InlineLoadingStatus) => {
3122
}
3223
}
3324

34-
const FlowJsonEditor = ({ content, setContent }: JsonEditorProps) => {
35-
return (
36-
<div className="options-modal__editor">
37-
<Editor
38-
value={content}
39-
onValueChange={(code) => setContent(code)}
40-
highlight={(code) => hljs.highlight(code, { language: "json" }).value}
41-
padding={16}
42-
textareaClassName="options-modal__editor-textarea"
43-
/>
44-
</div>
45-
)
46-
}
47-
4825
export const ImportFlowModal = ({ open, setOpen }: ImportFlowModalProps) => {
4926
const [loadingStatus, setLoadingStatus] =
5027
useState<InlineLoadingStatus>("inactive")
@@ -84,7 +61,11 @@ export const ImportFlowModal = ({ open, setOpen }: ImportFlowModalProps) => {
8461
loadingDescription={getLoadingDescription(loadingStatus)}
8562
onRequestSubmit={doImport}
8663
>
87-
<FlowJsonEditor content={content} setContent={updateContent} />
64+
<ModalCodeEditor
65+
content={content}
66+
setContent={updateContent}
67+
language="json"
68+
/>
8869
</Modal>,
8970
document.body
9071
)

0 commit comments

Comments
 (0)