Skip to content

Commit 38b5d53

Browse files
committed
SdGSoft:
- Rework
1 parent bd94b42 commit 38b5d53

13 files changed

Lines changed: 50 additions & 51 deletions

File tree

apps/chaingraph-frontend/src/components/flow/nodes/ChaingraphNode/ports/ArrayPort/AddElementPopover.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0.
77
*/
88

9-
import type { ArrayPort, IPortConfig, PortType } from '@badaitech/chaingraph-types'
9+
import type { IPort, ArrayPortConfig, IPortConfig, PortType } from '@badaitech/chaingraph-types'
1010
import { Button } from '@/components/ui/button'
1111
import {
1212
DropdownMenu,
@@ -26,7 +26,7 @@ interface Data {
2626
}
2727

2828
interface Props {
29-
port: ArrayPort
29+
port: IPort<ArrayPortConfig>
3030
onClose: () => void
3131
onSubmit: (newItemConfig: IPortConfig) => void
3232
}
@@ -112,7 +112,7 @@ export function AddElementPopover(props: Props) {
112112
const { onClose, onSubmit, port } = props
113113

114114
const itemType = port.getConfig().itemConfig.type
115-
const dropDownValues = (itemType !== 'any' ? [itemType] : (port.getConfig().ui?.enumValues || PORT_TYPES)).filter(portType => portType !== 'any') // && portType !== 'secret')))
115+
const dropDownValues = (itemType !== 'any' ? [itemType] : (port.getConfig().ui?.allowedTypes || PORT_TYPES)).filter(portType => portType !== 'any') // && portType !== 'secret')))
116116

117117
const [type, setType] = useState<PortType | undefined>(
118118
dropDownValues.at(0) || itemType

apps/chaingraph-frontend/src/components/flow/nodes/ChaingraphNode/ports/ArrayPort/ArrayPort.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
} from '@/components/flow/nodes/ChaingraphNode/ports/context/PortContext'
1212
import type {
1313
ArrayPortConfig,
14-
ArrayPort as ArrayPortType,
1514
INode,
1615
IPort,
1716
IPortConfig,
@@ -320,7 +319,7 @@ export function ArrayPort({ node, port, context }: ArrayPortProps) {
320319
</PopoverTrigger>
321320
{isAddPropOpen && (
322321
<AddElementPopover
323-
port={port as ArrayPortType}
322+
port={port}
324323
onClose={handleClosePopover}
325324
onSubmit={handleSubmitPopover}
326325
/>

apps/chaingraph-frontend/src/components/flow/nodes/ChaingraphNode/ports/ObjectPort/ObjectPort.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import type {
1010
PortContextValue,
1111
} from '@/components/flow/nodes/ChaingraphNode/ports/context/PortContext'
12-
import type { INode, IPort, ObjectPortConfig, ObjectPort as ObjectPortType, } from '@badaitech/chaingraph-types'
12+
import type { INode, IPort, ObjectPortConfig } from '@badaitech/chaingraph-types'
1313
import { PortTitle } from '@/components/flow/nodes/ChaingraphNode/ports/ui/PortTitle'
1414
import { Popover, PopoverTrigger } from '@/components/ui/popover'
1515
import { cn } from '@/lib/utils'
@@ -223,7 +223,7 @@ export function ObjectPort({ node, port, context }: ObjectPortProps) {
223223
onClose={handleClosePopover}
224224
onSubmit={handleSubmitPopover}
225225
nextOrder={childPorts.length + 1}
226-
port={port as ObjectPortType}
226+
port={port}
227227
/>
228228
)}
229229
</Popover>

apps/chaingraph-frontend/src/components/flow/nodes/ChaingraphNode/ports/ObjectPort/components/AddPropPopover.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0.
77
*/
88

9-
import type { ObjectPort, IPortConfig, PortType } from '@badaitech/chaingraph-types'
9+
import type { IPort, ObjectPortConfig, IPortConfig, PortType } from '@badaitech/chaingraph-types'
1010
import { Button } from '@/components/ui/button'
1111
import {
1212
DropdownMenu,
@@ -29,7 +29,7 @@ interface Props {
2929
onClose: () => void
3030
onSubmit: (data: Data) => void
3131
nextOrder?: number
32-
port: ObjectPort
32+
port: IPort<ObjectPortConfig>
3333
}
3434

3535
const typeConfigMap: Record<PortType, IPortConfig> = {
@@ -113,8 +113,8 @@ export function AddPropPopover(props: Props) {
113113
const { onClose, onSubmit, port } = props
114114
const [key, setKey] = useState('')
115115

116-
// use all porttypes if enumvalues undefined and filter stream ans any out
117-
const dropDownValues = (port.getConfig().ui?.enumValues || PORT_TYPES).filter(t => t !== 'stream' && t !== 'any')
116+
// use all porttypes if allowedTypes undefined and filter stream ans any out
117+
const dropDownValues = (port.getConfig().ui?.allowedTypes || PORT_TYPES).filter(t => t !== 'stream' && t !== 'any')
118118

119119
const [type, setType] = useState<PortType | undefined>(
120120
// use as initial value first enumvalue if type is any

docs/nodes/port-decorators-spec.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ All port types support a common set of UI configuration properties through the `
983983
| addItemFormHidden | boolean | Hide the "Add Item" form |
984984
| addItemFormSpoilerState | boolean | Initial state of the "Add Item" form visibility |
985985
| itemDeletable | boolean | Whether array items can be deleted |
986-
| enumValues | PortType[] | Types allowed when adding new items |
986+
| allowedTypes | PortType[] | Types allowed when adding new items |
987987

988988
### Object Port UI
989989

@@ -992,7 +992,7 @@ All port types support a common set of UI configuration properties through the `
992992
| keyDeletable | boolean | Whether object properties can be deleted |
993993
| collapsed | boolean | Whether the object port collapsed |
994994
| hidePropertyEditor | boolean | Whether object properties can be edited |
995-
| enumValues | PortType[] | Types allowed when adding new properties |
995+
| allowedTypes | PortType[] | Types allowed when adding new properties |
996996

997997
## 7. Complete Examples
998998

packages/chaingraph-nodes/src/nodes/flow/switch.node.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SwitchNode extends BaseNode {
6262
keyDeletable: true,
6363
hideEditor: false,
6464
hidePropertyEditor: true,
65-
enumValues: ['boolean'],
65+
allowedTypes: ['boolean'],
6666
},
6767
})
6868
caseObject: Record<string, boolean> = {}
@@ -84,14 +84,7 @@ class SwitchNode extends BaseNode {
8484
async execute(context: ExecutionContext): Promise<NodeExecutionResult> {
8585
const keys: string[] = Object.keys(this.caseObject)
8686
for (const key of keys) {
87-
try {
88-
if (typeof this.caseObject[key] !== 'boolean') {
89-
continue
90-
}
91-
this.caseObject[key] = this.input === key
92-
} catch (error) {
93-
this.logError(`Error matching case value ${key} with input value ${this.input}:`, error)
94-
}
87+
this.caseObject[key] = this.input === key
9588
}
9689
this.default = !keys.includes(this.input)
9790

packages/chaingraph-trpc/server/procedures/flow/update-port-value.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const updatePortValue = flowContextProcedure
4949

5050
// console.log('Port value updated', { flowId: input.flowId, nodeId: input.nodeId, portId: input.portId, value: input.value })
5151

52-
await ctx.flowStore.updateFlow(flow as Flow)
52+
await ctx.flowStore.updateFlow(flow)
5353

5454
return {
5555
flowId: input.flowId,
@@ -114,7 +114,7 @@ export const addFieldObjectPort = flowContextProcedure
114114

115115
// console.log('Object port key added', { flowId: input.flowId, nodeId: input.nodeId, portId: input.portId, key, config })
116116

117-
await ctx.flowStore.updateFlow(flow as Flow)
117+
await ctx.flowStore.updateFlow(flow)
118118

119119
return {
120120
flowId: input.flowId,
@@ -187,7 +187,7 @@ export const removeFieldObjectPort = flowContextProcedure
187187

188188
// console.log('Object port key removed', { flowId: input.flowId, nodeId: input.nodeId, portId: input.portId, key })
189189

190-
await ctx.flowStore.updateFlow(flow as Flow)
190+
await ctx.flowStore.updateFlow(flow)
191191

192192
return {
193193
flowId: input.flowId,
@@ -222,10 +222,10 @@ export const updateItemConfigArrayPort = flowContextProcedure
222222
if (!port)
223223
throw new Error('Port not found')
224224

225-
if (port.getConfig().type !== 'array')
225+
const config = port.getConfig()
226+
if (config.type !== 'array')
226227
throw new Error('Port is not an array port')
227228

228-
const config = port.getConfig() as ArrayPortConfig
229229
port.setConfig({
230230
...config,
231231
itemConfig: input.itemConfig
@@ -236,7 +236,7 @@ export const updateItemConfigArrayPort = flowContextProcedure
236236

237237
flow.updateNode(node)
238238

239-
await ctx.flowStore.updateFlow(flow as Flow)
239+
await ctx.flowStore.updateFlow(flow)
240240

241241
return {
242242
flowId: input.flowId,
@@ -279,7 +279,7 @@ export const appendElementArrayPort = flowContextProcedure
279279

280280
// console.log('Object port key added', { flowId: input.flowId, nodeId: input.nodeId, portId: input.portId, key, config })
281281

282-
await ctx.flowStore.updateFlow(flow as Flow)
282+
await ctx.flowStore.updateFlow(flow)
283283

284284
return {
285285
flowId: input.flowId,
@@ -325,7 +325,7 @@ export const removeElementArrayPort = flowContextProcedure
325325

326326
// console.log('Object port key added', { flowId: input.flowId, nodeId: input.nodeId, portId: input.portId, key, config })
327327

328-
await ctx.flowStore.updateFlow(flow as Flow)
328+
await ctx.flowStore.updateFlow(flow)
329329

330330
return {
331331
flowId: input.flowId,

packages/chaingraph-types/src/node/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ The system provides robust support for complex data structures through specializ
213213
Complex port operations include:
214214
- `addObjectProperty`: Adds a property to an object port
215215
- `removeObjectProperty`: Removes a property from an object port
216-
- `updateArrayItemConfig`: Updates the items with new item configuration
216+
- `updateArrayItemConfig`: Updates the items with the new array ports item configuration
217217
- `appendArrayItem`: Adds an item to an array port
218218
- `removeArrayItem`: Removes an item from an array port
219219
- `recreateArrayItemPorts`: Rebuilds port structure for array items
@@ -344,9 +344,6 @@ this.addObjectProperty(
344344
})
345345
tags: string[] = ['important', 'urgent'];
346346

347-
// Update items with new configuration using API
348-
this.updateArrayItemConfig(tagsPort!);
349-
350347
// Add an item
351348
this.tags.push('follow-up'); // Automatically updates port
352349

@@ -356,6 +353,18 @@ this.appendArrayItem(tagsPort!, 'critical');
356353

357354
// Remove an item
358355
this.removeArrayItem(tagsPort!, 1); // Removes 'urgent'
356+
357+
358+
// Update the item configuration using API
359+
const tagsConfig = tagsPort!.getConfig()
360+
tagsPort!.setConfig({
361+
...tagsConfig,
362+
itemConfig: {
363+
...tagsConfig.itemConfig,
364+
defaultValue: '-'
365+
}
366+
})
367+
this.updateArrayItemConfig(tagsPort!)
359368
```
360369

361370
### Implementing Event Handling

packages/chaingraph-types/src/node/id-generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function generatePortID(propertyKey: string = ''): string {
1515
// return uuidv7()
1616
}
1717

18-
export function generatePortIDArrayElement(portId: string, elementKey: string | number): string {
18+
export function generatePortIDArrayElement(portId: string, elementKey: number): string {
1919
return `${portId}[${elementKey}]`
2020
//return `${portId}[${customAlphabet(nolookalikes, 16)()}]`
2121
}

packages/chaingraph-types/src/node/implementations/complex-port-handler.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,11 @@ export class ComplexPortHandler implements IComplexPortHandler {
262262
}
263263

264264
/**
265-
* Updates the items with new configuration
265+
* Updates the items with the new array ports item configuration
266266
* @param arrayPort The array port
267267
*/
268268
updateArrayItemConfig(arrayPort: IPort): void {
269-
const config = arrayPort.getConfig() as ArrayPortConfig
270-
if (config.type !== 'array') {
269+
if (arrayPort.getConfig().type !== 'array') {
271270
throw new Error('Cannot remove item from non-array port')
272271
}
273272

@@ -277,6 +276,7 @@ export class ComplexPortHandler implements IComplexPortHandler {
277276
if (currentValue.length === 0)
278277
return
279278

279+
// This recreates all item ports and use the new item configuration from the array port
280280
this.recreateArrayItemPorts(arrayPort, currentValue)
281281

282282
// Update the array port
@@ -290,7 +290,7 @@ export class ComplexPortHandler implements IComplexPortHandler {
290290
* @returns The index of the new item
291291
*/
292292
appendArrayItem(arrayPort: IPort, value: any): number {
293-
const config = arrayPort.getConfig() as ArrayPortConfig
293+
const config = arrayPort.getConfig()
294294
if (config.type !== 'array') {
295295
throw new Error('Cannot append item to non-array port')
296296
}
@@ -300,9 +300,8 @@ export class ComplexPortHandler implements IComplexPortHandler {
300300
const newLength = currentValue.length
301301

302302
// Process item config
303-
let portItemConfig = { ...config.itemConfig }
304-
portItemConfig = this.processPortConfig(
305-
portItemConfig,
303+
const itemConfig = this.processPortConfig(
304+
{ ...config.itemConfig },
306305
{
307306
nodeId: this.nodeId,
308307
parentPortConfig: config,
@@ -314,7 +313,7 @@ export class ComplexPortHandler implements IComplexPortHandler {
314313
// Create the item port
315314
const itemPortId = generatePortIDArrayElement(arrayPort.id, newLength)
316315
const completeItemConfig = {
317-
...portItemConfig,
316+
...itemConfig,
318317
id: itemPortId,
319318
parentId: arrayPort.id,
320319
key: newLength.toString(),
@@ -344,7 +343,7 @@ export class ComplexPortHandler implements IComplexPortHandler {
344343
* @param index The index to remove
345344
*/
346345
removeArrayItem(arrayPort: IPort, index: number): void {
347-
const config = arrayPort.getConfig() as ArrayPortConfig
346+
const config = arrayPort.getConfig()
348347
if (config.type !== 'array') {
349348
throw new Error('Cannot remove item from non-array port')
350349
}
@@ -434,9 +433,8 @@ export class ComplexPortHandler implements IComplexPortHandler {
434433
const config = arrayPort.getConfig() as ArrayPortConfig
435434

436435
// Process item config
437-
let itemConfig = { ...config.itemConfig }
438-
itemConfig = this.processPortConfig(
439-
itemConfig,
436+
const itemConfig = this.processPortConfig(
437+
{ ...config.itemConfig },
440438
{
441439
nodeId: this.nodeId,
442440
parentPortConfig: config,

0 commit comments

Comments
 (0)