IDEMSInternational / open-app-builder

PLH App Frontend
GNU General Public License v3.0
5 stars 24 forks source link

feat: add calc function: merge_sub_arrays #2124

Closed jfmcquade closed 10 months ago

jfmcquade commented 10 months ago

PR Checklist

Description

Adds a new function available in all @calc() blocks: merge_sub_arrays(). This is a hack to expose some particular array manipulation logic to authors, for a specific purpose in the upcoming plh_facilitator_my deployment release.

merge_sub_arrays() takes 3 arguments: an array of arrays (expected to be a partition of a set) and 2 values that appear in sub-arrays. The function looks for the sub-array containing one value and merges it with the sub-array containing another, returning a mutation of the original partition. See screenshots and debug sheets below for usage.

Notes

I initially tried writing the function in a data list and referring to it in a @calc() block. See debug_functions_data_list and debug_calc_functions

Screenshot 2023-11-03 at 10 37 53 Screenshot 2023-11-03 at 10 39 17

However, this approach does not work as the evaluated string from @calc() gets returned in the resulting javascript, so additional functions cannot be defined. Further thought is required to enable authors to write functions in data lists and call them in @calc() blocks, see #2121.

Screenshot 2023-11-03 at 10 12 06

Git Issues

Closes #

Screenshots/Videos

See debug_calc_functions template for usage

Screenshot 2023-11-03 at 10 37 03 Screenshot 2023-11-03 at 10 37 17