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

Add unique key to Action component #5127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

viktorvanwijk
Copy link
Contributor

Closes #5040

Changes

Added a unique key to the Action component.

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages_js.sh
    • Ran ./bin/compilemessages_js.sh
  • Dockerfile/scripts

    • Updated the Dockerfile with the necessary scripts from the ./bin folder
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

…same trigger

When two variable-set actions are configured for the same trigger, deleting the first action will result in the second one getting the JSON-logic value of the first one.
Keys tell React which array item each component corresponds to, so that it can match them up later. They must be unique, see https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key

Previously, the key was set to the index of the action as it occurred in the actions array. After deletion of an action, the ActionSet would be regenerated, and the keys for the actions will start counting from 0 again. This means the keys were not unique, and it created unexpected behaviour when deleting an action.

Now, each Action will get a unique key using getUniqueRandomString.
@viktorvanwijk viktorvanwijk force-pushed the bug/5040-delete-one-of-multiple-logic-actions-in-same-trigger branch from 12aa225 to d3fcb25 Compare February 27, 2025 15:31
@viktorvanwijk
Copy link
Contributor Author

According to the docs:

Rather than generating keys on the fly, you should include them in your data

I have considered doing this by adding a (uu)id to EMPTY_ACTION, but this would require it to be saved in FormLogic.actions field, and I wasn't confident that was the way to go

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.75%. Comparing base (43c6df6) to head (d3fcb25).
Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5127      +/-   ##
==========================================
+ Coverage   96.73%   96.75%   +0.01%     
==========================================
  Files         775      777       +2     
  Lines       26664    26724      +60     
  Branches     3469     3474       +5     
==========================================
+ Hits        25794    25856      +62     
+ Misses        608      606       -2     
  Partials      262      262              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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