Skip to content

Commit

Permalink
Refactor to get links to artefacts
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed Oct 23, 2023
1 parent 13c7abe commit f69ec86
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 164 deletions.
3 changes: 3 additions & 0 deletions frontend/lib/models/artefact.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:freezed_annotation/freezed_annotation.dart';

import 'stage_name.dart';

part 'artefact.freezed.dart';
part 'artefact.g.dart';

Expand All @@ -10,6 +12,7 @@ class Artefact with _$Artefact {
required String name,
required String version,
required Map<String, dynamic> source,
required StageName stage,
}) = _Artefact;

factory Artefact.fromJson(Map<String, Object?> json) =>
Expand Down
16 changes: 0 additions & 16 deletions frontend/lib/models/stage.dart

This file was deleted.

20 changes: 20 additions & 0 deletions frontend/lib/models/stage_name.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'family_name.dart';

enum StageName { edge, beta, candidate, stable, proposed, updates }

List<StageName> familyStages(FamilyName family) {
switch (family) {
case FamilyName.snap:
return [
StageName.edge,
StageName.beta,
StageName.candidate,
StageName.stable,
];
case FamilyName.deb:
return [
StageName.proposed,
StageName.updates,
];
}
}
15 changes: 15 additions & 0 deletions frontend/lib/providers/artefact.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../models/artefact.dart';
import 'dio.dart';

part 'artefact.g.dart';

@riverpod
Future<Artefact> artefact(ArtefactRef ref, String artefactId) async {
final dio = ref.watch(dioProvider);

final response = await dio.get('/v1/artefacts/$artefactId');
final artefact = Artefact.fromJson(response.data);
return artefact;
}
21 changes: 21 additions & 0 deletions frontend/lib/providers/family_artefacts.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../models/artefact.dart';
import '../models/family_name.dart';
import 'dio.dart';

part 'family_artefacts.g.dart';

@riverpod
Future<List<Artefact>> familyArtefacts(
FamilyArtefactsRef ref,
FamilyName family,
) async {
final dio = ref.watch(dioProvider);

final response = await dio.get('/v1/artefacts?family=${family.name}');
final List artefactsJson = response.data;
final artefacts =
artefactsJson.map((json) => Artefact.fromJson(json)).toList();
return artefacts;
}
10 changes: 0 additions & 10 deletions frontend/lib/providers/name_of_selected_stage.dart

This file was deleted.

8 changes: 0 additions & 8 deletions frontend/lib/providers/names_of_stages.dart

This file was deleted.

24 changes: 24 additions & 0 deletions frontend/lib/providers/stage_artefacts.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../models/artefact.dart';
import '../models/family_name.dart';
import '../models/stage_name.dart';
import 'family_artefacts.dart';

part 'stage_artefacts.g.dart';

@riverpod
Future<List<Artefact>> stageArtefacts(
StageArtefactsRef ref,
FamilyName family,
StageName stage,
) async {
final artefacts = await ref.watch(
familyArtefactsProvider(family).selectAsync(
(artefacts) =>
artefacts.where((artefact) => artefact.stage == stage).toList(),
),
);

return artefacts;
}
17 changes: 0 additions & 17 deletions frontend/lib/providers/stages.dart

This file was deleted.

45 changes: 42 additions & 3 deletions frontend/lib/routing.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import 'models/family_name.dart';
import 'ui/dashboard/artefact_dialog.dart';
import 'ui/dashboard/dashboard.dart';
import 'ui/dialog_page.dart';
import 'ui/skeleton.dart';

