-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat!: data items local #2772
feat!: data items local #2772
Conversation
…nal/open-app-builder into feat/data-items-local
…international/open-app-builder into feat/data-items-local
…international/open-app-builder into feat/data-items-local
@chrismclarke thanks for the example, I wasn't aware of the syntax This almost works for my use case, only that there seems to be some sort of order-of-rendering issue:
Screenity.video.-.Feb.20.2025.1.webm
Screenity.video.-.Feb.20.2025.webm |
That makes sense, as the data-items will only correctly update after being rendered for the first time, prompting a quick re-render after first evaluation. If moving to a
HOWEVER - the one issue with doing this is that if all the modules are completed then there would be no current_module_id as evaluated as first non-completed, and no content would show. So we need an additional to identify the case where all modules are completed, or at least to know the difference between current module being undefined due to all completed vs not yet evaluated. In this case I think it makes most sense to add a
Sidenote I've updated the demo to remove the unused So hopefully that should be closer to what you need, but let me know if anything doesn't fully make sense or isn't working as you want it to. |
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 updates in e0e25f7 make sense, and good to see the final authoring patterns in module_path_debug looking pretty neat.
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.
Thanks @chrismclarke, that works!
as we're not including any inner items for the data_items loop, we don't actually need the begin/end statement. This might be a nicer way to implement item loops used for querying, as the syntax could later just be swapped out for data_query or whatever we settle on
I hadn't realised this was possible (so thanks for pointing out), makes sense.
I've also added an intermediate unlocked variable (as that's the main purpose of this PR :p ), which simplifies some of the other conditions a bit.
I also had that at first, but the non-debug template for some reason doesn't work when the condition is put in an intermediate variable. No clue why but no strict need to get to the bottom of right now...
Overall the authoring pattern feels pretty nice to me, so might be good to copy across some to the comp_data_items example
Done, see example_data_actions
PR Checklist
TODO
example_auth
Feat!: auth restore data #2795Description
Add support for creating local variables within a data_items loop
Breaking changes
@jfmcquade:
These changes may break some functionality that relies upon evaluating local variables in order within a data-items loop, and persisting these changes across multiple iterations within the loop. These authoring patterns were never explicitly supported, and refactoring to use the new functionality would be desirable, but it's possible there are cases of production deployments that will need to be updated if targeting a code version including these changes.
Author Notes
Now any
set_variable
(or unnamed) row types within a data_items loop will create a temporary variable, available only within that loop. This can be used to generate more complex expressions to include within templated child rowsAs a side-effect, more complex data can be used within data_items loops via intermediate variables, e.g. example_auth can now show app theme via nested
@item.contact_fields["rp-contact-field._app_theme"]
Review Notes
A new comp_data_items_dev sheet has been created for the purpose of testing. Once in a good state could ideally be merged into main comp_data_items sheet (or renamed and linked from the comp_data_items sheet)
Should also check whether addresses issue in original issue
There is some scope for knock-on to data_items sheets more generally, so would be good to cross-check any advanced authoring examples. There are fairly comprehensive examples in
comp_data_items
andfeat_data_actions
- I've gone through each of these and they appear to be working as expected, but would be good to get a second pass.I've also triggered a new set of screenshots generated on
master
to compare with this PR and the only thing that stands out to me as related todata_items
isdebug_data_items_condition
sheet which appears broken on master and maybe fixed a bit on this branch (didn't look at the sheet itself as assuming it's an old sheet)Dev Notes
This PR further decouples the
data-items
system from the rest of templating. It no longer processes item loops using the sameItemProcessor
(but does use the processor to pipe operators like filter, sort etc.). This is because local context requires data-items to process in chunks by item (so that local context can be reset between evaluation), but itemProcessor outputs a single array of all processed items. So new methods have been added to thedata_items
service and utils to handle row generation and processing in a more linear way.Handling support for
@calc(...)
statements within the data-items local variables was complicated, as up till now the newAppDataEvaluator
hasn't had to deal with them. As a short term solution these expressions are being explicitly checked for and handled separately, but in the future it might be useful to consider how this should interoperate with the rest of the templated data system. Ideally methods to extract lists of local variables used should also be able to extract any calc references along with list of global functions used within the expression. All of this should ideally happen at the parser level, however that is beyond the scope of this PRGit Issues
Closes #2766
Screenshots/Videos
comp_data_items_dev
Example - data_item loop now able to show deep nested contact field
