feat(app): show template stage counts
This commit is contained in:
@@ -67,6 +67,7 @@ class TemplatesScreen extends StatefulWidget {
|
||||
class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
late TemplateRepository _repository = TemplateRepository(widget.gateway);
|
||||
List<TemplateEntry> _templates = const [];
|
||||
Map<String, int?> _stageCounts = const {};
|
||||
bool _loading = true;
|
||||
bool _loaded = false;
|
||||
String? _error;
|
||||
@@ -91,6 +92,7 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
// selection while the replacement is read.
|
||||
_repository = TemplateRepository(widget.gateway);
|
||||
_templates = const [];
|
||||
_stageCounts = const {};
|
||||
_loaded = false;
|
||||
_selectedKey = null;
|
||||
unawaited(_load());
|
||||
@@ -107,8 +109,22 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
try {
|
||||
final templates = await _repository.listTemplates();
|
||||
if (!_owns(generation)) return;
|
||||
final stageCounts = <String, int?>{};
|
||||
for (final entry in templates) {
|
||||
try {
|
||||
final graph = await _repository.validate(entry.source);
|
||||
final stages = graph['stages'];
|
||||
stageCounts[entry.key] = stages is List ? stages.length : null;
|
||||
} catch (_) {
|
||||
// A refusal means the count is unknown, not that the template has
|
||||
// zero stages. The catalogue remains usable, as it does on the web.
|
||||
stageCounts[entry.key] = null;
|
||||
}
|
||||
if (!_owns(generation)) return;
|
||||
}
|
||||
setState(() {
|
||||
_templates = templates;
|
||||
_stageCounts = stageCounts;
|
||||
_loaded = true;
|
||||
_loading = false;
|
||||
final selected = _selectedKey;
|
||||
@@ -164,6 +180,7 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
final body = selected == null
|
||||
? TemplateGallery(
|
||||
templates: _templates,
|
||||
stageCounts: _stageCounts,
|
||||
loaded: _loaded,
|
||||
loading: _loading,
|
||||
error: _error,
|
||||
|
||||
@@ -24,6 +24,7 @@ class TemplateGallery extends StatelessWidget {
|
||||
const TemplateGallery({
|
||||
super.key,
|
||||
required this.templates,
|
||||
required this.stageCounts,
|
||||
required this.loaded,
|
||||
required this.loading,
|
||||
required this.error,
|
||||
@@ -32,6 +33,9 @@ class TemplateGallery extends StatelessWidget {
|
||||
});
|
||||
|
||||
final List<TemplateEntry> templates;
|
||||
|
||||
/// Parsed counts; a present null value means the source could not be parsed.
|
||||
final Map<String, int?> stageCounts;
|
||||
final bool loaded;
|
||||
final bool loading;
|
||||
final String? error;
|
||||
@@ -98,9 +102,7 @@ class TemplateGallery extends StatelessWidget {
|
||||
return ListTile(
|
||||
key: templateRowKey(entry.key),
|
||||
title: Text(templateGalleryName(entry)),
|
||||
subtitle: entry.description.trim().isEmpty
|
||||
? null
|
||||
: Text(entry.description),
|
||||
subtitle: _materialSubtitle(entry),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => onOpen(entry.key),
|
||||
);
|
||||
@@ -118,9 +120,7 @@ class TemplateGallery extends StatelessWidget {
|
||||
CupertinoListTile(
|
||||
key: templateRowKey(entry.key),
|
||||
title: _cupertinoText(templateGalleryName(entry)),
|
||||
subtitle: entry.description.trim().isEmpty
|
||||
? null
|
||||
: _cupertinoText(entry.description),
|
||||
subtitle: _cupertinoSubtitle(entry),
|
||||
trailing: const CupertinoListTileChevron(),
|
||||
onTap: () => onOpen(entry.key),
|
||||
),
|
||||
@@ -135,4 +135,38 @@ class TemplateGallery extends StatelessWidget {
|
||||
/// with the content and nothing else about the tile is restyled.
|
||||
Widget _cupertinoText(String text) =>
|
||||
DefaultTextStyle.merge(maxLines: 3, child: Text(text));
|
||||
|
||||
Widget _materialSubtitle(TemplateEntry entry) {
|
||||
final description = entry.description.trim().isEmpty
|
||||
? null
|
||||
: Text(entry.description);
|
||||
final count = Text(_stageCountLabel(entry.key));
|
||||
if (description == null) return count;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [description, count],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoSubtitle(TemplateEntry entry) {
|
||||
final description = entry.description.trim().isEmpty
|
||||
? null
|
||||
: _cupertinoText(entry.description);
|
||||
final count = _cupertinoText(_stageCountLabel(entry.key));
|
||||
if (description == null) return count;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [description, count],
|
||||
);
|
||||
}
|
||||
|
||||
String _stageCountLabel(String key) {
|
||||
if (!stageCounts.containsKey(key) || stageCounts[key] == null) {
|
||||
return 'stage count unavailable';
|
||||
}
|
||||
final count = stageCounts[key]!;
|
||||
return '$count ${count == 1 ? 'stage' : 'stages'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,10 @@ Future<void> openTemplates(
|
||||
},
|
||||
],
|
||||
});
|
||||
await reply(tester, channel, 'validate', listRead, {
|
||||
'type': 'graph',
|
||||
'graph': {'stages': <dynamic>[]},
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
@@ -279,7 +283,7 @@ void main() {
|
||||
await tester.tap(find.byKey(templateCreateConfirmKey));
|
||||
await tester.pump();
|
||||
|
||||
await reply(tester, channel, 'validate', 1, {
|
||||
await reply(tester, channel, 'validate', 2, {
|
||||
'type': 'graph',
|
||||
'graph': {'stages': <dynamic>[]},
|
||||
});
|
||||
@@ -334,7 +338,8 @@ void main() {
|
||||
// again adds no request.
|
||||
expect(requestsOf(channel, 'list_pipelines'), hasLength(2));
|
||||
expect(requestsOf(channel, 'list_runs'), hasLength(2));
|
||||
expect(requestsOf(channel, 'validate'), hasLength(1));
|
||||
// One validation derives the gallery count; the other belongs to Create.
|
||||
expect(requestsOf(channel, 'validate'), hasLength(2));
|
||||
expect(requestsOf(channel, 'submit'), hasLength(1));
|
||||
expect(sockets, 1);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(gateway.callsOf('validate'), isEmpty);
|
||||
expect(gateway.callsOf('validate'), hasLength(2));
|
||||
expect(gateway.callsOf('submit'), isEmpty);
|
||||
expect(created, isEmpty);
|
||||
|
||||
@@ -48,7 +48,8 @@ void main() {
|
||||
await tester.tap(find.byKey(templateCreateConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.callsOf('validate').single.fields, {'source': source});
|
||||
expect(gateway.callsOf('validate'), hasLength(3));
|
||||
expect(gateway.callsOf('validate').last.fields, {'source': source});
|
||||
expect(gateway.callsOf('submit').single.fields, {
|
||||
'name': 'Café',
|
||||
'source': source,
|
||||
@@ -93,7 +94,7 @@ void main() {
|
||||
await tester.tap(find.byKey(templateCreateConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.callsOf('validate'), hasLength(1));
|
||||
expect(gateway.callsOf('validate'), hasLength(3));
|
||||
expect(gateway.callsOf('submit'), hasLength(1));
|
||||
expect(
|
||||
find.text('Created "Created release". It is in the Pipelines list.'),
|
||||
|
||||
@@ -31,10 +31,31 @@ void main() {
|
||||
expect(find.byKey(templatesGalleryKey), findsOneWidget);
|
||||
expect(find.text('Release workflow'), findsOneWidget);
|
||||
expect(find.text('Ship a version'), findsOneWidget);
|
||||
expect(find.text('2 stages'), findsNWidgets(2));
|
||||
expect(find.text('(unnamed template)'), findsOneWidget);
|
||||
expect(find.byKey(templatesLoadingKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('stage count is unavailable when server parsing refuses', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway =
|
||||
GalleryGateway((type, fields) async => templatesReply(galleryTemplates))
|
||||
..validationHandler = (type, fields) async {
|
||||
throw Exception('invalid definition');
|
||||
};
|
||||
|
||||
await pumpGallery(tester, gateway);
|
||||
|
||||
expect(find.text('stage count unavailable'), findsNWidgets(2));
|
||||
expect(find.text('0 stages'), findsNothing);
|
||||
expect(gateway.callsOf('validate'), hasLength(2));
|
||||
expect(
|
||||
gateway.callsOf('validate').first.fields['source'],
|
||||
galleryTemplates.first['source'],
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('an empty catalogue states it without inventing rows', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -148,7 +169,11 @@ void main() {
|
||||
expect(selectableSource(source), findsOneWidget);
|
||||
expect(selectableSource('release'), findsOneWidget);
|
||||
expect(find.text(templateCreateActionLabel), findsOneWidget);
|
||||
expect(gateway.callsOf('validate'), isEmpty);
|
||||
expect(gateway.callsOf('validate'), hasLength(2));
|
||||
expect(
|
||||
gateway.callsOf('validate').map((call) => call.fields['source']),
|
||||
everyElement(source),
|
||||
);
|
||||
expect(gateway.callsOf('submit'), isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(templatesBackKey));
|
||||
|
||||
@@ -17,11 +17,22 @@ class GalleryGateway implements ApiGateway {
|
||||
|
||||
final GalleryHandler handler;
|
||||
final List<({String type, JsonMap fields})> calls = [];
|
||||
GalleryHandler? validationHandler;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
final copy = Map<String, dynamic>.from(fields);
|
||||
calls.add((type: type, fields: copy));
|
||||
if (type == 'validate' && validationHandler != null) {
|
||||
return validationHandler!(type, copy);
|
||||
}
|
||||
if (type == 'validate') {
|
||||
return {
|
||||
'graph': {
|
||||
'stages': [{}, {}],
|
||||
},
|
||||
};
|
||||
}
|
||||
return handler(type, copy);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,11 @@ class _ProbeGateway implements ApiGateway {
|
||||
publish();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||
return {
|
||||
'graph': {'stages': const []},
|
||||
'graph': {
|
||||
'stages': const [
|
||||
{'key': 'release'},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
if (type == 'submit') {
|
||||
|
||||
@@ -241,7 +241,7 @@ try {
|
||||
await clickLabel('Release workflow', { contains: true });
|
||||
await assertBody('Definition source');
|
||||
const before = await state();
|
||||
if (before?.listCalls !== 1 || before?.validates !== 0 || before?.submits !== 0) {
|
||||
if (before?.listCalls !== 1 || before?.validates !== 2 || before?.submits !== 0) {
|
||||
throw new Error(`Opening the template made unexpected requests: ${JSON.stringify(before)}`);
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ try {
|
||||
await assertBody('Definition source');
|
||||
await assertBody('Create pipeline from this template');
|
||||
const refused = await state();
|
||||
if (refused?.listCalls !== 2 || refused?.validates !== 0 || refused?.submits !== 0) {
|
||||
if (refused?.listCalls !== 2 || refused?.validates !== 2 || refused?.submits !== 0) {
|
||||
throw new Error(`The failed refresh did not stay read-only: ${JSON.stringify(refused)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-detail-refresh-error`));
|
||||
@@ -286,6 +286,7 @@ try {
|
||||
await assertBody('Release workflow');
|
||||
await assertBody('(unnamed template)');
|
||||
await assertBody('Ship a version');
|
||||
await assertBody('1 stage');
|
||||
const gallery = await state();
|
||||
if (gallery?.listCalls !== 2) {
|
||||
throw new Error(`Retry did not re-read exactly once: ${JSON.stringify(gallery)}`);
|
||||
@@ -299,7 +300,7 @@ try {
|
||||
await assertBody('Includes a schedule');
|
||||
await assertBody('Create pipeline from this template');
|
||||
const detail = await state();
|
||||
if (detail?.validates !== 0 || detail?.submits !== 0) {
|
||||
if (detail?.validates !== 2 || detail?.submits !== 0) {
|
||||
throw new Error(`Opening a template sent a write: ${JSON.stringify(detail)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-detail`));
|
||||
@@ -310,7 +311,7 @@ try {
|
||||
await clickLabel('Refresh');
|
||||
await assertBody('Added after refresh');
|
||||
const refreshed = await state();
|
||||
if (refreshed?.listCalls !== 3) {
|
||||
if (refreshed?.listCalls !== 3 || refreshed?.validates !== 5) {
|
||||
throw new Error(`Refresh made unexpected requests: ${JSON.stringify(refreshed)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-refreshed`));
|
||||
@@ -326,7 +327,7 @@ try {
|
||||
await clickLabel('Cancel');
|
||||
await waitFor(async () => !(await semanticText()).includes('Create from Release workflow'), 'the prompt to close');
|
||||
const cancelled = await state();
|
||||
if (cancelled?.validates !== 0 || cancelled?.submits !== 0 || cancelled?.created?.length !== 0) {
|
||||
if (cancelled?.validates !== 5 || cancelled?.submits !== 0 || cancelled?.created?.length !== 0) {
|
||||
throw new Error(`Cancel sent a request: ${JSON.stringify(cancelled)}`);
|
||||
}
|
||||
checks.push({ check: 'Cancel sent nothing', state: cancelled });
|
||||
@@ -341,7 +342,7 @@ try {
|
||||
await clickLabel('Create');
|
||||
await assertBody('Created "Probe created". It is in the Pipelines list.');
|
||||
const created = await state();
|
||||
if (created?.validates !== 1 || created?.submits !== 1 || created?.created?.length !== 1) {
|
||||
if (created?.validates !== 6 || created?.submits !== 1 || created?.created?.length !== 1) {
|
||||
throw new Error(`The accepted create was not reported exactly once: ${JSON.stringify(created)}`);
|
||||
}
|
||||
if (created.lastSubmit?.name !== 'Probe release' || created.lastSubmit?.create_only !== true) {
|
||||
|
||||
Reference in New Issue
Block a user