From 68d88469c1ce0f259dccabed1522dada3f03e603 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Sun, 25 Feb 2024 19:40:21 +0100 Subject: [PATCH] add table infos when no pkgs or builds are there yet --- .../components/dashboard/builds_chart.dart | 16 ++--- .../components/dashboard/recent_builds.dart | 59 ++++++++-------- .../lib/components/dashboard/side_panel.dart | 32 +++++++-- .../components/dashboard/your_packages.dart | 68 ++++++++++--------- frontend/lib/components/table_info.dart | 30 ++++++++ frontend/lib/screens/builds_screen.dart | 8 ++- 6 files changed, 139 insertions(+), 74 deletions(-) create mode 100644 frontend/lib/components/table_info.dart diff --git a/frontend/lib/components/dashboard/builds_chart.dart b/frontend/lib/components/dashboard/builds_chart.dart index b7ed3b4..3580c51 100644 --- a/frontend/lib/components/dashboard/builds_chart.dart +++ b/frontend/lib/components/dashboard/builds_chart.dart @@ -3,15 +3,15 @@ import 'package:flutter/material.dart'; class BuildsChart extends StatefulWidget { const BuildsChart({ - Key? key, + super.key, required this.nrbuilds, required this.nrfailedbuilds, - required this.nrActiveBuilds, - }) : super(key: key); + required this.nrEnqueuedBuilds, + }); final int nrbuilds; final int nrfailedbuilds; - final int nrActiveBuilds; + final int nrEnqueuedBuilds; @override _BuildsChartState createState() => _BuildsChartState(); @@ -88,10 +88,10 @@ class _BuildsChartState extends State { color: const Color(0xff0a7005), value: (widget.nrbuilds - widget.nrfailedbuilds - - widget.nrActiveBuilds) + widget.nrEnqueuedBuilds) .toDouble(), title: - "${((widget.nrbuilds - widget.nrfailedbuilds - widget.nrActiveBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", + "${((widget.nrbuilds - widget.nrfailedbuilds - widget.nrEnqueuedBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", radius: radius, titleStyle: TextStyle( fontSize: fontSize, @@ -101,9 +101,9 @@ class _BuildsChartState extends State { case 2: return PieChartSectionData( color: const Color(0xFF0044AA), - value: (widget.nrActiveBuilds).toDouble(), + value: (widget.nrEnqueuedBuilds).toDouble(), title: - "${((widget.nrActiveBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", + "${((widget.nrEnqueuedBuilds) * 100 / widget.nrbuilds).toStringAsFixed(2)}%", radius: radius, titleStyle: TextStyle( fontSize: fontSize, diff --git a/frontend/lib/components/dashboard/recent_builds.dart b/frontend/lib/components/dashboard/recent_builds.dart index 3c4bdc3..6f8b6ed 100644 --- a/frontend/lib/components/dashboard/recent_builds.dart +++ b/frontend/lib/components/dashboard/recent_builds.dart @@ -5,17 +5,11 @@ import 'package:aurcache/providers/api/builds_provider.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import '../../constants/color_constants.dart'; +import '../table_info.dart'; -class RecentBuilds extends StatefulWidget { - const RecentBuilds({ - Key? key, - }) : super(key: key); +class RecentBuilds extends StatelessWidget { + const RecentBuilds({super.key}); - @override - State createState() => _RecentBuildsState(); -} - -class _RecentBuildsState extends State { @override Widget build(BuildContext context) { return Container( @@ -31,27 +25,34 @@ class _RecentBuildsState extends State { "Recent Builds", style: Theme.of(context).textTheme.subtitle1, ), - SizedBox( - width: double.infinity, - child: APIBuilder, BuildsDTO>( - key: const Key("Builds on dashboard"), - dto: BuildsDTO(limit: 10), - interval: const Duration(seconds: 10), - onLoad: () => const Text("no data"), - onData: (t) { - return BuildsTable(data: t); - }, - ), - ), - ElevatedButton( - onPressed: () { - context.push("/builds"); + APIBuilder, BuildsDTO>( + key: const Key("Builds on dashboard"), + dto: BuildsDTO(limit: 10), + interval: const Duration(seconds: 10), + onLoad: () => const Text("no data"), + onData: (t) { + if (t.isEmpty) { + return const TableInfo(title: "You have no builds yet"); + } else { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: double.infinity, child: BuildsTable(data: t)), + ElevatedButton( + onPressed: () { + context.push("/builds"); + }, + child: Text( + "List all Builds", + style: TextStyle(color: Colors.white.withOpacity(0.8)), + ), + ), + ], + ); + } }, - child: Text( - "List all Builds", - style: TextStyle(color: Colors.white.withOpacity(0.8)), - ), - ) + ), ], ), ); diff --git a/frontend/lib/components/dashboard/side_panel.dart b/frontend/lib/components/dashboard/side_panel.dart index 8afbda3..91811a2 100644 --- a/frontend/lib/components/dashboard/side_panel.dart +++ b/frontend/lib/components/dashboard/side_panel.dart @@ -35,10 +35,34 @@ class SidePanel extends StatelessWidget { ), ), const SizedBox(height: defaultPadding), - BuildsChart( - nrbuilds: nrbuilds, - nrfailedbuilds: nrfailedbuilds, - nrActiveBuilds: nrEnqueuedBuilds), + nrbuilds > 0 + ? BuildsChart( + nrbuilds: nrbuilds, + nrfailedbuilds: nrfailedbuilds, + nrEnqueuedBuilds: nrEnqueuedBuilds) + : const SizedBox( + width: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + height: 15, + ), + Icon( + Icons.info_outline_rounded, + size: 42, + ), + SizedBox( + height: 15, + ), + Text("Add Packages to view Graph"), + SizedBox( + height: 30, + ) + ], + ), + ), SideCard( color: const Color(0xff0a7005), title: "Successful Builds", diff --git a/frontend/lib/components/dashboard/your_packages.dart b/frontend/lib/components/dashboard/your_packages.dart index cc11b1a..88283fd 100644 --- a/frontend/lib/components/dashboard/your_packages.dart +++ b/frontend/lib/components/dashboard/your_packages.dart @@ -1,21 +1,19 @@ +import 'dart:ffi'; + import 'package:aurcache/components/api/APIBuilder.dart'; import 'package:aurcache/components/packages_table.dart'; import 'package:aurcache/providers/api/packages_provider.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; import '../../constants/color_constants.dart'; import '../../models/package.dart'; +import '../table_info.dart'; -class YourPackages extends StatefulWidget { - const YourPackages({ - Key? key, - }) : super(key: key); +class YourPackages extends StatelessWidget { + const YourPackages({super.key}); - @override - State createState() => _YourPackagesState(); -} - -class _YourPackagesState extends State { @override Widget build(BuildContext context) { return Container( @@ -31,29 +29,35 @@ class _YourPackagesState extends State { "Your Packages", style: Theme.of(context).textTheme.subtitle1, ), - Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ - SizedBox( - width: double.infinity, - child: APIBuilder, PackagesDTO>( - key: const Key("Packages on dashboard"), - interval: const Duration(seconds: 10), - dto: PackagesDTO(limit: 10), - onData: (data) { - return PackagesTable(data: data); - }, - onLoad: () => const Text("No data"), - ), - ), - ElevatedButton( - onPressed: () { - context.push("/packages"); - }, - child: Text( - "List all Packages", - style: TextStyle(color: Colors.white.withOpacity(0.8)), - ), - ) - ]), + APIBuilder, PackagesDTO>( + key: const Key("Packages on dashboard"), + interval: const Duration(seconds: 10), + dto: PackagesDTO(limit: 10), + onData: (data) { + if (data.isEmpty) { + return const TableInfo(title: "You have no packages yet"); + } else { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: double.infinity, + child: PackagesTable(data: data)), + ElevatedButton( + onPressed: () { + context.push("/packages"); + }, + child: Text( + "List all Packages", + style: TextStyle(color: Colors.white.withOpacity(0.8)), + ), + ) + ], + ); + } + }, + onLoad: () => const CircularProgressIndicator(), + ), ], ), ); diff --git a/frontend/lib/components/table_info.dart b/frontend/lib/components/table_info.dart new file mode 100644 index 0000000..eb9751b --- /dev/null +++ b/frontend/lib/components/table_info.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; + +class TableInfo extends StatelessWidget { + const TableInfo({super.key, required this.title}); + final String title; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox( + height: 5, + ), + const Divider(), + const SizedBox( + height: 15, + ), + const Icon( + Icons.info_outline_rounded, + size: 42, + ), + const SizedBox( + height: 15, + ), + Text(title), + ], + ); + } +} diff --git a/frontend/lib/screens/builds_screen.dart b/frontend/lib/screens/builds_screen.dart index eeab18c..1f3e49b 100644 --- a/frontend/lib/screens/builds_screen.dart +++ b/frontend/lib/screens/builds_screen.dart @@ -1,5 +1,6 @@ import 'package:aurcache/components/builds_table.dart'; import 'package:aurcache/components/api/APIBuilder.dart'; +import 'package:aurcache/components/table_info.dart'; import 'package:aurcache/providers/api/builds_provider.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -43,7 +44,12 @@ class BuildsScreen extends StatelessWidget { interval: const Duration(seconds: 10), onLoad: () => const Text("no data"), onData: (data) { - return BuildsTable(data: data); + if (data.isEmpty) { + return const TableInfo( + title: "You have no builds yet"); + } else { + return BuildsTable(data: data); + } }), ) ],