-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: template parser answer list support #2211
Merged
Merged
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a12fd5b
refactor: parse answer_lists in template parser
chrismclarke 8426652
chore: remove legacy parsAppDataString
chrismclarke e4e57bc
chore: update template answer list extract
chrismclarke 98a4f0e
Merge branch 'fix/combo-box-radio-group-empty-fields' of https://gith…
chrismclarke 974c65f
chore: wip spec tests
chrismclarke fa76774
feat: template row name generation
chrismclarke dca4f6c
Merge branch 'master' of https://github.com/IDEMSInternational/parent…
chrismclarke 7fdf475
chore: deprecate parseAnswerListItem
chrismclarke a87acd3
chore: code tidying
chrismclarke b6c9dc8
chore: code tidying
chrismclarke 15dbe48
Merge branch 'master' into refactor/answer-list-parser
chrismclarke 133f3b6
chore: deprecate and move nav bar value list item parse
chrismclarke 46413a7
chore: code tidying
chrismclarke fed27f5
Merge branch 'master' into refactor/answer-list-parser
esmeetewinkel ce3aa0d
Merge branch 'master' into refactor/answer-list-parser
esmeetewinkel ea119d9
feat: update list and collection field matching
chrismclarke d8fde56
Merge branch 'master' into refactor/answer-list-parser
esmeetewinkel 6e961c5
Merge branch 'master' into refactor/answer-list-parser
esmeetewinkel c2d266e
Merge branch 'master' into refactor/answer-list-parser
chrismclarke 0089892
fix: cache versions
chrismclarke 8752f73
Merge branch 'master' into refactor/answer-list-parser
esmeetewinkel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
180 changes: 178 additions & 2 deletions
180
...ripts/src/commands/app-data/convert/processors/flowParser/parsers/template.parser.spec.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 |
---|---|---|
@@ -1,3 +1,179 @@ | ||
describe("template Parser", () => { | ||
it("TODO - add tests", () => expect(true).toEqual(true)); | ||
import { FlowTypes } from "data-models"; | ||
import { TemplateParser } from "./template.parser"; | ||
|
||
const ROW_BASE: FlowTypes.TemplateRow = { | ||
_nested_name: "", | ||
name: "", | ||
type: "" as any, | ||
}; | ||
|
||
describe("Template Parser PostProcessor", () => { | ||
let parser: TemplateParser; | ||
beforeEach(() => { | ||
parser = new TemplateParser({} as any); | ||
}); | ||
|
||
it("Remove empty rows", () => { | ||
const res = parser.postProcessRow({} as any); | ||
expect(res).toEqual(undefined); | ||
}); | ||
|
||
it("Replaces empty row type with set_variable", () => { | ||
const res = parser.postProcessRow({ ...ROW_BASE, type: "" as any }); | ||
expect(res.type).toEqual("set_variable"); | ||
}); | ||
|
||
// TODO - notify authors of change (can now auto gen multiple) | ||
it("Generates default row names when omitted for multiple rows", () => { | ||
const res = parser.run({ | ||
flow_name: "test_name_generate_multiple", | ||
flow_type: "template", | ||
rows: [ | ||
{ ...ROW_BASE, name: "", type: "accordion" }, | ||
{ ...ROW_BASE, name: "", type: "accordion" }, | ||
], | ||
}); | ||
expect(res.rows).toEqual([ | ||
// Note - suffix numbers start at 2 as flow sheet would typically have row 1 as header row | ||
{ | ||
_nested_name: "accordion_2", | ||
name: "accordion_2", | ||
type: "accordion", | ||
}, | ||
{ | ||
_nested_name: "accordion_3", | ||
name: "accordion_3", | ||
type: "accordion", | ||
}, | ||
]); | ||
}); | ||
|
||
it("Converts rows with _list in name to templated list", () => { | ||
// CASE 0 - Do not convert rows without _list in name | ||
const case0 = parser.postProcessRow({ | ||
...ROW_BASE, | ||
value: "item_1; item_2; item_3;", | ||
}); | ||
expect(case0.value).toEqual("item_1; item_2; item_3;"); | ||
|
||
// CASE 1 - List items defined inline | ||
const case1 = parser.postProcessRow({ | ||
...ROW_BASE, | ||
name: "test_list", | ||
value: "item_1; item_2; item_3;", | ||
}); | ||
expect(case1.value).toEqual(["item_1", "item_2", "item_3"]); | ||
// CASE 2 - List refers to variable (do not parse) | ||
const case2 = parser.postProcessRow({ | ||
...ROW_BASE, | ||
name: "test_list", | ||
value: "@local.some_list", | ||
}); | ||
expect(case2.value).toEqual("@local.some_list"); | ||
// CASE 3 - List items include variables | ||
const case3 = parser.postProcessRow({ | ||
...ROW_BASE, | ||
name: "test_list", | ||
value: "@local.item_1; @local.item_2", | ||
}); | ||
expect(case3.value).toEqual(["@local.item_1", "@local.item_2"]); | ||
// CASE 4 - List items as json (mix dynamic and missing) | ||
const case4 = parser.postProcessRow({ | ||
...ROW_BASE, | ||
name: "test_list", | ||
value: "key_1a: textValue | key_1b: @local.value; key_2a: | key_2b: 5", | ||
}); | ||
expect(case4.value).toEqual([ | ||
{ key_1a: "textValue", key_1b: "@local.value" }, | ||
{ key_2a: "", key_2b: "5" }, | ||
]); | ||
}); | ||
|
||
it("Converts rows with _collection in name to templated collection", () => { | ||
const res = parser.postProcessRow({ | ||
...ROW_BASE, | ||
name: "test_collection", | ||
value: "key_1:value_1; key_2:value_2", | ||
}); | ||
expect(res.value).toEqual({ key_1: "value_1", key_2: "value_2" }); | ||
}); | ||
|
||
it("Parses parameter lists", () => { | ||
const res = parser.postProcessRow({ | ||
...ROW_BASE, | ||
// NOTE - list already array due to defaultParser initial parse | ||
parameter_list: ["key_1:val_1", "key_2: val_trailing_spaces ", "key_3_no_value"] as any, | ||
}); | ||
// TODO - anymore advanced cases? | ||
expect(res.parameter_list).toEqual({ | ||
key_1: "val_1", | ||
key_2: "val_trailing_spaces", | ||
key_3_no_value: "true", | ||
}); | ||
}); | ||
|
||
it("Replaces action list self-references", () => { | ||
const res = parser.postProcessRow({ | ||
...ROW_BASE, | ||
name: "my_action_list", | ||
action_list: [ | ||
{ trigger: "click", action_id: "", args: ["@local.my_action_list", "some_value"] }, | ||
], | ||
}); | ||
expect(res.action_list[0].args).toEqual(["this.value", "some_value"]); | ||
}); | ||
|
||
it("Extracts dynamic fields", () => { | ||
const res = parser.postProcessRow({ | ||
...ROW_BASE, | ||
value: "@local.dynamic_value", | ||
}); | ||
expect(res._dynamicFields).toEqual({ | ||
value: [ | ||
{ | ||
fullExpression: "@local.dynamic_value", | ||
matchedExpression: "@local.dynamic_value", | ||
type: "local", | ||
fieldName: "dynamic_value", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it("Extracts dynamic dependencies", () => { | ||
const res = parser.postProcessRow({ | ||
...ROW_BASE, | ||
value: "@local.dynamic_value", | ||
}); | ||
expect(res._dynamicDependencies).toEqual({ "@local.dynamic_value": ["value"] }); | ||
}); | ||
|
||
it("Creates nested path names for child rows", () => { | ||
const rows: FlowTypes.TemplateRow[] = [ | ||
{ | ||
_nested_name: "my_items", | ||
name: "my_items", | ||
type: "items", | ||
// Handle case of both named and unnamed nested row names | ||
rows: [ | ||
{ | ||
...ROW_BASE, | ||
type: "text", | ||
name: "named_text", | ||
}, | ||
{ ...ROW_BASE, type: "text" }, | ||
], | ||
}, | ||
]; | ||
const res = parser.run({ flow_type: "template", flow_name: "test_nested", rows }); | ||
const itemRows = res.rows[0].rows; | ||
const nestedNames = itemRows.map((n) => n._nested_name); | ||
expect(nestedNames).toEqual(["my_items.named_text", "my_items.text_2"]); | ||
}); | ||
}); | ||
|
||
describe("Template Parser [QC]", () => { | ||
// TODO - confirm what checks to include and add to code | ||
// it("Ensures answer_list parameters refer to list variables", () => { | ||
// }); | ||
}); |
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
27 changes: 0 additions & 27 deletions
27
packages/scripts/src/commands/app-data/convert/utils/app-data-string.utils.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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lines in the final if statement above throw some TypeScript errors. These are present on master too so not necessary to fix, but this could be an opportunity to do so (e.g. by asserting
as FlowTypes.IDynamicField
?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think asserting the type kinda overlooks the issue that the function isn't written very well given the ambiguous return depending on type of data input.
Given that trying to fix this here might have knock-ons for the outputs we're trying to review against I think better this handled in a follow-up PR instead. I'll try to draft something that can be merged after this and once debug content repo updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will follow-up in #2294