Skip to content

Commit

Permalink
[feature] Allow app to check if there is a new version (#1176)
Browse files Browse the repository at this point in the history
* [feature] Allow app to check if there is a new version

* style new version message

* dart analysis fixes

---------

Co-authored-by: Irina Southwell <[email protected]>
  • Loading branch information
rvowles and IrinaSouth authored Aug 20, 2024
1 parent 8a15f37 commit 259825b
Show file tree
Hide file tree
Showing 24 changed files with 401 additions and 90 deletions.
2 changes: 1 addition & 1 deletion admin-frontend/app_mr_layer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<plugin>
<groupId>io.repaint.maven</groupId>
<artifactId>tiles-maven-plugin</artifactId>
<version>2.17</version>
<version>2.32</version>
<extensions>true</extensions>
<configuration>
<filtering>false</filtering>
Expand Down
8 changes: 4 additions & 4 deletions admin-frontend/open_admin_app/lib/config/route_handlers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ class RouteCreator {
child: const ManageAdminServiceAccountsRoute());
}

Widget systemConfig(mrBloc,
{Map<String, List<String?>> params = const {}}) {
return BlocProvider<SystemConfigBloc>(creator: (context,bag) => SystemConfigBloc(mrBloc),
child: SystemConfigPanel());
Widget systemConfig(mrBloc, {Map<String, List<String?>> params = const {}}) {
return BlocProvider<SystemConfigBloc>(
creator: (context, bag) => SystemConfigBloc(mrBloc),
child: const SystemConfigPanel());
}

Widget serviceAccount(mrBloc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class CustomTextStyle {
}

static TextStyle bodyMediumBold(BuildContext context) {
return TextStyle(fontWeight: FontWeight.bold);
return const TextStyle(fontWeight: FontWeight.bold);
}
}
7 changes: 6 additions & 1 deletion admin-frontend/open_admin_app/lib/widget_creator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:open_admin_app/widgets/common/fh_error_message_details_widget.da
import 'package:open_admin_app/widgets/user/common/select_portfolio_group_bloc.dart';
import 'package:open_admin_app/widgets/user/edit/edit_user_bloc.dart';
import 'package:open_admin_app/widgets/user/signin/signin_widget.dart';
import 'package:open_admin_app/widgets/version-check/version_check_widget.dart';

import 'api/client_api.dart';

Expand All @@ -26,7 +27,9 @@ class WidgetCreator {
List<Widget> extraGlobalMenuItems(ManagementRepositoryClientBloc client) =>
[];

String externalOrganisationUrl(String urlPrefix, String urlPartial, ManagementRepositoryClientBloc client) => "";
String externalOrganisationUrl(String urlPrefix, String urlPartial,
ManagementRepositoryClientBloc client) =>
"";

Widget errorMessageDetailsWidget({required FHError fhError}) {
return FHErrorMessageDetailsWidget(fhError: fhError);
Expand All @@ -43,6 +46,8 @@ class WidgetCreator {
adminSdkBaseUrlWidget(ManagementRepositoryClientBloc mrClient) {
return const SizedBox.shrink();
}

Widget newVersionCheckWidget() => const VersionCheckWidget();
}

WidgetCreator widgetCreator = WidgetCreator();
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:open_admin_app/widgets/apps/webhook/track_events_panel_widget.dart';
import 'package:open_admin_app/widgets/apps/webhook/webhook_env_bloc.dart';
import 'package:open_admin_app/widgets/common/fh_external_link_outlined_widget.dart';
import 'package:open_admin_app/widgets/common/fh_external_link_widget.dart';

class SlackPanelWidget extends StatefulWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:mrapi/api.dart';
import 'package:open_admin_app/widgets/apps/webhook/slack_panel_widget.dart';
import 'package:open_admin_app/widgets/apps/webhook/webhook_env_bloc.dart';
import 'package:open_admin_app/widgets/apps/webhook/webhook_environment_table_widget.dart';
import 'package:open_admin_app/widgets/common/fh_external_link_widget.dart';
import 'package:open_admin_app/widgets/common/fh_loading_error.dart';
import 'package:open_admin_app/widgets/common/fh_loading_indicator.dart';

Expand Down
14 changes: 11 additions & 3 deletions admin-frontend/open_admin_app/lib/widgets/common/fh_appbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,17 @@ class FHappBar extends StatelessWidget {
if (appVersion != 'main')
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
' (v$appVersion)',
style: const TextStyle(fontSize: 10.0),
child: Row(
children: [
Text(
' (v$appVersion)',
style: const TextStyle(fontSize: 10.0),
),
const SizedBox(
width: 16.0,
),
if (isWide) widgetCreator.newVersionCheckWidget()
],
),
)
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';

class FhAttentionWidget extends StatelessWidget {
final String text;

const FhAttentionWidget({super.key, required this.text});

@override
Widget build(BuildContext context) {
return Row(
children: [
const Icon(Icons.lightbulb_outline_sharp,
size: 24.0, color: Colors.orange),
const SizedBox(width: 4.0),
Text(text,
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: Colors.orange)),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ class EditingRolloutStrategy {

RolloutStrategy? toRolloutStrategy(dynamic value) {
if (name == null ||
attributes.any((rsa) => rsa.toRolloutStrategyAttribute() == null))
attributes.any((rsa) => rsa.toRolloutStrategyAttribute() == null)) {
return null;
}
return RolloutStrategy(
id: id,
name: name!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SiteSystemConfigState extends State<SiteSystemConfigWidget>
@override
Widget build(BuildContext context) {
if (settings.isEmpty || loading) {
return FHLoadingIndicator();
return const FHLoadingIndicator();
}

try {
Expand Down Expand Up @@ -132,8 +132,8 @@ class SiteSystemConfigState extends State<SiteSystemConfigWidget>
],
);
} catch (e, s) {
fhosLogger.severe("failed ${e}: ${s}");
return SizedBox.shrink();
fhosLogger.severe("failed $e: $s");
return const SizedBox.shrink();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:mrapi/api.dart';
import 'package:open_admin_app/fhos_logger.dart';
import 'package:open_admin_app/widget_creator.dart';
import 'package:open_admin_app/widgets/common/fh_external_link_outlined_widget.dart';
import 'package:open_admin_app/widgets/common/fh_external_link_widget.dart';
import 'package:open_admin_app/widgets/common/fh_loading_indicator.dart';
Expand Down Expand Up @@ -192,7 +191,7 @@ class SlackSystemConfigState extends State<SlackSystemConfigWidget>
);
} catch (e, s) {
fhosLogger.severe("failed $e: $s");
return SizedBox.shrink();
return const SizedBox.shrink();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:mrapi/api.dart';
import 'package:open_admin_app/fhos_logger.dart';
import 'package:open_admin_app/widgets/common/fh_flat_button.dart';
import 'package:open_admin_app/widgets/systemconfig/systemconfig_bloc.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';

Expand Down Expand Up @@ -84,28 +83,28 @@ class _SystemConfigDataSource extends DataGridSource {
]))
.toList();

_encryptedKey = '${systemConfigKey}.encrypt';
_encryptedKey = '$systemConfigKey.encrypt';
encryptedRows = sourceData[_encryptedKey]
?.split(',')
.whereNot((k) => k.isEmpty)
.toList() ??
[];

fhosLogger.info("reset to ${sourceData}, e-rows ${encryptedRows}");
fhosLogger.info("reset to $sourceData, e-rows $encryptedRows");

// prefill
_deletedKey = '${systemConfigKey}.deleted';
_deletedKey = '$systemConfigKey.deleted';
deletedRows.clear();
}

submit() {
fhosLogger.info(
"sourceData is ${sourceData}, e-rows ${encryptedRows}, d-rows ${deletedRows}");
var _deletedRows = deletedRows
"sourceData is $sourceData, e-rows $encryptedRows, d-rows $deletedRows");
var rows = deletedRows
.where((k) => sourceData[k] == null)
.where((k) => k.isNotEmpty);
if (_deletedRows.isNotEmpty) {
sourceData[_deletedKey] = _deletedRows.join(',');
if (rows.isNotEmpty) {
sourceData[_deletedKey] = rows.join(',');
}
sourceData[_encryptedKey] =
encryptedRows.where((k) => k.isNotEmpty).join(",");
Expand All @@ -121,6 +120,7 @@ class _SystemConfigDataSource extends DataGridSource {
return _rows;
}

@override
bool onCellBeginEdit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex,
GridColumn column) {
if (rowColumnIndex.columnIndex > 1) return false;
Expand Down Expand Up @@ -171,8 +171,9 @@ class _SystemConfigDataSource extends DataGridSource {
@override
Future<void> onCellSubmit(DataGridRow dataGridRow,
RowColumnIndex rowColumnIndex, GridColumn column) async {
if (rowColumnIndex.columnIndex < 0 || rowColumnIndex.columnIndex > 1)
if (rowColumnIndex.columnIndex < 0 || rowColumnIndex.columnIndex > 1) {
return;
}

final oldValue = dataGridRow.getCells()[rowColumnIndex.columnIndex].value;

Expand All @@ -198,7 +199,7 @@ class _SystemConfigDataSource extends DataGridSource {
newCellValue;
}

fhosLogger.info("sourceMap is now ${sourceData}, e-rows ${encryptedRows}");
fhosLogger.info("sourceMap is now $sourceData, e-rows $encryptedRows");

// To reset the new cell value after successfully updated to DataGridRow
//and underlying mode.
Expand Down Expand Up @@ -314,7 +315,7 @@ class _SystemConfigDataSource extends DataGridSource {
if (key.isNotEmpty) {
encryptedRows.add(key);
}
fhosLogger.info(", e-rows ${encryptedRows}");
fhosLogger.info(", e-rows $encryptedRows");
}

// we have to do it this way, getting the key at the last second as it may change
Expand Down Expand Up @@ -369,7 +370,7 @@ class _SystemConfigDataSource extends DataGridSource {
addRow(String key, String value) {
if (sourceData[key] != null) return;

fhosLogger.info("adding ${key} with value ${value}");
fhosLogger.info("adding $key with value $value");
sourceData[key] = value;
_rows.add(DataGridRow(cells: [
DataGridCell(columnName: keyRowName, value: key),
Expand Down Expand Up @@ -479,7 +480,8 @@ class SystemConfigEncryptableMapWidgetState
alignment: Alignment.center,
child: Text(
widget.keyHeaderName,
style: TextStyle(fontWeight: FontWeight.bold),
style: const TextStyle(
fontWeight: FontWeight.bold),
))),
GridColumn(
columnName: 'value',
Expand All @@ -488,8 +490,8 @@ class SystemConfigEncryptableMapWidgetState
padding: const EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text(widget.valueHeaderName,
style:
TextStyle(fontWeight: FontWeight.bold)))),
style: const TextStyle(
fontWeight: FontWeight.bold)))),
GridColumn(
columnName: 'actions',
allowEditing: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:bloc_provider/bloc_provider.dart';
import 'package:flutter/material.dart';
import 'package:mrapi/api.dart';
import 'package:open_admin_app/widgets/common/fh_flat_button.dart';
import 'package:open_admin_app/widgets/systemconfig/systemconfig_bloc.dart';

class SystemConfigEncryptableTextField extends StatefulWidget {
Expand Down Expand Up @@ -64,7 +63,7 @@ class SystemConfigEncryptableTextFieldState
} else {
widget.field.value = val;
}
},
},
decoration: widget.decoration,
)),
if (_textField.text == 'ENCRYPTED-TEXT')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@


import 'dart:convert';

import 'package:bloc_provider/bloc_provider.dart';
import 'package:dio/dio.dart';
import 'package:mrapi/api.dart';
import 'package:open_admin_app/api/client_api.dart';
import 'package:open_admin_app/fhos_logger.dart';
import 'package:rxdart/rxdart.dart';


class SystemConfigBloc implements Bloc {
final ManagementRepositoryClientBloc mrClient;
final SystemConfigServiceApi systemConfigServiceApi;
final knownConfigs = BehaviorSubject<List<SystemConfig>?>.seeded(null);

Stream<List<SystemConfig>?> get knownConfigStream => knownConfigs.stream;

SystemConfigBloc(this.mrClient):
systemConfigServiceApi = SystemConfigServiceApi(mrClient.apiClient)
{
SystemConfigBloc(this.mrClient)
: systemConfigServiceApi = SystemConfigServiceApi(mrClient.apiClient) {
_loadConfigs();
}

Expand All @@ -38,7 +33,8 @@ class SystemConfigBloc implements Bloc {
}

Future<String?> knownSiteRedirectUrl(String externalOrganisationUrl) async {
final data = await mrClient.apiClient.invokeAPI(externalOrganisationUrl, [], null, ['bearerAuth'], Options());
final data = await mrClient.apiClient.invokeAPI(
externalOrganisationUrl, [], null, ['bearerAuth'], Options());
if (data.statusCode == 200 && data.body != null) {
return await utf8.decodeStream(data.body!);
}
Expand Down
Loading

0 comments on commit 259825b

Please sign in to comment.