Merge branch 'main' into pager-bar-overlap
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../../ui/layout/app_list_avatar.dart';
|
||||
import '../../../../ui/layout/app_list_row.dart';
|
||||
import '../../../../ui/text/relative_time_label.dart';
|
||||
import '../../domain/chat_sessions.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'session_actions.dart';
|
||||
@@ -48,6 +49,7 @@ class ChatSessionRow extends StatelessWidget {
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
final text = chatSessionSubtitle(session);
|
||||
final updatedAt = _chatSessionInstant(session['updated_at']);
|
||||
return AppListRow(
|
||||
key: Key('chat-row-$id'),
|
||||
cupertino: cupertino,
|
||||
@@ -78,7 +80,9 @@ class ChatSessionRow extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
time: relativeChatSessionTime(session['updated_at']),
|
||||
timeWidget: updatedAt == null
|
||||
? null
|
||||
: RelativeTimeLabel(instant: updatedAt),
|
||||
// `Closed` leads the line of a closed chat, then the model and folder.
|
||||
subtitle: Text.rich(
|
||||
TextSpan(
|
||||
@@ -111,6 +115,11 @@ class ChatSessionRow extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
DateTime? _chatSessionInstant(Object? updatedAt) {
|
||||
final millis = chatSessionMillis(updatedAt);
|
||||
return millis <= 0 ? null : DateTime.fromMillisecondsSinceEpoch(millis);
|
||||
}
|
||||
|
||||
/// As tall as the title's text, so it follows text scaling.
|
||||
class _Star extends StatelessWidget {
|
||||
const _Star({required this.cupertino, required this.color});
|
||||
|
||||
@@ -466,7 +466,6 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
steps: runDetailArtifactSteps(widget.run),
|
||||
executing: runDetailExecuting(widget.run),
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
initiallyCollapsed: true,
|
||||
embedded: true,
|
||||
);
|
||||
case RunDetailTab.changes:
|
||||
|
||||
@@ -39,7 +39,6 @@ class RunVisitArtifacts extends StatelessWidget {
|
||||
steps: runSteps.isEmpty ? <JsonMap>[step] : runSteps,
|
||||
focusIndex: runSteps.isEmpty ? 0 : visitIndex,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
initiallyCollapsed: true,
|
||||
embedded: true,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -6,7 +6,7 @@ import '../../../ui/adaptive/host.dart';
|
||||
import '../../../ui/layout/app_list_avatar.dart';
|
||||
import '../../../ui/layout/app_list_row.dart';
|
||||
import '../../../ui/status/run_status_icon.dart';
|
||||
import '../../../ui/text/relative_time.dart';
|
||||
import '../../../ui/text/relative_time_label.dart';
|
||||
import '../domain/run_deletion.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_more_menu.dart';
|
||||
@@ -77,6 +77,7 @@ class RunListRow extends StatelessWidget {
|
||||
final scheduled = run['scheduled'] == true;
|
||||
final bytes = runSizeBytes(run);
|
||||
final size = bytes == null ? null : formatByteSize(bytes);
|
||||
final createdAt = DateTime.tryParse('${run['created_at'] ?? ''}');
|
||||
final subtitle = [
|
||||
?pipelineLabel,
|
||||
if (scheduled) 'Scheduled',
|
||||
@@ -107,7 +108,9 @@ class RunListRow extends StatelessWidget {
|
||||
child: RunStatusIcon(state: state, label: runStatusLabel(run)),
|
||||
),
|
||||
title: Text(title),
|
||||
time: formatRelativeTimestamp('${run['created_at'] ?? ''}', now: now),
|
||||
timeWidget: createdAt == null
|
||||
? null
|
||||
: RelativeTimeLabel(instant: createdAt, now: now),
|
||||
subtitle: Text(subtitle),
|
||||
compactSubtitle: Text(compactSubtitle),
|
||||
// A narrow list pane beside the open run leaves the row no room for a
|
||||
|
||||
@@ -39,6 +39,7 @@ class AppListRow extends StatelessWidget {
|
||||
required this.title,
|
||||
this.leading,
|
||||
this.time,
|
||||
this.timeWidget,
|
||||
this.subtitle,
|
||||
this.compactSubtitle,
|
||||
this.subtitleLeading,
|
||||
@@ -59,6 +60,7 @@ class AppListRow extends StatelessWidget {
|
||||
final Widget title;
|
||||
final Widget? leading;
|
||||
final String? time;
|
||||
final Widget? timeWidget;
|
||||
final Widget? subtitle;
|
||||
|
||||
/// Replaces [subtitle] in a compact row, which has less room for facts.
|
||||
@@ -204,17 +206,25 @@ class AppListRow extends StatelessWidget {
|
||||
child: title,
|
||||
),
|
||||
),
|
||||
if (!compact && time != null && time!.isNotEmpty)
|
||||
if (!compact &&
|
||||
(timeWidget != null || (time != null && time!.isNotEmpty)))
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: constraints.maxWidth * 0.4),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 8),
|
||||
child: Text(
|
||||
time!,
|
||||
style: styles.time,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
child: timeWidget == null
|
||||
? Text(
|
||||
time!,
|
||||
style: styles.time,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)
|
||||
: DefaultTextStyle(
|
||||
style: styles.time,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
child: timeWidget!,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -41,16 +41,15 @@ class StickySection extends StatelessWidget {
|
||||
);
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
PinnedHeaderSliver(
|
||||
child: SizedBox(
|
||||
height: extent,
|
||||
child: StickySectionTitle(
|
||||
title: title,
|
||||
open: open,
|
||||
onToggle: onToggle,
|
||||
trailing: trailing,
|
||||
color: titleColor,
|
||||
),
|
||||
SliverPersistentHeader(
|
||||
pinned: true,
|
||||
delegate: _StickySectionHeaderDelegate(
|
||||
extent: extent,
|
||||
title: title,
|
||||
open: open,
|
||||
onToggle: onToggle,
|
||||
trailing: trailing,
|
||||
color: titleColor,
|
||||
),
|
||||
),
|
||||
// The content grows and shrinks under the pinned title, on its own
|
||||
@@ -72,6 +71,74 @@ class StickySection extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _StickySectionHeaderDelegate extends SliverPersistentHeaderDelegate {
|
||||
_StickySectionHeaderDelegate({
|
||||
required this.extent,
|
||||
required this.title,
|
||||
required this.open,
|
||||
required this.onToggle,
|
||||
required this.trailing,
|
||||
required this.color,
|
||||
});
|
||||
|
||||
final double extent;
|
||||
final String title;
|
||||
final bool open;
|
||||
final VoidCallback onToggle;
|
||||
final List<Widget> trailing;
|
||||
final Color? color;
|
||||
|
||||
@override
|
||||
double get minExtent => extent;
|
||||
|
||||
@override
|
||||
double get maxExtent => extent;
|
||||
|
||||
@override
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
double shrinkOffset,
|
||||
bool overlapsContent,
|
||||
) {
|
||||
final heading = SectionHeadingStyle.of(context);
|
||||
final inset = MediaQuery.paddingOf(context).top;
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
if (overlapsContent)
|
||||
Positioned(
|
||||
top: -inset,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
// The top-bar clearance is pinned ahead of this header. Once
|
||||
// this header is pinned, cover that clearance too so scrolled
|
||||
// content cannot remain visible above the section title.
|
||||
child: ColoredBox(color: heading.background),
|
||||
),
|
||||
StickySectionTitle(
|
||||
title: title,
|
||||
open: open,
|
||||
onToggle: onToggle,
|
||||
trailing: trailing,
|
||||
color: color,
|
||||
pinned: overlapsContent,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRebuild(_StickySectionHeaderDelegate oldDelegate) =>
|
||||
extent != oldDelegate.extent ||
|
||||
title != oldDelegate.title ||
|
||||
open != oldDelegate.open ||
|
||||
color != oldDelegate.color ||
|
||||
!identical(onToggle, oldDelegate.onToggle) ||
|
||||
!identical(trailing, oldDelegate.trailing);
|
||||
}
|
||||
|
||||
/// A sticky section's title bar: name, actions and the open/close chevron.
|
||||
class StickySectionTitle extends StatelessWidget {
|
||||
const StickySectionTitle({
|
||||
@@ -81,6 +148,7 @@ class StickySectionTitle extends StatelessWidget {
|
||||
required this.onToggle,
|
||||
this.trailing = const [],
|
||||
this.color,
|
||||
this.pinned = false,
|
||||
});
|
||||
|
||||
final String title;
|
||||
@@ -88,6 +156,7 @@ class StickySectionTitle extends StatelessWidget {
|
||||
final VoidCallback onToggle;
|
||||
final List<Widget> trailing;
|
||||
final Color? color;
|
||||
final bool pinned;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -140,9 +209,11 @@ class StickySectionTitle extends StatelessWidget {
|
||||
);
|
||||
// The whole strip opens and closes the section; its own buttons (copy)
|
||||
// still take their taps first.
|
||||
// The translucent page-colour scrim keeps this pinned heading readable as
|
||||
// content moves underneath without returning to the old solid section band.
|
||||
final scrim = heading.background.withValues(alpha: 0.94);
|
||||
// The page-colour scrim keeps this pinned heading readable as content moves
|
||||
// underneath without returning to the old solid section band.
|
||||
final scrim = pinned
|
||||
? heading.background
|
||||
: heading.background.withValues(alpha: 0.94);
|
||||
final Widget strip = cupertino
|
||||
? GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'relative_time.dart';
|
||||
|
||||
/// A relative-time label that rebuilds only itself when its formatter can
|
||||
/// change. It stops its timer while the app is backgrounded.
|
||||
class RelativeTimeLabel extends StatefulWidget {
|
||||
const RelativeTimeLabel({super.key, required this.instant, this.now});
|
||||
|
||||
final DateTime? instant;
|
||||
final DateTime? now;
|
||||
|
||||
@override
|
||||
State<RelativeTimeLabel> createState() => _RelativeTimeLabelState();
|
||||
}
|
||||
|
||||
class _RelativeTimeLabelState extends State<RelativeTimeLabel>
|
||||
with WidgetsBindingObserver {
|
||||
Timer? _timer;
|
||||
DateTime _now = DateTime.now();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_schedule();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(RelativeTimeLabel oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.instant != widget.instant) _schedule();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_now = DateTime.now();
|
||||
if (mounted) setState(() {});
|
||||
_schedule(current: _now);
|
||||
} else if (state == AppLifecycleState.hidden ||
|
||||
// Not inactive: a desktop window that lost focus is still visible.
|
||||
state == AppLifecycleState.paused ||
|
||||
state == AppLifecycleState.detached) {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
void _schedule({DateTime? current}) {
|
||||
_timer?.cancel();
|
||||
final instant = widget.instant;
|
||||
if (instant == null) return;
|
||||
final now = current ?? widget.now ?? DateTime.now();
|
||||
_now = now;
|
||||
final next = _nextBoundary(instant, now);
|
||||
final delay = next.difference(now);
|
||||
_timer = Timer(delay.isNegative ? Duration.zero : delay, () {
|
||||
if (!mounted) return;
|
||||
_now = _now.add(delay);
|
||||
setState(() {});
|
||||
_schedule(current: _now);
|
||||
});
|
||||
}
|
||||
|
||||
DateTime _nextBoundary(DateTime instant, DateTime now) {
|
||||
final difference = now.difference(instant);
|
||||
final age = difference.abs();
|
||||
final unit = age < const Duration(hours: 1)
|
||||
? const Duration(minutes: 1)
|
||||
: age < const Duration(days: 1)
|
||||
? const Duration(hours: 1)
|
||||
: age < const Duration(days: 7)
|
||||
? const Duration(days: 1)
|
||||
: null;
|
||||
if (unit != null) {
|
||||
final units = age.inMilliseconds ~/ unit.inMilliseconds;
|
||||
final boundary = difference.isNegative
|
||||
// Future labels use a decreasing count. Add a second so an exact
|
||||
// boundary does not immediately schedule another zero-delay timer.
|
||||
? instant.subtract(unit * units).add(const Duration(seconds: 1))
|
||||
: instant.add(unit * (units + 1));
|
||||
if (boundary.isAfter(now)) return boundary;
|
||||
}
|
||||
final midnight = DateTime(now.year, now.month, now.day + 1);
|
||||
return midnight.isAfter(now)
|
||||
? midnight
|
||||
: now.add(const Duration(minutes: 1));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// The row's time style (an unread row's accent) stays on the label
|
||||
// itself, as on the plain Text this replaces.
|
||||
return Text(
|
||||
formatRelativeTime(widget.instant, now: _now) ?? '',
|
||||
style: DefaultTextStyle.of(context).style,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||
import 'package:pipelines_app/ui/layout/sticky_section.dart';
|
||||
|
||||
import '../../artifacts/domain/artifact_fixtures.dart';
|
||||
|
||||
@@ -114,11 +113,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('run-detail-tab-artifacts')));
|
||||
await tester.pumpAndSettle();
|
||||
final sections = find.byType(StickySectionTitle);
|
||||
for (var index = 0; index < sections.evaluate().length; index += 1) {
|
||||
await tester.tap(sections.at(index));
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
// Artifact groups start open: the files show without a tap.
|
||||
|
||||
expect(find.text('Artifacts · 2 recorded'), findsOneWidget);
|
||||
expect(find.text('build.log'), findsOneWidget);
|
||||
|
||||
@@ -7,19 +7,10 @@ import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/layout/sticky_section.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
import 'run_detail_visit_support.dart';
|
||||
|
||||
Future<void> _expandArtifactGroups(WidgetTester tester) async {
|
||||
final sections = find.byType(StickySectionTitle);
|
||||
for (var index = 0; index < sections.evaluate().length; index += 1) {
|
||||
await tester.tap(sections.at(index));
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _showTurnDocuments(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(const Key('artifact-debug-toggle')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -204,7 +195,7 @@ void main() {
|
||||
await openVisit(tester, platform, run: run, sequence: 2);
|
||||
expectVisitHeading(tester, 'plan', 2);
|
||||
await openVisitTab(tester, RunVisitSection.artifacts);
|
||||
await _expandArtifactGroups(tester);
|
||||
// Artifact groups start open: the files show without a tap.
|
||||
expect(find.text('plan-2.csv'), findsOneWidget);
|
||||
expect(find.text('public/shared.csv'), findsNothing);
|
||||
expect(find.byType(ArtifactGalleryPage), findsOneWidget);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
|
||||
import 'package:pipelines_app/ui/layout/section_heading.dart';
|
||||
import 'package:pipelines_app/ui/layout/sticky_section.dart';
|
||||
|
||||
@@ -16,6 +18,7 @@ class _HostState extends State<_Host> {
|
||||
@override
|
||||
Widget build(BuildContext context) => CustomScrollView(
|
||||
slivers: [
|
||||
const SliverTopBarClearance(),
|
||||
StickySection(
|
||||
title: 'Input',
|
||||
open: open,
|
||||
@@ -48,6 +51,39 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
for (final host in ['Material', 'Cupertino']) {
|
||||
testWidgets('pins an opaque section edge below the top bar in $host', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final child = MediaQuery(
|
||||
data: const MediaQueryData(padding: EdgeInsets.only(top: 64)),
|
||||
child: _Host(),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
host == 'Cupertino'
|
||||
? CupertinoApp(home: child)
|
||||
: MaterialApp(home: Scaffold(body: child)),
|
||||
);
|
||||
|
||||
await tester.drag(find.byType(CustomScrollView), const Offset(0, -800));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final title = tester.widget<StickySectionTitle>(
|
||||
find.byType(StickySectionTitle),
|
||||
);
|
||||
expect(title.pinned, isTrue);
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(widget) => widget is Positioned && widget.top == -64,
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a tap anywhere on the title strip toggles the section', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/text/relative_time_label.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('updates at the next relative-time boundary', (tester) async {
|
||||
final instant = DateTime.now().subtract(const Duration(minutes: 4));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: RelativeTimeLabel(instant: instant)),
|
||||
);
|
||||
expect(find.text('4m'), findsOneWidget);
|
||||
|
||||
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
||||
expect(find.text('5m'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('future labels schedule their next boundary', (tester) async {
|
||||
final instant = DateTime.now().add(const Duration(minutes: 4));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: RelativeTimeLabel(instant: instant)),
|
||||
);
|
||||
expect(find.text('in 3m'), findsOneWidget);
|
||||
|
||||
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
||||
expect(find.text('in 2m'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('cancels its timer when disposed', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: RelativeTimeLabel(
|
||||
instant: DateTime.now().subtract(const Duration(minutes: 4)),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(const MaterialApp(home: SizedBox()));
|
||||
await tester.pump(const Duration(hours: 1));
|
||||
});
|
||||
|
||||
testWidgets('keeps ticking while inactive, pauses while hidden and '
|
||||
'refreshes on resume', (tester) async {
|
||||
final instant = DateTime.now().subtract(const Duration(minutes: 4));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: RelativeTimeLabel(instant: instant)),
|
||||
);
|
||||
expect(find.text('4m'), findsOneWidget);
|
||||
|
||||
// A desktop window that lost focus is still on screen: keep ticking.
|
||||
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.inactive,
|
||||
);
|
||||
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
||||
expect(find.text('5m'), findsOneWidget);
|
||||
|
||||
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.hidden,
|
||||
);
|
||||
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
||||
expect(find.text('5m'), findsOneWidget);
|
||||
|
||||
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.inactive,
|
||||
);
|
||||
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.resumed,
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(minutes: 1, seconds: 1));
|
||||
expect(find.text('5m'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user