-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [TASK] add join string * fix: join * add test --------- Co-authored-by: SorsOps <[email protected]>
- Loading branch information
Showing
10 changed files
with
611 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tokens-studio/graph-engine": minor | ||
--- | ||
|
||
Adds a string join node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"join": "Join", | ||
"uppercase": "Uppercase", | ||
"lowercase": "Lowercase", | ||
"regex": "Regex" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/graph-editor/src/components/flow/nodes/string/join.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { Handle, HandleContainer } from '../../handles.tsx'; | ||
import { Stack, Text, TextInput } from '@tokens-studio/ui'; | ||
import { WrapNode, useNode } from '../../wrapper/nodeV2.tsx'; | ||
import { node } from '@tokens-studio/graph-engine/nodes/string/join.js'; | ||
import { PreviewArray } from '../../preview/array.tsx'; | ||
import { PreviewAny } from '../../preview/any.tsx'; | ||
|
||
const JoinStringNode = () => { | ||
const { input, output } = useNode(); | ||
|
||
return ( | ||
<Stack direction="row" gap={4}> | ||
<HandleContainer type="target"> | ||
<Handle id="array"> | ||
<Text>Array</Text> | ||
<PreviewArray value={input.array} /> | ||
</Handle> | ||
|
||
<Handle id="separator"> | ||
<Text>Separator</Text> | ||
{input.separator !== undefined ? ( | ||
<PreviewAny value={input.separator} /> | ||
) : ( | ||
<TextInput placeholder="Enter separator" /> | ||
)} | ||
</Handle> | ||
</HandleContainer> | ||
|
||
<HandleContainer type="source"> | ||
<Handle id="output"> | ||
<Text>Output</Text> | ||
<PreviewAny value={output?.output} /> | ||
</Handle> | ||
</HandleContainer> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default WrapNode(JoinStringNode, { | ||
...node, | ||
title: 'Join String', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { node as lowercase } from "./lowercase.js"; | ||
import { node as joinString } from "./join.js"; | ||
import { node as regex } from "./regex.js"; | ||
import { node as uppercase } from "./uppercase.js"; | ||
|
||
export const nodes = [lowercase, regex, uppercase]; | ||
export const nodes = [lowercase, joinString, regex, uppercase]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NodeDefinition, NodeTypes } from "../../types.js"; | ||
|
||
const type = NodeTypes.JOIN_STRING; | ||
|
||
export type NamedInput = { | ||
array: string[]; | ||
separator: string; | ||
}; | ||
|
||
export const defaults = { | ||
array: [], | ||
separator: "", | ||
}; | ||
|
||
export const process = (input: NamedInput, state: NamedInput) => { | ||
const { array, separator } = { ...state, ...input }; | ||
return array.join(separator); | ||
}; | ||
|
||
export const node: NodeDefinition<NamedInput, NamedInput> = { | ||
defaults, | ||
type, | ||
process, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/graph-engine/tests/suites/nodes/string/join.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { executeNode } from "#/core.js"; | ||
import { node } from "#/nodes/string/join.js"; | ||
|
||
describe("string/join", () => { | ||
it("should join the string array correctly", async () => { | ||
const output = await executeNode({ | ||
input: { | ||
array: ["a", "b", "c"], | ||
}, | ||
node, | ||
state: { | ||
seperator: ",", | ||
}, | ||
nodeId: "testId", | ||
}); | ||
|
||
expect(output).toStrictEqual({ | ||
output: "a,b,c", | ||
}); | ||
}); | ||
}); |