mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Implement trigger formulas (generalizing default formulas)
Summary: Trigger formulas can be calculated for new records, or for new records and updates to certain fields, or all fields. They do not recalculate on open, and they MAY be set directly by the user, including for data-cleaning. - Column metadata now includes recalcWhen and recalcDeps fields. - Trigger formulas are NOT recalculated on open or on schema changes. - When recalcWhen is "never", formula isn't calculated even for new records. - When recalcWhen is "allupdates", formula is calculated for new records and any manual (non-formula) updates to the record. - When recalcWhen is "", formula is calculated for new records, and changes to recalcDeps fields (which may be formula fields or column itself). - A column whose recalcDeps includes itself is a "data-cleaning" column; a value set by the user will still trigger the formula. - All trigger-formulas receive a "value" argument (to support the case above). Small changes - Update RefLists (used for recalcDeps) when target rows are deleted. - Add RecordList.__contains__ (for `rec in refList` or `id in refList` checks) - Clarify that Calculate action has replaced load_done() in practice, and use it in tests too, to better match reality. Left for later: - UI for setting recalcWhen / recalcDeps. - Implementation of actions such as "Recalculate for all cells". - Allowing trigger-formulas access to the current user's info. Test Plan: Added a comprehensive python-side test for various trigger combinations Reviewers: paulfitz, alexmojaki Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2872
This commit is contained in:
@@ -65,6 +65,19 @@ class IdentityRelation(Relation):
|
||||
# test_dependencies_relations_bug for a detailed description of a bug this can cause.]
|
||||
|
||||
|
||||
class SingleRowsIdentityRelation(IdentityRelation):
|
||||
"""
|
||||
Represents an identity relation, but one which refuses to pass along ALL_ROWS. In other words,
|
||||
if a full column changed (i.e. ALL_ROWS), none of the dependent cells will be considered
|
||||
changed. But when specific rows are changed, those changes propagate.
|
||||
|
||||
This is used for trigger formulas, to ensure they don't recalculate in full when a dependency
|
||||
column is renamed or modified (as opposed to particular records).
|
||||
"""
|
||||
def get_affected_rows(self, input_rows):
|
||||
return [] if input_rows == depend.ALL_ROWS else input_rows
|
||||
|
||||
|
||||
class ComposedRelation(Relation):
|
||||
"""
|
||||
Represents a composition of two Relations. E.g. if referring side maps Students to Schools, and
|
||||
@@ -107,6 +120,8 @@ class ReferenceRelation(Relation):
|
||||
def get_affected_rows(self, input_rows):
|
||||
# Each input row (target of the reference link) may be pointed to by multiple references,
|
||||
# so we need to take the union of all of those sets.
|
||||
if input_rows == depend.ALL_ROWS:
|
||||
return depend.ALL_ROWS
|
||||
affected_rows = set()
|
||||
for target_row_id in input_rows:
|
||||
affected_rows.update(self.inverse_map.get(target_row_id, ()))
|
||||
|
||||
Reference in New Issue
Block a user