feat(app): a pipeline's Run and Runs are floating action buttons
This commit is contained in:
@@ -24,8 +24,12 @@ class RunPipelineAction extends StatefulWidget {
|
||||
required this.detail,
|
||||
required this.gateway,
|
||||
this.onRunStarted,
|
||||
this.fab = false,
|
||||
});
|
||||
|
||||
/// A floating action button instead of an inline button.
|
||||
final bool fab;
|
||||
|
||||
final PipelinesController controller;
|
||||
final PipelineDetail detail;
|
||||
final ApiGateway gateway;
|
||||
@@ -165,6 +169,17 @@ class _RunPipelineActionState extends State<RunPipelineAction> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final label = const Text(runPipelineActionLabel);
|
||||
if (widget.fab) {
|
||||
return pipelineFab(
|
||||
context,
|
||||
key: runPipelineActionKey,
|
||||
primary: true,
|
||||
materialIcon: Icons.play_arrow,
|
||||
cupertinoIcon: CupertinoIcons.play_fill,
|
||||
label: runPipelineActionLabel,
|
||||
onPressed: _open,
|
||||
);
|
||||
}
|
||||
if (useCupertinoControls(context)) {
|
||||
return CupertinoButton.filled(
|
||||
key: runPipelineActionKey,
|
||||
@@ -179,3 +194,63 @@ class _RunPipelineActionState extends State<RunPipelineAction> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A floating action for a pipeline: Material's extended FAB, or on Cupertino
|
||||
/// a filled pill with the same icon and word and a soft shadow.
|
||||
Widget pipelineFab(
|
||||
BuildContext context, {
|
||||
required Key key,
|
||||
required bool primary,
|
||||
required IconData materialIcon,
|
||||
required IconData cupertinoIcon,
|
||||
required String label,
|
||||
required VoidCallback? onPressed,
|
||||
}) {
|
||||
if (useCupertinoControls(context)) {
|
||||
final content = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(cupertinoIcon, size: 18),
|
||||
const SizedBox(width: 6),
|
||||
Text(label),
|
||||
],
|
||||
);
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x33000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: primary
|
||||
? CupertinoButton.filled(
|
||||
key: key,
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
||||
onPressed: onPressed,
|
||||
child: content,
|
||||
)
|
||||
: CupertinoButton.tinted(
|
||||
key: key,
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
||||
onPressed: onPressed,
|
||||
child: content,
|
||||
),
|
||||
);
|
||||
}
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return FloatingActionButton.extended(
|
||||
key: key,
|
||||
heroTag: key,
|
||||
backgroundColor: primary ? null : scheme.secondaryContainer,
|
||||
foregroundColor: primary ? null : scheme.onSecondaryContainer,
|
||||
onPressed: onPressed,
|
||||
icon: Icon(materialIcon),
|
||||
label: Text(label),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
@@ -95,7 +96,7 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
|
||||
if (detail == null) return _withoutDetail(context);
|
||||
_retainGraphSelection(detail);
|
||||
_applyStageRequest(context, detail);
|
||||
return LayoutBuilder(
|
||||
final panel = LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final headerLimit = _headerLimit(constraints);
|
||||
return Column(
|
||||
@@ -154,6 +155,16 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
|
||||
);
|
||||
},
|
||||
);
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(child: panel),
|
||||
PositionedDirectional(
|
||||
end: 16,
|
||||
bottom: 16,
|
||||
child: SafeArea(child: _fabs(context, detail)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// The header keeps its natural height while at least
|
||||
@@ -327,46 +338,48 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
|
||||
padding: const EdgeInsets.fromLTRB(12, 6, 12, 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
heading,
|
||||
const SizedBox(height: 4),
|
||||
// One action row, as the web's `.pipeline-actions`: the primary Run,
|
||||
// then the secondary Runs, 8 apart.
|
||||
Wrap(
|
||||
key: const Key('pipeline-actions'),
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
RunPipelineAction(
|
||||
controller: _controller,
|
||||
detail: detail,
|
||||
gateway: widget.gateway,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
),
|
||||
Semantics(
|
||||
button: true,
|
||||
label: detail.name.trim().isEmpty
|
||||
? 'View runs of this pipeline'
|
||||
: 'View runs of ${detail.name}',
|
||||
child: ExcludeSemantics(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: widget.onViewPipelineRuns == null
|
||||
? null
|
||||
: () => widget.onViewPipelineRuns!(detail.id),
|
||||
icon: const Icon(Icons.list_alt),
|
||||
label: const Text('Runs'),
|
||||
key: const Key('pipeline-view-runs'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
children: [heading],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Run and Runs float at the bottom right: Runs above, the primary Run at
|
||||
/// the edge.
|
||||
Widget _fabs(BuildContext context, PipelineDetail detail) => Column(
|
||||
key: const Key('pipeline-actions'),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Semantics(
|
||||
button: true,
|
||||
label: detail.name.trim().isEmpty
|
||||
? 'View runs of this pipeline'
|
||||
: 'View runs of ${detail.name}',
|
||||
child: ExcludeSemantics(
|
||||
child: pipelineFab(
|
||||
context,
|
||||
key: const Key('pipeline-view-runs'),
|
||||
primary: false,
|
||||
materialIcon: Icons.list_alt,
|
||||
cupertinoIcon: CupertinoIcons.list_bullet,
|
||||
label: 'Runs',
|
||||
onPressed: widget.onViewPipelineRuns == null
|
||||
? null
|
||||
: () => widget.onViewPipelineRuns!(detail.id),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
RunPipelineAction(
|
||||
controller: _controller,
|
||||
detail: detail,
|
||||
gateway: widget.gateway,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
fab: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Widget _source(BuildContext context, PipelineDetail detail) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||
|
||||
@@ -107,10 +108,13 @@ void main() {
|
||||
|
||||
expect(find.bySemanticsLabel('View runs of Alpha review'), findsOneWidget);
|
||||
// Run and Runs share one action row, as the web's pipeline actions.
|
||||
final runs = tester.getCenter(find.byKey(const Key('pipeline-view-runs')));
|
||||
final actions = tester.getRect(find.byKey(const Key('pipeline-actions')));
|
||||
expect(actions.height, lessThan(56));
|
||||
expect(runs.dx, greaterThan(actions.left + 40));
|
||||
// Run and Runs float at the bottom right, Runs above the primary Run.
|
||||
final runs = tester.getRect(find.byKey(const Key('pipeline-view-runs')));
|
||||
final run = tester.getRect(find.byKey(runPipelineActionKey));
|
||||
final screen = tester.view.physicalSize / tester.view.devicePixelRatio;
|
||||
expect(runs.bottom, lessThanOrEqualTo(run.top));
|
||||
expect(run.right, greaterThan(screen.width - 40));
|
||||
expect(run.bottom, greaterThan(screen.height - 120));
|
||||
await tester.tap(find.byKey(const Key('pipeline-view-runs')));
|
||||
expect(opened, [1]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user