Let upsertViewWidget clear filter group fields with null

Merged
FE
2d ago
+338-57

Alternative to #30480. It fixes the same bug and also makes null mean "clear" in upsertViewWidget, so it follows the convention of the other metadata update paths. Merge one of the two.

Problem

In ViewWidgetUpsertService, the filter and filter-group update branches used ??. Omitting a field and sending null therefore both kept the saved value:

  • a filter could not be taken out of its group, and a nested group could not be moved back to the root;
  • on top of that, the saved group was lost when the field was omitted, because the universal identifier was resolved from the input (undefined → null) and not from the value being kept. That's the bug #30480 fixes.

The rest of the metadata API (updateViewFilter, updateViewFilterGroup, updateView, … via mergeUpdateInExistingRecord), and even the view-field branch of this same service (aggregateOperation), already treat omitted as keep and null as clear.

Changes

  • ViewWidgetUpsertService: in the filter and filter-group update branches, viewFilterGroupId, positionInViewFilterGroup, subFieldName, relationTargetFieldMetadataId and parentViewFilterGroupId go through mergeUpdateInExistingRecord. The merged values feed the change check, the universal identifier lookup and the update. operand and logicalOperator are non-nullable and still fall back with ??, but the change check now compares the effective value, so omitting them no longer counts as a change.
  • Behaviour change: relationTargetFieldMetadataId used to be cleared when omitted. It is now kept.
  • Conflicting requests are rejected. A request that keeps a filter in a group it is removing, or keeps a group under a parent it is removing, now fails with INVALID_VIEW_DATA. Before, removing the group cascade-deleted the kept filter or sub-group even though the input still listed it. The UI never sends such a request: rule groups only exist one level under the root, and removing a group removes its contents.
  • Input DTOs: these fields are typed | null, with an explicit GraphQL type (Float/String) because reflection can't infer a union. The GraphQL schema is unchanged.
  • useSaveRecordTableWidgetViews: it sends the full draft, so a cleared field now goes out as null instead of undefined. Without this, a filter taken out of its group would stay in it, and relationTargetFieldMetadataId could no longer be cleared. On the current server, null behaves the same as undefined, so a frontend deployed before the server is harmless.

Testing

  • Integration upsert-view-widget: 27/27 pass. Four new tests:

    • a filter keeps its group when the field is omitted, and leaves it on null;
    • a nested group keeps its parent when the field is omitted, and moves to the root on null;
    • keeping a filter in a group that is being removed is rejected, and the filter is left untouched;
    • keeping a group under a parent that is being removed is rejected, and both groups are left untouched.

    Each fails without its change.

  • Unit useSaveRecordTableWidgetViews: 2/2 pass, including the check that cleared fields are sent as null.

  • Typecheck (tsgo) and oxlint/oxfmt pass on the changed files.


Generated by Claude Code