Skip to content

Commit

Permalink
[MBL-17888][Parent] Fixed help menu serialization #2586
Browse files Browse the repository at this point in the history
refs: MBL-17888
affects: Parent
release note: Fixed an issue where help links wouldn't load in some cases
  • Loading branch information
tamaskozmer authored Oct 7, 2024
1 parent 2a0b1d4 commit e692350
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 48 deletions.
8 changes: 4 additions & 4 deletions apps/flutter_parent/lib/models/help_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ abstract class HelpLink implements Built<HelpLink, HelpLinkBuilder> {

factory HelpLink([void Function(HelpLinkBuilder) updates]) = _$HelpLink;

String get id;
String? get id;

String get type;

@BuiltValueField(wireName: 'available_to')
BuiltList<AvailableTo> get availableTo;

String get url;
String? get url;

String get text;
String? get text;

String get subtext;
String? get subtext;
}

class AvailableTo extends EnumClass {
Expand Down
73 changes: 41 additions & 32 deletions apps/flutter_parent/lib/models/help_link.g.dart

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

24 changes: 12 additions & 12 deletions apps/flutter_parent/lib/screens/help/help_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class _HelpScreenState extends State<HelpScreen> {
List<Widget> _generateLinks(List<HelpLink>? links) {
List<Widget> helpLinks = List.from(links?.map(
(l) => ListTile(
title: Text(l.text, style: Theme.of(context).textTheme.titleMedium),
subtitle: Text(l.subtext, style: Theme.of(context).textTheme.bodySmall),
title: Text(l.text ?? '', style: Theme.of(context).textTheme.titleMedium),
subtitle: Text(l.subtext ?? '', style: Theme.of(context).textTheme.bodySmall),
onTap: () => _linkClick(l),
),
) ?? []);
Expand All @@ -84,7 +84,7 @@ class _HelpScreenState extends State<HelpScreen> {
}

void _linkClick(HelpLink link) {
String url = link.url;
String url = link.url ?? '';
if (url[0] == '#') {
// Internal link
if (url.contains('#create_ticket')) {
Expand All @@ -93,24 +93,24 @@ class _HelpScreenState extends State<HelpScreen> {
// Custom for Android
_showShareLove();
}
} else if (link.id.contains('submit_feature_idea')) {
} else if (link.id?.contains('submit_feature_idea') == true) {
_showRequestFeature();
} else if (link.url.startsWith('tel:+')) {
} else if (url.startsWith('tel:+')) {
// Support phone links: https://community.canvaslms.com/docs/DOC-12664-4214610054
locator<AndroidIntentVeneer>().launchPhone(link.url);
} else if (link.url.startsWith('mailto:')) {
locator<AndroidIntentVeneer>().launchPhone(url);
} else if (url.startsWith('mailto:')) {
// Support mailto links: https://community.canvaslms.com/docs/DOC-12664-4214610054
locator<AndroidIntentVeneer>().launchEmail(link.url);
} else if (link.url.contains('cases.canvaslms.com/liveagentchat')) {
locator<AndroidIntentVeneer>().launchEmail(url);
} else if (url.contains('cases.canvaslms.com/liveagentchat')) {
// Chat with Canvas Support - Doesn't seem work properly with WebViews, so we kick it out
// to the external browser
locator<UrlLauncher>().launch(link.url);
} else if (link.id.contains('search_the_canvas_guides')) {
locator<UrlLauncher>().launch(url);
} else if (link.id?.contains('search_the_canvas_guides') == true) {
// Send them to the mobile Canvas guides
_showSearch();
} else {
// External url
locator<UrlLauncher>().launch(link.url);
locator<UrlLauncher>().launch(url);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class HelpScreenInteractor {
link.availableTo.contains(AvailableTo.user));

List<HelpLink> filterObserverLinks(BuiltList<HelpLink> list) => list
.where((link) => link.url != null && link.text != null)
.where((link) =>
link.availableTo.contains(AvailableTo.observer) ||
link.availableTo.contains(AvailableTo.user))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ void main() {
observerLinks);
});

test('filterObserverLinks only returns links that has text and url', () async {
var validLinks = [
createHelpLink(availableTo: [AvailableTo.observer]),
createHelpLink(availableTo: [AvailableTo.user]),
];

var invalidLinks = [
createNullableHelpLink(url: 'url', availableTo: [AvailableTo.observer]),
createNullableHelpLink(text: 'text', availableTo: [AvailableTo.observer]),
];

expect(HelpScreenInteractor().filterObserverLinks(BuiltList.from([...validLinks, ...invalidLinks])),
validLinks);
});

test('custom list is returned if there are any custom lists', () async {
var api = MockHelpLinksApi();
var customLinks = [
Expand Down Expand Up @@ -144,3 +159,11 @@ HelpLink createHelpLink({String? id, String? text, String? url, List<AvailableTo
..url = url ?? 'https://www.instructure.com'
..text = text ?? 'text'
..subtext = 'subtext');

HelpLink createNullableHelpLink({String? id, String? text, String? url, List<AvailableTo>? availableTo}) => HelpLink((b) => b
..id = id
..type = ''
..availableTo = ListBuilder(availableTo != null ? availableTo : <AvailableTo>[])
..url = url
..text = text
..subtext = 'subtext');

0 comments on commit e692350

Please sign in to comment.