ensureCrudFormSubmit method

void ensureCrudFormSubmit({
  1. required String page,
  2. required BrownfieldPatternTarget submit,
  3. required Endpoint endpoint,
  4. required Map<String, Object?> params,
  5. List<DslAction> onSuccess = const <DslAction>[],
  6. List<DslAction> onFailure = const <DslAction>[],
  7. FFActionTriggerType triggerType = FFActionTriggerType.ON_TAP,
})

Attaches a CRUD form submit API call to an existing submit trigger.

This validates endpoint params up front so agent mistakes fail locally before push.

Implementation

void ensureCrudFormSubmit({
  required String page,
  required BrownfieldPatternTarget submit,
  required Endpoint endpoint,
  required Map<String, Object?> params,
  List<DslAction> onSuccess = const <DslAction>[],
  List<DslAction> onFailure = const <DslAction>[],
  FFActionTriggerType triggerType = FFActionTriggerType.ON_TAP,
}) {
  raw((project) {
    final editor = _pagePatternEditor(page);
    final pageSnapshot = _requirePagePatternSnapshot(project, page);
    final submitRef = _resolvePatternTarget(
      pageSnapshot,
      editor,
      submit,
      operation: 'ensureCrudFormSubmit(submit: ...)',
    );
    _validateEndpointParams(
      endpoint,
      params,
      operation: 'ensureCrudFormSubmit',
    );

    editor.ensureActions(
      _selectionForResolvedTarget(editor, submitRef),
      triggerType: triggerType,
      actions: [
        ApiCall(
          endpoint,
          params: params,
          onSuccess: (_) => onSuccess,
          onFailure: onFailure,
        ),
      ],
    );
    _applyBrownfieldWidgetClassEdit(project, editor);
  });
}