Skip to content

Commit 88033f8

Browse files
committed
fix split-string node-type and improve load-text-file node-type
1 parent 2013f6a commit 88033f8

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

libs/web-flow-executor/src/nodes/load-text-file.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { NodeInfo } from '../types/node-info';
1515
interface FileInfo {
1616
fileName: string;
1717
lines: string[];
18+
fileContent: string;
1819
}
1920

2021
const selectFile = () => {
@@ -32,7 +33,11 @@ const selectFile = () => {
3233
reader.addEventListener('load', (event) => {
3334
if (event && event.target && event.target.result) {
3435
const lines = (event.target.result as string).split(/\r\n|\n/);
35-
resolve({ lines, fileName: files[0].name });
36+
resolve({
37+
lines,
38+
fileContent: event.target.result as string,
39+
fileName: files[0].name,
40+
});
3641
}
3742
input.remove();
3843
});
@@ -50,18 +55,22 @@ const selectFile = () => {
5055

5156
export const loadTextFileNodeName = 'load-text-file';
5257
const fieldName = 'fileName';
53-
export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
58+
export const loadTextFile = (updated: () => void): NodeTask<NodeInfo> => {
5459
let node: IRectNodeComponent<NodeInfo>;
5560
let htmlNode: INodeComponent<NodeInfo> | undefined = undefined;
5661
let hasInitialValue = true;
5762
let rect: ReturnType<IFlowCanvasBase<NodeInfo>['createRect']> | undefined =
5863
undefined;
5964
let lines: string[] = [];
65+
let fileContent = '';
6066
const initializeCompute = () => {
6167
hasInitialValue = true;
6268
if (htmlNode && htmlNode.domElement) {
6369
htmlNode.domElement.textContent = 'Click to load text file';
70+
(htmlNode.domElement as HTMLElement).title = '';
6471
}
72+
fileContent = '';
73+
lines = [];
6574
return;
6675
};
6776
const compute = () => {
@@ -70,6 +79,12 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
7079
hasInitialValue = false;
7180
}
7281
}
82+
if (!node.nodeInfo?.formValues?.parseLines) {
83+
return {
84+
result: fileContent,
85+
followPath: undefined,
86+
};
87+
}
7388
return {
7489
result: lines,
7590
followPath: undefined,
@@ -100,9 +115,12 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
100115
.then((fileInfo) => {
101116
if (htmlNode && fileInfo && node) {
102117
lines = fileInfo.lines;
103-
(htmlNode.domElement as HTMLImageElement).textContent = `${
118+
fileContent = fileInfo.fileContent;
119+
const fileName = `${
104120
fileInfo.fileName
105-
}: ${lines.length.toString()}`;
121+
}: ${lines.length.toString()} lines`;
122+
(htmlNode.domElement as HTMLElement).textContent = fileName;
123+
(htmlNode.domElement as HTMLElement).title = fileName;
106124
}
107125
resolve();
108126
})
@@ -112,11 +130,30 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
112130
});
113131
},
114132
},
133+
{
134+
fieldType: FormFieldType.Checkbox,
135+
fieldName: 'parseLines',
136+
label: 'Parse lines',
137+
value: initalValues?.['parseLines'] ?? false,
138+
onChange: (value: string) => {
139+
if (!node.nodeInfo) {
140+
return;
141+
}
142+
node.nodeInfo.formValues = {
143+
...node.nodeInfo.formValues,
144+
parseLines: Boolean(value),
145+
};
146+
147+
if (updated) {
148+
updated();
149+
}
150+
},
151+
},
115152
];
116153
htmlNode = createElement(
117154
'div',
118155
{
119-
class: '',
156+
class: 'overflow-hidden whitespace-nowrap text-ellipsis',
120157
},
121158
undefined,
122159
'-'
@@ -170,13 +207,6 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
170207
}
171208
);
172209

173-
if (initalValues && initalValues[fieldName] && htmlNode?.domElement) {
174-
hasInitialValue = false;
175-
(
176-
htmlNode.domElement as HTMLImageElement
177-
).src = `data:image/png;base64,${initalValues[fieldName]}`;
178-
}
179-
180210
if (!rect.nodeComponent) {
181211
throw new Error('rect.nodeComponent is undefined');
182212
}
@@ -188,7 +218,7 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
188218
node.nodeInfo.compute = compute;
189219
node.nodeInfo.initializeCompute = initializeCompute;
190220
node.nodeInfo.formValues = {
191-
image: initalValues?.[fieldName] ?? '',
221+
parseLines: Boolean(initalValues?.['parseLines']) ?? false,
192222
};
193223
}
194224
return node;

libs/web-flow-executor/src/nodes/split-string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const splitString: NodeTaskFactory<NodeInfo> = (
4040
splitBy = '\t';
4141
} else if (splitBy.toUpperCase() === 'PIPE') {
4242
splitBy = '|';
43-
} else if (splitBy.toUpperCase() === 'CRKF') {
43+
} else if (splitBy.toUpperCase() === 'CRLF') {
4444
splitBy = '\r\n';
4545
}
4646
const splitLines = (input ?? '').toString().trim().split(splitBy);

0 commit comments

Comments
 (0)