Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch single artefact on artefact page #210

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions frontend/lib/providers/artefact.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../models/artefact.dart' as artefact_model;
import 'api.dart';

part 'artefact.g.dart';

@riverpod
class Artefact extends _$Artefact {
@override
Future<artefact_model.Artefact> build(int artefactId) {
final api = ref.watch(apiProvider);
return api.getArtefact(artefactId);
}

Future<void> changeArtefactStatus(
id,
artefact_model.ArtefactStatus status,
) async {
final api = ref.read(apiProvider);
final artefact = await api.changeArtefactStatus(artefactId, status);
state = AsyncData(artefact);
}

Future<void> updateCompletedTestExecutionsCount(int count) async {
final artefact = await future;
state = AsyncData(artefact.copyWith(completedTestExecutionsCount: count));
}
}
37 changes: 6 additions & 31 deletions frontend/lib/providers/family_artefacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,10 @@ import 'api.dart';
part 'family_artefacts.g.dart';

@riverpod
class FamilyArtefacts extends _$FamilyArtefacts {
@override
Future<Map<int, Artefact>> build(FamilyName family) async {
final api = ref.watch(apiProvider);
return api.getFamilyArtefacts(family);
}

Future<void> changeArtefactStatus(
int artefactId,
ArtefactStatus newStatus,
) async {
final api = ref.read(apiProvider);
final artefact = await api.changeArtefactStatus(artefactId, newStatus);

final previousState = await future;
state = AsyncData({...previousState, artefact.id: artefact});
}

Future<void> updateCompletedTestExecutionsCount(
int artefactId,
int count,
) async {
final previousState = await future;
final artefact = previousState[artefactId];
if (artefact != null) {
state = AsyncData({
...previousState,
artefactId: artefact.copyWith(completedTestExecutionsCount: count),
});
}
}
Future<Map<int, Artefact>> familyArtefacts(
FamilyArtefactsRef ref,
FamilyName family,
) {
final api = ref.watch(apiProvider);
return api.getFamilyArtefacts(family);
}
11 changes: 3 additions & 8 deletions frontend/lib/providers/review_test_execution.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../models/family_name.dart';
import '../models/test_execution.dart';
import 'artefact.dart';
import 'artefact_builds.dart';
import 'family_artefacts.dart';

part 'review_test_execution.g.dart';

Expand All @@ -18,7 +17,6 @@ class ReviewTestExecution extends _$ReviewTestExecution {
int testExecutionId,
String reviewComment,
List<TestExecutionReviewDecision> reviewDecision,
FamilyName familyName,
int artefactId,
) async {
await ref
Expand All @@ -41,10 +39,7 @@ class ReviewTestExecution extends _$ReviewTestExecution {
.fold(0, (a, b) => a + b);

await ref
.read(familyArtefactsProvider(familyName).notifier)
.updateCompletedTestExecutionsCount(
artefactId,
newCompletedTestExecutionsCount,
);
.read(artefactProvider(artefactId).notifier)
.updateCompletedTestExecutionsCount(newCompletedTestExecutionsCount);
}
}
5 changes: 5 additions & 0 deletions frontend/lib/repositories/api_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,9 @@ class ApiRepository {
Future<void> deleteTestIssue(int issueId) async {
await dio.delete('/v1/test-cases/reported-issues/$issueId');
}

Future<Artefact> getArtefact(int artefactId) async {
final response = await dio.get('/v1/artefacts/$artefactId');
return Artefact.fromJson(response.data);
}
}
27 changes: 4 additions & 23 deletions frontend/lib/ui/artefact_page/artefact_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru/widgets.dart';

import '../../providers/family_artefacts.dart';
import '../../routing.dart';
import '../dialog_header.dart';
import '../../providers/artefact.dart';
import '../spacing.dart';
import 'artefact_page_body.dart';
import 'artefact_page_header.dart';
Expand All @@ -15,34 +13,17 @@ class ArtefactPage extends ConsumerWidget {

final int artefactId;

Column get _invalidArtefactErrorMessage {
return const Column(
children: [
DialogHeader(),
Expanded(
child: Center(
child: Text('Artefact not found. It may be that a'
' newer version has been released already'),
),
),
],
);
}

@override
Widget build(BuildContext context, WidgetRef ref) {
final family = AppRoutes.familyFromUri(AppRoutes.uriFromContext(context));
final artefacts = ref.watch(familyArtefactsProvider(family));
final artefact = ref.watch(artefactProvider(artefactId));
return Padding(
padding: const EdgeInsets.only(
left: Spacing.pageHorizontalPadding,
right: Spacing.pageHorizontalPadding,
top: Spacing.level5,
),
child: artefacts.when(
data: (artefacts) {
final artefact = artefacts[artefactId];
if (artefact == null) return _invalidArtefactErrorMessage;
child: artefact.when(
data: (artefact) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down
6 changes: 2 additions & 4 deletions frontend/lib/ui/artefact_page/artefact_signoff_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru/widgets.dart';

import '../../models/artefact.dart';
import '../../providers/family_artefacts.dart';
import '../../routing.dart';
import '../../providers/artefact.dart' hide Artefact;

class ArtefactSignoffButton extends ConsumerWidget {
const ArtefactSignoffButton({super.key, required this.artefact});
Expand All @@ -14,7 +13,6 @@ class ArtefactSignoffButton extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final fontStyle = Theme.of(context).textTheme.titleMedium;
final family = AppRoutes.familyFromUri(AppRoutes.uriFromContext(context));

return YaruPopupMenuButton(
child: Text(
Expand All @@ -26,7 +24,7 @@ class ArtefactSignoffButton extends ConsumerWidget {
(status) => PopupMenuItem(
value: status,
onTap: () => ref
.read(familyArtefactsProvider(family).notifier)
.read(artefactProvider(artefact.id).notifier)
.changeArtefactStatus(artefact.id, status),
child: Text(
status.name,
Expand Down
4 changes: 0 additions & 4 deletions frontend/lib/ui/artefact_page/test_execution_pop_over.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru/widgets.dart';

import '../../models/family_name.dart';
import '../../models/test_execution.dart';
import '../../providers/review_test_execution.dart';
import '../spacing.dart';
Expand All @@ -13,12 +12,10 @@ class TestExecutionPopOver extends ConsumerStatefulWidget {
super.key,
required this.testExecution,
required this.artefactId,
required this.family,
});

final TestExecution testExecution;
final int artefactId;
final FamilyName family;

@override
TestExecutionPopOverState createState() => TestExecutionPopOverState();
Expand Down Expand Up @@ -117,7 +114,6 @@ class TestExecutionPopOverState extends ConsumerState<TestExecutionPopOver> {
widget.testExecution.id,
reviewCommentController.text,
reviewDecisions,
widget.family,
widget.artefactId,
);
Navigator.pop(context);
Expand Down
2 changes: 0 additions & 2 deletions frontend/lib/ui/artefact_page/test_execution_review.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class TestExecutionReviewButton extends StatelessWidget {

@override
Widget build(BuildContext context) {
final family = AppRoutes.familyFromUri(AppRoutes.uriFromContext(context));
final artefactId =
AppRoutes.artefactIdFromUri(AppRoutes.uriFromContext(context));
return GestureDetector(
Expand All @@ -47,7 +46,6 @@ class TestExecutionReviewButton extends StatelessWidget {
bodyBuilder: (context) => TestExecutionPopOver(
testExecution: testExecution,
artefactId: artefactId,
family: family,
),
direction: PopoverDirection.bottom,
width: 500,
Expand Down
Loading