-
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
Feat: set data action standalone #2513
Conversation
Visit the preview URL for this PR (updated for commit a75b533): https://plh-teens-app1--pr2513-feat-set-data-action-fga52kw1.web.app (expires Tue, 03 Dec 2024 00:16:04 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: e4c0bab6b08dd290fbf002fd6e07987fa4b5fce1 |
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.
Functional test passed. I still don't particularly like the syntax
click | set_data |
_list_id: feat_data_actions_list,
_index: @local.last_index,
completed:!@item.completed
because the conditions (_list_id: feat_data_actions_list, _index: @local.last_index,
) and the action that should happen when the conditions are satisfied (completed:!@item.completed
) appear in the same list - but appreciate it might be the most straightforward way that respects our conventions so far.
We previously said set_data would be the preferred name for actions to align with
set_field
,set_local
etc. Although do we still want to keep this convention given we will likely need several follow-up actions, namely:
set_data, reset_data, insert_data, remove_data
This naming makes sense to me and seems consistent (also reset_field
and remove_field
could make sense as operations - I don't have an immediate use case though).
For now authors can still use set_item, but be aware it uses different code to the set_data action and so might behave slightly differently.
Noted.
As such it means the first row of any data_list currently needs to contain values for this to work correctly. It might be worth creating a follow-up issue to provide alternate ways to define the schema of a data_list, for example allowing a top-row metadata row that just specifies data types.
Noted, follow-up issue here.
The main reason for keeping it limited to everything in a 3rd argument is so that the
If we move to using 4 arguments by default then
I'm not totally opposed to this, but then it does raise the question if we start to add more functionality (like filter/limit operations) whether we keep adding on more arguments. In the past I've found going over 3 arguments to get pretty confusing, but ultimately we're trying to include a huge amount of information in a single cell so never going to be perfect. Another option might even to be having a dedicated data_list subtype
Where essentially the list can use named columns that will just be passed as ordered arguments (although this gets suuuper confusing if still referring to things in the local template).
Sounds good
Thanks |
Slight issue although may be with tasks and not this. The problem comes with the multiple datalists that need to be maintained to allow tasks to work and that we don't want to be restrictive on sub levels. Therefore the action (completed = completed[user_group]) needs to run on an unspecified number of datalists (i.e. Modules, Modules_[sub_module] x Number of sub-modules, Modules_[sub_module]_[sub_sub_module] ..) Possible solutions:
Personally, I would like the ability to do both of these. Option 1 feels the better solution for this issue as it lowers the complexity of generating multiple datalists. The 2nd option would mean that any datalist actions can be centralised as there may be multiple places we want to perform the same action. |
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.
Looks good, really nice to have the tests and demo templates. I've run the tests manually with positive results.
Question
We previously said set_data would be the preferred name for actions to align with set_field , set_local etc. Although do we still want to keep this convention given we will likely need several follow-up actions, namely:
set_data, reset_data, insert_data, remove_data
vs
data_set, data_reset, data_insert, data_remove
I don't have a strong opinion here, I can see advantages to each. I suppose another option would be to separate the actions within a "data" namespace, so they were called like:
click | data: set | _list_id: feat_data_actions_list, _index: @local.last_index, completed: false;
click | data: reset | _list_id: feat_data_actions_list, _index: @local.last_index, completed: false;
click | data: insert | _list_id: feat_data_actions_list, _index: @local.last_index, completed: false;
etc.
This would still be breaking from the implied convention of set_field
, set_local
etc.
@@ -100,8 +100,7 @@ export function isEqual(a: any, b: any) { | |||
if (!isEqual(Object.keys(aSorted), Object.keys(bSorted))) return false; | |||
return isEqual(Object.values(aSorted), Object.values(bSorted)); | |||
} | |||
// could not compare (e.g. symbols, date objects, functions, buffers etc) | |||
console.warn(`[isEqual] could not compare`, a, b); |
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.
@esmeetewinkel noticed that this warning has been appearing, see #2528. I can't understand what's causing this as the comparison appears to be between two strings. It doesn't seem to cause any problems for functionality, but just flagging here
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.
Yeah the console log is wrong as up till this point we've checked:
- strict equivalent (a===b) \ true
- different types \ false
- equivalent arrays and equivalent object literals \ true
so what we are left with are non-equivalent but same type (strings, numbers etc.), or additional primative types not already checked (e.g. date objects, bigints etc.).
So if we wanted we could add a type check for string, number and boolean types and confidently return false
, and then add a log just to catch other types; but for now I've just dropped the log and added a note on the function limitation. I don't see this being of practical consequence as there's currently no way to construct other primitive types from the code.
it("set_data ignores evaluation when _updates provided", async () => { | ||
const params: IActionSetDataParams = { _updates: [{ id: "id_0", number: "@item.number" }] }; | ||
const data = await triggerTestSetDataAction(service, params); | ||
// test case illustrative only of not parsing data (would have been parsed independently) |
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.
So the point of this test case is just to demonstrate that using the _updates
param (which should only be considered from within the code) requires any dynamic values to be evaluated already?
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.
Yes, part of the idea with the parallel work on items
loops is that the item loop handles all its own data update processing (it already has an active data_list query subscription, so doesn't to run a single db query like a regular set_data
operation needs to).
Although part of me is thinking that this inefficiency might actually be better just to simplify the set_items
handling, and given that the data_list query is only making a single call to in-memory db so really not an expensive operation to duplicate. So I might decide to remove this functionality in a follow-up PR, but for now it does act as a bypass.
if (isObjectLiteral(params)) { | ||
const parsed = this.hackParseTemplatedParams(params); | ||
let { _updates, _list_id } = parsed; | ||
console.log("params", { params, parsed }); |
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.
debug log could be tidied or removed
Yeah I think at this point I think the more natural way of expression an action like |
@chrismclarke Am I right in thinking there is no way to dynamically specify the field to update i.e. also when using a combobox |
Referring to the |
I have just got the combobox to work and was coming back to delete my message before anyone saw it. Still having issues with setting field dynamically but, again, this could be an issue my side |
I've just tested this use-case and can confirm it is not currently working. I'll raise a PR to address |
PR Checklist
Description
Add actions to support data_list manipulation from outside of
data_items
context loops, originally discussed in RFC 21. Data ActionsThis PR originally started in #2454, but has been separated out. This does not include any changes to
set_item
syntax ordata_items
loop handling (will be addressed in follow-ups)Main Changes
set_data
actionreset_data
actionAdditional Changes
Future Follow-ups
insert_data
actionremove_data
actionhackParseTemplatedParams
method added (requires update to items loop code)Author Notes
Syntax
See examples in sheet feat_data_actions
Question
We previously said
set_data
would be the preferred name for actions to align withset_field
,set_local
etc. Although do we still want to keep this convention given we will likely need several follow-up actions, namely:set_data
,reset_data
,insert_data
,remove_data
vs
data_set
,data_reset
,data_insert
,data_remove
Key Point
This PR does not change how data_lists are updated from within
data_items
loops. For now authors can still useset_item
, but be aware it uses different code to theset_data
action and so might behave slightly differently. Follow-up PRs are planned to unify the handling so that theset_item
code can function in the same way asset_data
, using the context of the item loop to set default_list_id
and_id
variables for the item (so author only needs to write explicit values to update)Key Point
When setting data from a parameter_list, by default all the key-value pairs defined in the parameter list are parsed as strings (unless set as an intermediate local variable first). As this has high potential to confuse authoring, additional code has been added to try and convert the string into the correct data type, using the original data_list as source of which columns contain which type of data. As such it means the first row of any data_list currently needs to contain values for this to work correctly. It might be worth creating a follow-up issue to provide alternate ways to define the schema of a data_list, for example allowing a top-row metadata row that just specifies data types.
Review Notes
Functional test of feat_data_actions
For code tests, see updated specs (will need to run individually)
Dev Notes
This includes quite a few updates to tests, however as the angular tests are still not built into CI (due to #2196) they all need to be run manually. As we continue to work on refactoring service code it would be really useful to get these tests unblocked so that we can identify any regressions introduced.
A few of the mock tests have been moved to their own folder instead of the original spec file just so that the corresponding tests aren't triggered when importing from the file (looks like there's a few tests that will have been broken recently, likely with changes to deployment and app config - but beyond scope to fix). So again, would be good to get the full angular test suite passing so that we can include in CI
Some of the existing code and tests within the
dynamic-data.service
file has been migrated into the newdata-actions.service
, and further developed from there. This is to try and keep code a little bit more separated and easy to iterate onI remember some of the initial discussion for the
set_data
action started in #2388, however I lost track of that PR when creating the various follow-ups. So I'm assuming the code here (and in other draft PRs) should supercede, but I'll hold off closing that for now until I do another follow-up on data_items lists in #2454While developing I realised the issue with all parameter_list values being parsed as strings and added the workaround to coerce data types. I think generally this is useful to have and could be build on in the future to include more things like data validation (or any other rxdb schema options that we want to expose to authors). I haven't tried to address object or array types as I don't think there's a way for authors to include those data_types in lists (although maybe if a column ends
_list
...?). I think more advanced data type handling could possibly be saved for follow-upYou'll notice I've update the
resetFlow
method of thedynamic-data.service
. Previously the method would delete the entire table and recreate from scratch. The problem with doing this when resetting data is that any existing data subscriptions also get destroyed, so thedata-items
component would somehow need to know to resubscribe once recreated. Instead it now deletes all rows and repopulates. This is more desirable than just trying to reverting values within existing rows for future cases where we have the ability to append new rows.Git Issues
Closes #
Screenshots/Videos
Screenity.video.-.Nov.9.2024.webm