Skip to content

Commit

Permalink
feat: add data point detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
nottmey committed Sep 30, 2023
1 parent 84d5866 commit 0daba57
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 8 deletions.
129 changes: 129 additions & 0 deletions lib/api/api.graphql.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions lib/api/api.graphql.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/api/queries/data_point/GetDataPoint.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query GetDataPoint($id: ID!) {
getDataPoint(id: $id) {
...DataPoint
}
}
27 changes: 27 additions & 0 deletions lib/features/data_points/pages/data_point_details_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:climate/common/widgets/app_header_sliver.dart';
import 'package:climate/common/widgets/app_page_widget.dart';
import 'package:climate/features/data_points/providers/data_point_family.dart';

class DataPointDetailsPage extends AppPageWidget {
final String id;

const DataPointDetailsPage({
super.key,
required this.id,
});

@override
List<Widget> buildSlivers(BuildContext context, WidgetRef ref) {
final dataPointProvider = dataPointFamily(id);

return [
AppHeaderSliver(
titleProvider: dataPointProvider.select(
(state) => state.whenData(
(dataPoint) => '${dataPoint?.id}: ${dataPoint?.value?.ceil()}',
),
),
),
];
}
}
12 changes: 12 additions & 0 deletions lib/features/data_points/providers/data_point_family.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:climate/api/api.graphql.dart';
import 'package:climate/api/utils/execute.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final dataPointFamily =
FutureProvider.autoDispose.family<DataPointMixin?, String>((ref, id) async {
final response = await execute(
GetDataPointQuery(variables: GetDataPointArguments(id: id)),
);

return response.getDataPoint;
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import 'package:climate/api/utils/execute.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final quantificationDataPointsFamily = FutureProvider.autoDispose
.family<GetDataPointsOnQuantification$Query, String>((ref, id) {
return execute(
.family<List<DataPointMixin>?, String>((ref, id) async {
final response = await execute(
GetDataPointsOnQuantificationQuery(
variables: GetDataPointsOnQuantificationArguments(
parentQuantificationId: id,
),
),
);
return response.getQuantification?.dataPoints;
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:climate/common/widgets/app_header_sliver.dart';
import 'package:climate/common/widgets/app_page_widget.dart';
import 'package:climate/features/data_points/providers/quantification_data_points_family.dart';
import 'package:climate/features/quantifications/providers/quantifications_family.dart';
import 'package:climate/router.dart';

class QuantificationDetailsPage extends AppPageWidget {
final String id;
Expand All @@ -32,19 +33,27 @@ class QuantificationDetailsPage extends AppPageWidget {
skipLoadingOnRefresh: false,
loading: () => const Text('loading'),
error: (e, st) => Text('error $e'),
data: (result) {
data: (dataPoints) {
return Column(
children: (result.getQuantification?.dataPoints ?? [])
children: (dataPoints ?? [])
.map(
(e) => Row(
(dataPoint) => Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Data Point: ${e.value?.ceil()}'),
TextButton(
onPressed: () {
context.goToDataPointDetails(dataPoint.id);
},
child: const Icon(Icons.info_outlined),
),
Text('Data Point: ${dataPoint.value?.ceil()}'),
TextButton(
onPressed: () async {
await execute(
DeleteDataPointMutation(
variables: DeleteDataPointArguments(id: e.id),
variables: DeleteDataPointArguments(
id: dataPoint.id,
),
),
);
ref.invalidate(dataPointsProvider);
Expand Down Expand Up @@ -78,7 +87,7 @@ class QuantificationDetailsPage extends AppPageWidget {
},
),
),
)
),
];
}
}
21 changes: 21 additions & 0 deletions lib/router.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:climate/features/data_points/pages/data_point_details_page.dart';
import 'package:climate/features/database_browser/pages/attribute_page.dart';
import 'package:climate/features/database_browser/pages/database_navigator_page.dart';
import 'package:climate/features/database_browser/pages/entity_page.dart';
Expand All @@ -16,6 +17,7 @@ import 'package:go_router/go_router.dart';
const _overviewSegment = 'overview';
const _boundaryDetailsSegment = 'details';
const _quantificationDetailsSegment = 'quantifications';
const _dataPointDetailsSegment = 'datapoints';
const _databaseBrowserSegment = 'data';
const _databaseEntitySegment = 'entity';
const _databaseAttributeSegment = 'attribute';
Expand All @@ -33,6 +35,15 @@ extension Routes on BuildContext {
go('/$_overviewSegment/$_boundaryDetailsSegment/$boundaryId/$_quantificationDetailsSegment/$quantificationId');
}

void goToDataPointDetails(String dataPointId) {
final state = GoRouterState.of(this);
final boundaryId = state.pathParameters['boundaryId'];
final quantificationId = state.pathParameters['quantificationId'];
go(
'/$_overviewSegment/$_boundaryDetailsSegment/$boundaryId/$_quantificationDetailsSegment/$quantificationId/$_dataPointDetailsSegment/$dataPointId',
);
}

void goToDatabaseEntityIfNew(String id) {
pushIfNew('/$_databaseBrowserSegment/$_databaseEntitySegment?id=$id');
}
Expand Down Expand Up @@ -72,6 +83,16 @@ GoRouter newRouter() {
id: state.pathParameters['quantificationId']!,
);
},
routes: [
GoRoute(
path: '$_dataPointDetailsSegment/:dataPointId',
builder: (context, state) {
return DataPointDetailsPage(
id: state.pathParameters['dataPointId']!,
);
},
),
],
),
],
),
Expand Down

0 comments on commit 0daba57

Please sign in to comment.