Skip to content

Commit ea119d9

Browse files
committed
feat: update list and collection field matching
1 parent ce3aa0d commit ea119d9

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

packages/scripts/src/commands/app-data/convert/processors/flowParser/flowParser.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { arrayToHashmap, groupJsonByKey, IContentsEntry } from "../../utils";
55
import BaseProcessor from "../base";
66

77
export class FlowParserProcessor extends BaseProcessor<FlowTypes.FlowTypeWithData> {
8-
public cacheVersion = 20240315.0;
8+
public cacheVersion = 20240402.0;
99

1010
public parsers: { [flowType in FlowTypes.FlowType]: Parsers.DefaultParser } = {
1111
data_list: new Parsers.DataListParser(this),
@@ -14,6 +14,7 @@ export class FlowParserProcessor extends BaseProcessor<FlowTypes.FlowTypeWithDat
1414
global: new Parsers.DefaultParser(this),
1515
template: new Parsers.TemplateParser(this),
1616
tour: new Parsers.DefaultParser(this),
17+
asset_pack: new Parsers.DefaultParser(this),
1718
};
1819

1920
/** Keep a track of all processed flows by type and name (used in data_pipes)*/

packages/scripts/src/commands/app-data/convert/processors/flowParser/parsers/default.parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ class RowProcessor {
235235
// handle custom fields
236236
if (!shouldSkip) {
237237
if (typeof value === "string") {
238-
if (field.endsWith("_list")) {
238+
if (field.endsWith("_list") || field.includes("_list_")) {
239239
this.row[field] = parseAppDataListString(value);
240240
}
241-
if (field.endsWith("_collection")) {
241+
if (field.endsWith("_collection") || field.includes("_collection_")) {
242242
this.row[field] = parseAppDataCollectionString(this.row[field]);
243243
}
244244
if (field.endsWith("action_list")) {

packages/scripts/src/commands/app-data/convert/processors/flowParser/parsers/template.parser.spec.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ describe("Template Parser PostProcessor", () => {
4848
]);
4949
});
5050

51-
it("Converts rows with _list in name to templated list", () => {
52-
// CASE 0 - Do not convert rows without _list in name
53-
const case0 = parser.postProcessRow({
51+
it("Converts rows ending _list or containing _list_ in name to templated list", () => {
52+
// CASE 0 - Do not convert rows unless explicit includes _list_ or ends _list
53+
const case0_1 = parser.postProcessRow({
5454
...ROW_BASE,
55+
name: "test_listen",
5556
value: "item_1; item_2; item_3;",
5657
});
57-
expect(case0.value).toEqual("item_1; item_2; item_3;");
58+
expect(case0_1.value).toEqual("item_1; item_2; item_3;");
5859

5960
// CASE 1 - List items defined inline
6061
const case1 = parser.postProcessRow({
@@ -66,21 +67,21 @@ describe("Template Parser PostProcessor", () => {
6667
// CASE 2 - List refers to variable (do not parse)
6768
const case2 = parser.postProcessRow({
6869
...ROW_BASE,
69-
name: "test_list",
70+
name: "test_list_2",
7071
value: "@local.some_list",
7172
});
7273
expect(case2.value).toEqual("@local.some_list");
7374
// CASE 3 - List items include variables
7475
const case3 = parser.postProcessRow({
7576
...ROW_BASE,
76-
name: "test_list",
77+
name: "test_list_3",
7778
value: "@local.item_1; @local.item_2",
7879
});
7980
expect(case3.value).toEqual(["@local.item_1", "@local.item_2"]);
8081
// CASE 4 - List items as json (mix dynamic and missing)
8182
const case4 = parser.postProcessRow({
8283
...ROW_BASE,
83-
name: "test_list",
84+
name: "test_list_4",
8485
value: "key_1a: textValue | key_1b: @local.value; key_2a: | key_2b: 5",
8586
});
8687
expect(case4.value).toEqual([

packages/scripts/src/commands/app-data/convert/processors/flowParser/parsers/template.parser.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ export class TemplateParser extends DefaultParser {
3232
// convert any variables (local/global) list or collection strings (e.g. 'my_list_1')
3333
// in similar way to how top-level properties get converted by default parser
3434
if (row.value && typeof row.value === "string") {
35-
if (row.name?.includes("_list")) {
35+
if (row.name?.endsWith("_list") || row.name?.includes("_list_")) {
3636
row.value = this.parseTemplateList(row.value);
3737
}
38-
if (row.name?.includes("_collection") && row.value && typeof row.value === "string") {
39-
row.value = parseAppDataCollectionString(row.value);
38+
if (row.name?.endsWith("_collection") || row.name?.includes("_collection_")) {
39+
if (row.value && typeof row.value === "string") {
40+
row.value = parseAppDataCollectionString(row.value);
41+
}
4042
}
4143
}
4244
if (row.parameter_list) {

0 commit comments

Comments
 (0)