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

feat: Skip landscape page #997

Merged
merged 10 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:ubuntupro/core/environment.dart';
import 'package:ubuntupro/launch_agent.dart';
import 'package:ubuntupro/main.dart' as app;
import 'package:ubuntupro/pages/landscape/landscape_page.dart';
import 'package:ubuntupro/pages/landscape_skip/landscape_skip_page.dart';
import 'package:ubuntupro/pages/startup/startup_page.dart';
import 'package:ubuntupro/pages/subscribe_now/subscribe_now_page.dart';
import 'package:ubuntupro/pages/subscription_status/subscription_status_page.dart';
Expand Down Expand Up @@ -128,18 +129,15 @@ void main() {
await tester.tap(button);
await tester.pumpAndSettle();

// check that we transitioned to the LandscapePage
l10n = tester.l10n<LandscapePage>();
// check we transition to skip page
l10n = tester.l10n<LandscapeSkipPage>();
final radios = find.byType(YaruSelectableContainer);
expect(radios, findsNWidgets(3));
await tester.tap(radios.at(1));
await tester.pump();
await tester.tap(radios.at(0));
await tester.pump();
await tester.tap(radios.at(2));
await tester.pump();
final skip = find.button(l10n.buttonSkip);
expect(radios, findsNWidgets(2));
final skip = find.text(l10n.landscapeSkip);
await tester.tap(skip);
await tester.pump();
final next = find.button(l10n.buttonNext);
await tester.tap(next);
await tester.pumpAndSettle();

// checks that we transitioned to the SubscriptionStatusPage
Expand Down Expand Up @@ -172,6 +170,17 @@ void main() {
await tester.tap(button);
await tester.pumpAndSettle();

// check we transition to skip page
l10n = tester.l10n<LandscapeSkipPage>();
final radios = find.byType(YaruSelectableContainer);
expect(radios, findsNWidgets(2));
final register = find.text(l10n.landscapeSkipRegister);
await tester.tap(register);
await tester.pump();
final next = find.button(l10n.buttonNext);
await tester.tap(next);
await tester.pumpAndSettle();

// check that we transitioned to the LandscapePage
l10n = tester.l10n<LandscapePage>();
final selfHostedRadio = find.ancestor(
Expand Down
12 changes: 12 additions & 0 deletions gui/packages/ubuntupro/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'core/agent_connection.dart';
import 'core/agent_monitor.dart';
import 'core/settings.dart';
import 'pages/landscape/landscape_page.dart';
import 'pages/landscape_skip/landscape_skip_page.dart';
import 'pages/startup/startup_page.dart';
import 'pages/subscribe_now/subscribe_now_page.dart';
import 'pages/subscription_status/subscription_status_page.dart';
Expand Down Expand Up @@ -76,6 +77,17 @@ class Pro4WSLApp extends StatelessWidget {
},
),
if (settings.isLandscapeConfigurationEnabled) ...{
Routes.skipLandscape: WizardRoute(
builder: (_) => const LandscapeSkipPage(),
onNext: (settings) {
switch (settings.arguments as SkipEnum) {
case SkipEnum.skip:
return Routes.subscriptionStatus;
default:
return null;
}
},
),
Routes.configureLandscape:
const WizardRoute(builder: LandscapePage.create),
Routes.subscriptionStatus: WizardRoute(
Expand Down
2 changes: 2 additions & 0 deletions gui/packages/ubuntupro/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ const kVersion = String.fromEnvironment(
'UP4W_FULL_VERSION',
defaultValue: 'Dev',
);

const kLandscapeTitle = 'Landscape';
8 changes: 6 additions & 2 deletions gui/packages/ubuntupro/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
"purchaseStatusServer":"Something went wrong with Microsoft Store. Please try again later.",
"purchaseStatusUnknown": "Unknown error when trying to purchase the subscription. Consider restarting this app.",

"landscapeHeading": "Configure the connection to {landscapeLink} to manage your Ubuntu WSL instances remotely.",
"landscapeSkip": "Skip for now",
"landscapeSkipDescription": "You can always configure Landscape later in this app",
"landscapeSkipRegister": "Register with Landscape",

"landscapeHeading": "Configure the connection to Landscape to manage your Ubuntu WSL instances remotely. {landscapeLink}",
"@landscapeHeading": {
"placeholders": {
"landscapeLink": {
Expand Down Expand Up @@ -95,7 +99,7 @@
}
},

"buttonNext": "Continue",
"buttonNext": "Next",
"buttonSkip": "Skip",
"buttonBack": "Back",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LandscapeModel extends ChangeNotifier {
LandscapeModel(this.client);

/// The URL to be shown in the UI.
final landscapeURI = Uri.https('ubuntu.com', '/landscape');
static final landscapeURI = Uri.https('ubuntu.com', '/landscape');

/// Whether the current form is complete (ready to be submitted).
bool get isComplete => _active.isComplete;
Expand Down
27 changes: 4 additions & 23 deletions gui/packages/ubuntupro/lib/pages/landscape/landscape_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:yaru/yaru.dart';

import '/core/agent_api_client.dart';
import '/pages/widgets/page_widgets.dart';
import '../../constants.dart';
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved
import 'landscape_model.dart';

const _kHeight = 8.0;
Expand All @@ -25,7 +26,6 @@ class LandscapePage extends StatelessWidget {
super.key,
required this.onApplyConfig,
required this.onBack,
required this.onSkip,
});

/// Callable invoked when this page successfully applies the configuration.
Expand All @@ -34,9 +34,6 @@ class LandscapePage extends StatelessWidget {
/// Callable invoked when the user navigates back.
final void Function() onBack;

/// Callable invoked when the user skips this page.
final void Function() onSkip;

@override
Widget build(BuildContext context) {
final lang = AppLocalizations.of(context);
Expand All @@ -49,21 +46,17 @@ class LandscapePage extends StatelessWidget {
),
),
),
).copyWith(
a: const TextStyle(
decoration: TextDecoration.underline,
),
);

return LandingPage(
svgAsset: 'assets/Landscape-tag.svg',
title: 'Landscape',
title: kLandscapeTitle,
children: [
// Only rebuilds if the value of model.landscapeURI changes (never in production)
Selector<LandscapeModel, Uri>(
selector: (_, model) => model.landscapeURI,
selector: (_, model) => LandscapeModel.landscapeURI,
builder: (context, uri, _) => MarkdownBody(
data: lang.landscapeHeading('[Landscape]($uri)'),
data: lang.landscapeHeading('[${lang.learnMore}]($uri)'),
onTapLink: (_, href, __) => launchUrl(uri),
styleSheet: linkStyle,
),
Expand All @@ -79,7 +72,6 @@ class LandscapePage extends StatelessWidget {
selector: (_, model) => model.isComplete,
builder: (context, isComplete, _) => _NavigationButtonRow(
onBack: onBack,
onSkip: onSkip,
onNext: isComplete ? () => _tryApplyConfig(context) : null,
),
),
Expand Down Expand Up @@ -114,13 +106,11 @@ class LandscapePage extends StatelessWidget {
landscapePage = LandscapePage(
onApplyConfig: Wizard.of(context).back,
onBack: Wizard.of(context).back,
onSkip: Wizard.of(context).back,
);
} else {
landscapePage = LandscapePage(
onApplyConfig: Wizard.of(context).next,
onBack: Wizard.of(context).back,
onSkip: Wizard.of(context).next,
);
}

Expand Down Expand Up @@ -242,12 +232,10 @@ class LandscapeConfigForm extends StatelessWidget {
class _NavigationButtonRow extends StatelessWidget {
const _NavigationButtonRow({
this.onBack,
this.onSkip,
this.onNext,
});

final void Function()? onBack;
final void Function()? onSkip;
final void Function()? onNext;

@override
Expand All @@ -261,13 +249,6 @@ class _NavigationButtonRow extends StatelessWidget {
child: Text(lang.buttonBack),
),
const Spacer(),
FilledButton(
onPressed: onSkip,
child: Text(lang.buttonSkip),
),
const SizedBox(
width: 16.0,
),
ElevatedButton(
onPressed: onNext,
child: Text(lang.buttonNext),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:wizard_router/wizard_router.dart';

import '../../constants.dart';
import '../landscape/landscape_model.dart';
import '../widgets/navigation_row.dart';
import '../widgets/page_widgets.dart';
import '../widgets/radio_tile.dart';

enum SkipEnum {
skip,
register,
}

class LandscapeSkipPage extends StatefulWidget {
const LandscapeSkipPage({super.key});

@override
State<LandscapeSkipPage> createState() => _LandscapeSkipPageState();
}

class _LandscapeSkipPageState extends State<LandscapeSkipPage> {
SkipEnum groupValue = SkipEnum.skip;

@override
Widget build(BuildContext context) {
final lang = AppLocalizations.of(context);
final wizard = Wizard.of(context);

return ColumnPage(
svgAsset: 'assets/Landscape-tag.svg',
title: kLandscapeTitle,
left: [
MarkdownBody(
data: lang.landscapeHeading(
'[${lang.learnMore}](${LandscapeModel.landscapeURI})',
),
onTapLink: (_, href, __) => launchUrl(LandscapeModel.landscapeURI),
),
],
right: [
RadioTile(
value: SkipEnum.skip,
title: lang.landscapeSkip,
subtitle: lang.landscapeSkipDescription,
groupValue: groupValue,
onChanged: (v) => setState(() {
groupValue = v!;
}),
),
RadioTile(
value: SkipEnum.register,
title: lang.landscapeSkipRegister,
groupValue: groupValue,
onChanged: (v) => setState(() {
groupValue = v!;
}),
),
],
navigationRow: NavigationRow(
onBack: wizard.back,
onNext: () => wizard.next(arguments: groupValue),

Check warning on line 65 in gui/packages/ubuntupro/lib/pages/landscape_skip/landscape_skip_page.dart

View check run for this annotation

Codecov / codecov/patch

gui/packages/ubuntupro/lib/pages/landscape_skip/landscape_skip_page.dart#L65

Added line #L65 was not covered by tests
),
);
}
}
36 changes: 36 additions & 0 deletions gui/packages/ubuntupro/lib/pages/widgets/navigation_row.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class NavigationRow extends StatelessWidget {
const NavigationRow({
required this.onBack,
required this.onNext,
this.backText,
this.nextText,
super.key,
});

final void Function()? onBack;
final String? backText;
final void Function()? onNext;
final String? nextText;

@override
Widget build(BuildContext context) {
final lang = AppLocalizations.of(context);

return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
OutlinedButton(
onPressed: onBack,
child: Text(backText ?? lang.buttonBack),
),
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved
FilledButton(
onPressed: onNext,
child: Text(nextText ?? lang.buttonNext),
),
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved
],
);
}
}
Loading
Loading