final appRouter = GoRouter(
Expand All @@ -16,12 +20,35 @@ final appRouter = GoRouter(
routes: [
GoRoute(
path: AppRoutes.snaps,
pageBuilder: (_, __) =>
const NoTransitionPage(child: SnapDashboard()),
pageBuilder: (_, __) => const NoTransitionPage(
child: Dashboard(),
),
routes: [
GoRoute(
path: ':artefactId',
pageBuilder: (context, state) => DialogPage(
builder: (_) => ArtefactDialog(
artefactId: state.pathParameters['artefactId']!,
),
),
),
],
),
GoRoute(
path: AppRoutes.debs,
pageBuilder: (_, __) => const NoTransitionPage(child: DebDashboard()),
pageBuilder: (_, __) => const NoTransitionPage(
child: Dashboard(),
),
routes: [
GoRoute(
path: ':artefactId',
pageBuilder: (context, state) => DialogPage(
builder: (_) => ArtefactDialog(
artefactId: state.pathParameters['artefactId']!,
),
),
),
],
),
],
),
Expand All @@ -31,4 +58,16 @@ final appRouter = GoRouter(
class AppRoutes {
static const snaps = '/snaps';
static const debs = '/debs';

static FamilyName familyFromContext(BuildContext context) {
final route = GoRouterState.of(context).fullPath!;

if (route.startsWith(snaps)) {
return FamilyName.snap;
} else if (route.startsWith(debs)) {
return FamilyName.deb;
} else {
throw Exception('Unknown route: $route');
}
}
}
52 changes: 32 additions & 20 deletions frontend/lib/ui/dashboard/artefact_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ import 'package:yaru_widgets/widgets.dart';

import '../../models/artefact.dart';
import '../../models/artefact_build.dart';
import '../../models/stage_name.dart';
import '../../models/test_execution.dart';
import '../../providers/artefact.dart';
import '../../providers/artefact_builds.dart';
import '../../providers/name_of_selected_stage.dart';
import '../../providers/names_of_stages.dart';
import '../../routing.dart';
import '../inline_url_text.dart';
import '../spacing.dart';

class ArtefactDialog extends StatelessWidget {
const ArtefactDialog({super.key, required this.artefact});
class ArtefactDialog extends ConsumerWidget {
const ArtefactDialog({super.key, required this.artefactId});

final Artefact artefact;
final String artefactId;

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final artefact = ref.watch(artefactProvider(artefactId));

return SelectionArea(
child: Dialog(
child: SizedBox(
Expand All @@ -34,15 +37,21 @@ class ArtefactDialog extends StatelessWidget {
horizontal: Spacing.level5,
vertical: Spacing.level3,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_ArtefactHeader(title: artefact.name),
const SizedBox(height: Spacing.level4),
_ArtefactInfoSection(artefact: artefact),
const SizedBox(height: Spacing.level4),
Expanded(child: _EnvironmentsSection(artefact: artefact)),
],
child: artefact.when(
data: (artefact) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_ArtefactHeader(title: artefact.name),
const SizedBox(height: Spacing.level4),
_ArtefactInfoSection(artefact: artefact),
const SizedBox(height: Spacing.level4),
Expanded(child: _EnvironmentsSection(artefact: artefact)),
],
),
loading: () =>
const Center(child: YaruCircularProgressIndicator()),
error: (error, stackTrace) =>
Text('Failed to fetch artefact $artefactId $error'),
),
),
),
Expand Down Expand Up @@ -101,7 +110,7 @@ class _ArtefactInfoSection extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const _StagesRow(),
_StagesRow(stage: artefact.stage),
const SizedBox(height: Spacing.level3),
...artefactDetails
.map<Widget>(
Expand Down Expand Up @@ -140,12 +149,15 @@ class _ArtefactInfoSection extends StatelessWidget {
}

class _StagesRow extends ConsumerWidget {
const _StagesRow();
const _StagesRow({required this.stage});

final StageName stage;

@override
Widget build(BuildContext context, WidgetRef ref) {
final selectedStageName = ref.watch(nameOfSelectedStageProvider);
final namesOfStages = ref.watch(namesOfStagesProvider);
final family = AppRoutes.familyFromContext(context);
final selectedStageName = stage;
final namesOfStages = familyStages(family);

final stageNamesWidgets = <Widget>[];
bool passedSelectedStage = false;
Expand All @@ -160,7 +172,7 @@ class _StagesRow extends ConsumerWidget {

stageNamesWidgets.add(
Text(
stageName.capitalize(),
stageName.name.capitalize(),
style: Theme.of(context).textTheme.bodyLarge?.apply(color: fontColor),
),
);
Expand Down
49 changes: 8 additions & 41 deletions frontend/lib/ui/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,57 +1,24 @@
import 'package:dartx/dartx.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru_widgets/widgets.dart';

import '../../models/family_name.dart';
import '../../providers/stages.dart';
import '../../routing.dart';
import 'dashboard_body.dart';
import 'dashboard_header.dart';

class SnapDashboard extends StatelessWidget {
const SnapDashboard({super.key});

@override
Widget build(BuildContext context) {
return const _Dashboard(
familyName: FamilyName.snap,
title: 'Snap Update Verification',
);
}
}

class DebDashboard extends StatelessWidget {
const DebDashboard({super.key});

@override
Widget build(BuildContext context) {
return const _Dashboard(
familyName: FamilyName.deb,
title: 'Deb Update Verification',
);
}
}

class _Dashboard extends ConsumerWidget {
const _Dashboard({Key? key, required this.familyName, required this.title})
: super(key: key);

final FamilyName familyName;
final String title;
class Dashboard extends ConsumerWidget {
const Dashboard({Key? key}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
final stages = ref.watch(stagesProvider(familyName));
final familyName = AppRoutes.familyFromContext(context);

return Column(
children: [
DashboardHeader(title: title),
Expanded(
child: stages.when(
error: (error, _) => Center(child: Text('Error: $error')),
loading: () => const Center(child: YaruCircularProgressIndicator()),
data: (stages) => DashboardBody(stages: stages),
),
DashboardHeader(
title: '${familyName.name.capitalize()} Update Verification',
),
const Expanded(child: DashboardBody()),
],
);
}
Expand Down
Loading

0 comments on commit f69ec86

Please sign in to comment.