Skip to content

Commit 8fd39dc

Browse files
use prop_${count} based configuration
1 parent 0ea7a66 commit 8fd39dc

File tree

1 file changed

+49
-31
lines changed

1 file changed

+49
-31
lines changed

components/pipedream_utils/actions/extract-by-regular-expressions-list/extract-by-regular-expressions-list.mjs

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,57 @@ export default {
88
type: "action",
99
props: {
1010
pipedream_utils,
11-
alert: {
12-
type: "alert",
13-
alertType: "info",
14-
content: "Start by defining the keys you want to extract. Each key will have its own input and regex configuration.\nMake sure to Refresh the fields at the bottom after changing a configuration.",
15-
},
16-
keys: {
17-
type: "string[]",
18-
label: "Keys",
19-
description: "The list of keys to use for the result map",
11+
key_0: {
12+
type: "string",
13+
label: "Key",
14+
description: "The key where the extraction result for a regex will be stored",
2015
reloadProps: true,
2116
},
17+
input_0: {
18+
type: "string",
19+
label: "Input",
20+
description: "The text you would like to find a pattern from",
21+
},
22+
regex_0: {
23+
type: "string",
24+
label: "Regular Expression",
25+
description: "[Regular expression](https://www.w3schools.com/js/js_regexp.asp)",
26+
},
2227
},
2328
additionalProps() {
2429
const props = {};
25-
for (const key of this.keys) {
26-
if (this.isKeyValid(key)) {
27-
props[`${key}Input`] = {
28-
type: "string",
29-
label: `Input for: ${key}`,
30-
description: `The text you would like to find a pattern from for **${key}**`,
31-
};
32-
props[`${key}RegExp`] = {
33-
type: "string",
34-
label: `Regular Expression for: ${key}`,
35-
description: `[Regular expression](https://www.w3schools.com/js/js_regexp.asp) to use for **${key}**`,
36-
};
37-
}
30+
let count = 1;
31+
32+
while (this[`key_${count}`]) {
33+
props[`key_${count}`] = {
34+
type: "string",
35+
label: "Another Key",
36+
description: "The key where the extraction result for a regex will be stored",
37+
};
38+
props[`input_${count}`] = {
39+
type: "string",
40+
label: "Input",
41+
description: "The text you would like to find a pattern from",
42+
};
43+
props[`regex_${count}`] = {
44+
type: "string",
45+
label: "Regular Expression",
46+
description: "[Regular expression](https://www.w3schools.com/js/js_regexp.asp)",
47+
};
48+
count++;
3849
}
50+
51+
props[`key_${count}`] = {
52+
type: "string",
53+
label: "Another Key",
54+
description: "The key where the extraction result for a regex will be stored",
55+
optional: true,
56+
reloadProps: true,
57+
};
58+
3959
return props;
4060
},
4161
methods: {
42-
isKeyValid(key) {
43-
return key?.trim().length;
44-
},
4562
getRegExp(regExpStr) {
4663
return regExpStr.startsWith("/")
4764
? buildRegExp(regExpStr, [
@@ -60,16 +77,17 @@ export default {
6077
},
6178
},
6279
async run() {
80+
let count = 0;
6381
const resultMap = {};
6482

65-
for (const key of this.keys) {
66-
if (!this.isKeyValid(key)) continue;
67-
68-
const input = this[`${key}Input`];
69-
const regExpStr = this[`${key}RegExp`];
83+
while (this[`key_${count}`]) {
84+
const input = this[`input_${count}`];
85+
const regExpStr = this[`regex_${count}`];
7086

7187
const result = this.getResults(input, regExpStr);
72-
resultMap[key] = result;
88+
resultMap[this[`key_${count}`]] = result;
89+
90+
count++;
7391
}
7492

7593
return resultMap;

0 commit comments

Comments
 (0)