Skip to content
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/set data action #2454

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft

Conversation

chrismclarke
Copy link
Member

@chrismclarke chrismclarke commented Oct 3, 2024

PR Checklist

  • PR title descriptive (can be used in release notes)

TODO

  • Fix data items component to render from received template data (currently with this.item reference instead of @item)
  • Continue refactor of data-actions spec tests

Blocking
The system works when managing @items references, however an initial pass on item processing is handled in the main processor which also replaces @item with this.item references. Whilst it is possible to just add a hackUnparseItem method, this feels messy. Instead it would be better to improve the item handling at the parser level, to avoid replacing outside of the item processor. The challenge here is that the initial items template processor is reasonably untested and quite fragile, so changing as part of this PR isn't advisable

Due to the closely coupled nature of the parser and items the best solution appears to be to mostly detach the data_items
parsing from the template parser, and essentially handle it's own parsing from the ground up. Whilst it is still possible to expose and call methods from the current parser (e.g. processDynamicEvaluators), these methods themselves are quite hacky and have a number of issues (particularly regarding the way dynamic variables are replaced as strings one-by-one, making it harder to evaluate compound expressions, e.g. @row.first_name === 'Ada' replaces first_name without quotation).

However a full solution for this will likely involve creating a new base parser that can convert full expressions to valid js and evaluate. E.g.
Hello @field.{@local.lookup_field}}

->
"Hello+' '+[field[local.lookup_field]]"
or
`Hello ${field[local.lookup_field]}`

Description

Re-implementation of #2388, to use set_data action globally and update set_item / set_items actions in data_items list to call the global function.

It also includes better test coverage, and support for items with dynamic expressions, such as global `set_da

Author Notes

General Use
Set values on a specific data_list item

click | set_data | _list_id: example_list, _id: example_id, completed:true, count: 1;

Can include @item reference that will use existing row context

click | set_data | _list_id: example_list, _id: example_id, count: @item.count + 1;

Can set item by _index

click | set_data | _list_id: example_list, _index: 0, completed:false;

Can target all items in a list (no current support for filtered subset) by omitting _id

click | set_data | _list_id: example_list, completed: true;

Dev Notes

Git Issues

Closes #

Screenshots/Videos

If useful, provide screenshot or capture to highlight main changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants