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

Replace AlphaVersionBanner with DevelopmentStageBanner. #1291

Merged
merged 2 commits into from
Feb 7, 2024

Conversation

Jonas-Sander
Copy link
Collaborator

@Jonas-Sander Jonas-Sander commented Feb 7, 2024

This replaces the AlphaVersionBanner with DevelopmentStageBanner so that a banner is always shown if the user uses a non-stable version of Sharezone.
This is useful for #1290 (new "preview" stage for preview builds in PRs).

Currently the banner is only shown in alpha, not in beta. This will show a banner in alpha and beta.

grafik

Summary by CodeRabbit

  • New Features
    • Introduced a Development Stage Banner to inform users about the current development stage of the app.
  • Refactor
    • Improved the flexibility of testing by allowing the development stage variable to be overridden.
    • Enhanced the Development Stage Banner to dynamically display the app's development stage.
  • Tests
    • Added tests to ensure the Development Stage Banner accurately reflects the app's current stage.

Copy link
Contributor

coderabbitai bot commented Feb 7, 2024

Walkthrough

The recent update introduces a new variable for testing development stages, enhances the visibility of the app's development stage through a banner, and refines widget functionality and testing. It shifts focus towards a more dynamic presentation of the app's current stage, improving both developer experience and end-user awareness regarding the app's maturity level.

Changes

File Path Change Summary
.../main/constants.dart Added kDevelopmentStageOrNull for testing development stages.
.../main/sharezone.dart Imported platform_check, removed constants.dart import, and replaced AlphaVersionBanner with DevelopmentStageBanner.
.../widgets/development_stage_banner.dart Renamed from AlphaVersionBanner, expanded to display development stage as a banner.
.../test_goldens/widgets/development_stage_banner_test.dart Added tests for DevelopmentStageBanner, verifying banner display based on development stage.

🐇✨
In the code's garden, changes bloom,
A banner now in every room.
From alpha to release, it shows,
Guiding where the project goes.
🌱🚀

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@Jonas-Sander Jonas-Sander marked this pull request as ready for review February 7, 2024 14:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 12008af and 4c6e6b7.
Files selected for processing (4)
  • app/lib/main/constants.dart (1 hunks)
  • app/lib/main/sharezone.dart (2 hunks)
  • app/lib/widgets/development_stage_banner.dart (1 hunks)
  • app/test_goldens/widgets/development_stage_banner_test.dart (1 hunks)
Additional comments: 2
app/lib/main/sharezone.dart (2)
  • 17-17: Ensure platform_check is used elsewhere in the file; otherwise, its import is unnecessary.
  • 33-33: The replacement of AlphaVersionBanner with DevelopmentStageBanner is consistent with the PR objectives.

Comment on lines +9 to +11
// Can be overridden for testing purposes.
String? kDevelopmentStageOrNull =
kDevelopmentStage == "" ? null : kDevelopmentStage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure kDevelopmentStage is defined before kDevelopmentStageOrNull to avoid referencing an undefined variable.

- String? kDevelopmentStageOrNull =
-     kDevelopmentStage == "" ? null : kDevelopmentStage;
- const kDevelopmentStage = String.fromEnvironment('DEVELOPMENT_STAGE');
+ const kDevelopmentStage = String.fromEnvironment('DEVELOPMENT_STAGE');
+ String? kDevelopmentStageOrNull =
+     kDevelopmentStage == "" ? null : kDevelopmentStage;

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// Can be overridden for testing purposes.
String? kDevelopmentStageOrNull =
kDevelopmentStage == "" ? null : kDevelopmentStage;
const kDevelopmentStage = String.fromEnvironment('DEVELOPMENT_STAGE');
String? kDevelopmentStageOrNull =
kDevelopmentStage == "" ? null : kDevelopmentStage;

Comment on lines +36 to +38
bool get _isStable =>
kDevelopmentStageOrNull == null || _uppercasedStage == 'STABLE';
String? get _uppercasedStage => kDevelopmentStageOrNull?.toUpperCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider caching _uppercasedStage to avoid calling toUpperCase() multiple times.

+  late final String? _cachedUppercasedStage = kDevelopmentStageOrNull?.toUpperCase();
+  String? get _uppercasedStage => _cachedUppercasedStage;

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
bool get _isStable =>
kDevelopmentStageOrNull == null || _uppercasedStage == 'STABLE';
String? get _uppercasedStage => kDevelopmentStageOrNull?.toUpperCase();
bool get _isStable =>
kDevelopmentStageOrNull == null || _uppercasedStage == 'STABLE';
late final String? _cachedUppercasedStage = kDevelopmentStageOrNull?.toUpperCase();
String? get _uppercasedStage => _cachedUppercasedStage;

Comment on lines 8 to 60

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:sharezone/main/constants.dart';

/// Displays a [Banner] saying "ALPHA" when running an alpha version at top left
/// hand corner.
/// Displays the current development stage as a [Banner] if it is not stable.
///
/// Displays nothing when [enabled] is false.
/// Sharezone has different development stages e.g. "alpha", "beta", "preview".
/// This widget displays the current development stage as a [Banner] at the top
/// hand corner of the screen if we are not in the stable/production development
/// stage.
///
/// This is intended so that users know that they are using a non-stable version
/// of the app and that they should expect bugs and other issues.
///
/// This widget is similar and inspired by the [CheckedModeBanner] which displays
/// "DEBUG" at the top right hand corner when running a Flutter app in debug
/// mode.
class AlphaVersionBanner extends StatelessWidget {
class DevelopmentStageBanner extends StatelessWidget {
/// Creates a const alpha version banner.
const AlphaVersionBanner({
const DevelopmentStageBanner({
super.key,
required this.child,
required this.enabled,
});

/// The widget to show behind the banner.
final Widget child;

/// Defines if the alpha banner should shown.
///
/// If set to false, the banner will not be shown and is not visible.
final bool enabled;
bool get _isStable =>
kDevelopmentStageOrNull == null || _uppercasedStage == 'STABLE';
String? get _uppercasedStage => kDevelopmentStageOrNull?.toUpperCase();

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
String message = 'disabled';
if (enabled) {
message = 'ALPHA';
if (!_isStable) {
message = _uppercasedStage!;
}
properties.add(DiagnosticsNode.message(message));
}

@override
Widget build(BuildContext context) {
if (!enabled) {
if (_isStable) {
return child;
}

return Banner(
message: 'ALPHA',
message: _uppercasedStage!,
textDirection: TextDirection.ltr,
location: BannerLocation.topEnd,
color: Colors.blue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [57-61]

Use BannerLocation.topStart instead of BannerLocation.topEnd for consistency with the description of displaying the banner at the top left corner.

-      location: BannerLocation.topEnd,
+      location: BannerLocation.topStart,

Comment on lines +20 to +33
kDevelopmentStageOrNull = 'alpha';

await tester.pumpWidgetBuilder(
const DevelopmentStageBanner(
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Text("Text"),
),
),
),
);

await screenMatchesGolden(tester, 'alpha_version_banner');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure kDevelopmentStageOrNull is reset to its original value after each test to avoid side effects between tests.

+ tearDown(() {
+   kDevelopmentStageOrNull = null;
+ });

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
kDevelopmentStageOrNull = 'alpha';
await tester.pumpWidgetBuilder(
const DevelopmentStageBanner(
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Text("Text"),
),
),
),
);
await screenMatchesGolden(tester, 'alpha_version_banner');
kDevelopmentStageOrNull = 'alpha';
await tester.pumpWidgetBuilder(
const DevelopmentStageBanner(
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Text("Text"),
),
),
),
);
await screenMatchesGolden(tester, 'alpha_version_banner');
tearDown(() {
kDevelopmentStageOrNull = null;
});

Comment on lines +37 to +83
testWidgets("does display the banner if stage is alpha, beta or preview",
(tester) async {
for (var stage in ['alpha', 'beta', 'preview']) {
kDevelopmentStageOrNull = stage;

await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: DevelopmentStageBanner(
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Text("Text"),
),
),
),
),
);

expect(find.byType(Banner), findsOneWidget,
reason: 'Stage "$stage" should display the banner');
}
});

testWidgets("does not display the banner if stage is 'stable' or null",
(tester) async {
for (var stage in ['stable', null]) {
kDevelopmentStageOrNull = stage;

await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: DevelopmentStageBanner(
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Text("Text"),
),
),
),
),
);

expect(find.byType(Banner), findsNothing,
reason: 'Stage "$stage" should not display the banner');
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider parameterizing tests for different stages to reduce code duplication.

-    testWidgets("does display the banner if stage is alpha, beta or preview",
-        (tester) async {
-      for (var stage in ['alpha', 'beta', 'preview']) {
-        kDevelopmentStageOrNull = stage;
-        ...
-      }
-    });
-    testWidgets("does not display the banner if stage is 'stable' or null",
-        (tester) async {
-      for (var stage in ['stable', null]) {
-        kDevelopmentStageOrNull = stage;
-        ...
-      }
-    });
+    final stagesWithBanner = ['alpha', 'beta', 'preview'];
+    final stagesWithoutBanner = ['stable', null];
+    for (var stage in [...stagesWithBanner, ...stagesWithoutBanner]) {
+      testWidgets("displays banner correctly for stage $stage", (tester) async {
+        kDevelopmentStageOrNull = stage;
+        ...
+        final expectedFindings = stagesWithBanner.contains(stage) ? findsOneWidget : findsNothing;
+        expect(find.byType(Banner), expectedFindings, reason: 'Stage "$stage" should ${expectedFindings == findsOneWidget ? '' : 'not '}display the banner');
+      });
+    }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
testWidgets("does display the banner if stage is alpha, beta or preview",
(tester) async {
for (var stage in ['alpha', 'beta', 'preview']) {
kDevelopmentStageOrNull = stage;
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: DevelopmentStageBanner(
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Text("Text"),
),
),
),
),
);
expect(find.byType(Banner), findsOneWidget,
reason: 'Stage "$stage" should display the banner');
}
});
testWidgets("does not display the banner if stage is 'stable' or null",
(tester) async {
for (var stage in ['stable', null]) {
kDevelopmentStageOrNull = stage;
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: DevelopmentStageBanner(
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Text("Text"),
),
),
),
),
);
expect(find.byType(Banner), findsNothing,
reason: 'Stage "$stage" should not display the banner');
}
});
final stagesWithBanner = ['alpha', 'beta', 'preview'];
final stagesWithoutBanner = ['stable', null];
for (var stage in [...stagesWithBanner, ...stagesWithoutBanner]) {
testWidgets("displays banner correctly for stage $stage", (tester) async {
kDevelopmentStageOrNull = stage;
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: DevelopmentStageBanner(
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Text("Text"),
),
),
),
),
);
final expectedFindings = stagesWithBanner.contains(stage) ? findsOneWidget : findsNothing;
expect(find.byType(Banner), expectedFindings,
reason: 'Stage "$stage" should ${expectedFindings == findsOneWidget ? '' : 'not '}display the banner');
});
}

Copy link

github-actions bot commented Feb 7, 2024

Visit the preview URL for this PR (updated for commit 4c6e6b7):

https://sharezone-test--pr1291-add-deployment-stage-x9bsmr71.web.app

(expires Sat, 10 Feb 2024 14:29:38 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 4cb3ae61e1e018abfd9841fd3239f5b49ccc034b

Copy link
Member

@nilsreichardt nilsreichardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Jonas-Sander Jonas-Sander added this pull request to the merge queue Feb 7, 2024
github-merge-queue bot pushed a commit that referenced this pull request Feb 7, 2024
…it. (#1290)

Use `sz build web` in web-app preview job and add `preview` stage to it.

Together with #1291 this will display a "PREVIEW" banner for all
previews.

Since this uses `pull_request_target` one can't see it in the preview
here. I checked manually though (by overriding `pull_request_target`
with `pull_request`)
Merged via the queue into main with commit a38bed9 Feb 7, 2024
41 of 44 checks passed
@Jonas-Sander Jonas-Sander deleted the add-deployment-stage-banner branch February 7, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants