shouldUpdateLocalExtraProperty static method

bool shouldUpdateLocalExtraProperty(
  1. String incomingPropertyKey,
  2. TBLExtraPropertyWithLevel incomingExtraProperty,
  3. Map<String, TBLExtraPropertyWithLevel> targetExtraProperties
)

Determines if a local extra property should be updated.

Returns true if:

  1. Property doesn't exist → always update
  2. Incoming is page-level → can override anything (if value differs)
  3. Incoming is global-level → can only override global, NOT page

Note: Unit-level properties only exist in unitExtraProperties, not in page/global maps. This ensures that page-level properties are not overridden by global updates.

Implementation

static bool shouldUpdateLocalExtraProperty(
    String incomingPropertyKey,
    TBLExtraPropertyWithLevel incomingExtraProperty,
    Map<String, TBLExtraPropertyWithLevel> targetExtraProperties) {
  final targetExtraPropertyWithIncomingKey = targetExtraProperties[incomingPropertyKey];

  // If property doesn't exist, always update
  if (targetExtraPropertyWithIncomingKey == null) {
    return true;
  }

  // If incoming is page-level, it can override anything (if value differs)
  if (incomingExtraProperty.level == TBLExtraPropertyLevel.page) {
    return _isPropertyValueDifferentThanExisting(
        targetExtraPropertyWithIncomingKey.value, incomingExtraProperty.value);
  }

  // Incoming is global-level
  // Global cannot override page-level properties (page has higher priority)
  if (targetExtraPropertyWithIncomingKey.level == TBLExtraPropertyLevel.page) {
    return false;  // Reject the global update
  }

  // Both existing and incoming are global-level - update if value differs
  return _isPropertyValueDifferentThanExisting(
      targetExtraPropertyWithIncomingKey.value, incomingExtraProperty.value);
}