e69883b5b6
Validate the template source first, then submit the typed name create-only, matching the browser's P5 flow and wording. Refusals keep the prompt and the typed name; the accepted detail is reported once through the callback. The labelled field, visible feedback and native Material/Cupertino controls are covered by focused widget tests and a loopback browser probe.
43 lines
1.8 KiB
Dart
43 lines
1.8 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../domain/template_entry.dart';
|
|
|
|
/// The browser client's create-from-template wording, kept verbatim.
|
|
const templateCreateNameLabel = 'New pipeline name (required)';
|
|
const templateCreateNote =
|
|
"Creates a new draft pipeline on the server from this template's source; it is not run.";
|
|
const templateCreateConfirmLabel = 'Create';
|
|
const templateCreateSendingLabel = 'Creating…';
|
|
const templateCreateCancelLabel = 'Cancel';
|
|
const templateCreateCloseLabel = 'Close';
|
|
|
|
/// Stable test/semantics keys for the prompt.
|
|
const templateCreateNameKey = ValueKey<String>('template-create-name');
|
|
const templateCreateConfirmKey = ValueKey<String>('template-create-confirm');
|
|
const templateCreateCancelKey = ValueKey<String>('template-create-cancel');
|
|
const templateCreateErrorKey = ValueKey<String>('template-create-error');
|
|
const templateCreateSuccessKey = ValueKey<String>('template-create-success');
|
|
|
|
/// `Create from {name}`, a blank name falling back to the template key.
|
|
String templateCreateTitle(TemplateEntry template) =>
|
|
'Create from ${template.name.trim().isNotEmpty ? template.name : template.key}';
|
|
|
|
/// The server's own created name, else the submitted name, trimmed.
|
|
String templateCreatedName(JsonMap detail, String submittedName) {
|
|
final name = '${detail['name'] ?? ''}'.trim();
|
|
return name.isNotEmpty ? name : submittedName.trim();
|
|
}
|
|
|
|
/// `Created "{name}". It is in the Pipelines list.` — the browser's exact line.
|
|
String templateCreateSuccess(String created) =>
|
|
'Created "$created". It is in the Pipelines list.';
|
|
|
|
/// The server's refusal, verbatim; only a blank reason gets a generic sentence.
|
|
String describeTemplateCreateError(Object error) {
|
|
final message = '$error';
|
|
return message.trim().isEmpty
|
|
? 'The server did not create the pipeline.'
|
|
: message;
|
|
}
|