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

[ToB] [Frontend] Authentication, unit progress, complete unit, SDK selection #24457

Merged
merged 73 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
7c23033
Content tree navigation (#23593)
Oct 21, 2022
5978d37
AnimatedBuilders instead of StatefulWidgets in unit & group (#23593)
Nov 4, 2022
8807c00
fixed _getNodeAncestors (#23593)
Nov 5, 2022
8e8d8c9
get sdkId (#23593)
Nov 5, 2022
2ab4b3b
addressing comments (#23593)
Nov 8, 2022
57800ee
sdkId getter & StatelessExpansionTile (#23593)
Nov 9, 2022
28cb6b8
expand & collapse group (#23593)
Nov 9, 2022
85e1234
StatelessExpansionTile (#23593)
Nov 9, 2022
8dc7719
license (#23593)
Nov 10, 2022
e4dee7b
ValueChanged and ValueKey in StatelessExpansionTile (#23593)
Nov 11, 2022
5b07e91
optional SDK selector in tour scaffold
Nov 14, 2022
497ff7c
AppNotifier
Nov 14, 2022
83c9c0e
moved AppNotifier into _initializeState
Nov 15, 2022
9d1f49b
StorageKeys
Nov 15, 2022
b78bbd3
remove listener
Nov 16, 2022
5297d25
auth, complete unit, user progress
Oct 19, 2022
d25eaf5
Merge branch 'master' into issue23692_auth
nausharipov Nov 18, 2022
12a685d
unit file fix
Nov 18, 2022
3c534d8
Merge remote-tracking branch 'origin/tour-header-sdk-selector' into a…
nausharipov Nov 18, 2022
de0f7c3
sdk selection works with auth
Nov 18, 2022
3a10e8d
show sdk selector in welcome screen
Nov 18, 2022
de273ba
hide back button after navigating from welcome
Nov 18, 2022
70c0d61
comments (0)
Nov 19, 2022
6f53e30
cache license
Nov 21, 2022
4aedd5a
SDK selector with fixed comments
Nov 21, 2022
5ad067f
non-nullable onChanged
Nov 21, 2022
10b287b
Merge pull request #324 from akvelon/tour-header-sdk-selector
nausharipov Nov 21, 2022
a6597d4
untested refinement
Nov 21, 2022
2068ce9
deleted show sdk selector
Nov 21, 2022
52838e5
notifier objects naming
Nov 21, 2022
3df27bc
untested refinement (1)
Nov 22, 2022
0b6fc8f
candidate repository
Nov 22, 2022
7fbaf38
new configs & todos
Nov 23, 2022
64965a1
canCompleteCurrentUnit (#23692)
Nov 24, 2022
6d21e1e
kOpenLoginOverlay (#23692)
Nov 24, 2022
2c90ced
login_overlay (#23692)
Nov 24, 2022
6ed38ac
unused import (#23692)
Nov 24, 2022
adbdeb6
deleted file (#23692)
Nov 24, 2022
c2f74a5
review comments (2)
Nov 27, 2022
a575717
deleted pubspec.lock
Nov 28, 2022
8607808
pubspec.lock in gitignore
Nov 28, 2022
1bbc092
comment fixes (3)
Nov 28, 2022
65dc521
updating & blocking complete unit button (#23692)
Nov 28, 2022
d55622e
missing await
Nov 28, 2022
c6004b0
no final else
Nov 28, 2022
0a76b40
pubspec.lock ignored only in PGC
Nov 29, 2022
749d8b1
pubspec.lock
Nov 29, 2022
fb1fea1
comment fixes (4)
Nov 29, 2022
ef63740
rearranged completeUnit (#23692)
Nov 29, 2022
4b2d855
renamed user progress model to unit progress (#23692)
Nov 29, 2022
27b26e4
clearUpdatingUnitId (#23692)
Nov 29, 2022
b6c4e3e
added async (#23692)
Nov 29, 2022
1e38328
removed "fix exception" todo after filing an issue (#23692)
Nov 29, 2022
96e41f7
Merge from master
Nov 30, 2022
e215ec4
generated files
Nov 30, 2022
a107952
renamed user progress cache to unit progress (#23692)
Dec 1, 2022
8b639d0
all caches extend cache (#23692)
Dec 1, 2022
c8db1ef
refined open overlay (#23692)
Dec 1, 2022
869b40c
extracted overlay body (#23692)
Dec 1, 2022
9720c13
moved dismissible overlay (#23692)
Dec 1, 2022
9e1bbb0
specific imports (#23692)
Dec 1, 2022
af936d0
added firebase_options.dart into gradle rat exclusions & added a miss…
Dec 1, 2022
d060372
removed padding from user menu (#23692)
Dec 6, 2022
a988404
documentation update (#23692)
Dec 7, 2022
943391d
Merge branch 'master' into issue23692_auth
Dec 23, 2022
dbcf032
Merge branch 'master' into issue23692_auth
Dec 26, 2022
d8b5c11
removed goToContextLine
Jan 6, 2023
ff8d32b
sdk getter (#23692)
Jan 6, 2023
256d7b7
todo: remove sdkId getter and setter (#23692)
Jan 6, 2023
6dd0a3b
todo: add unit and integration tests (#23692)
Jan 6, 2023
fddeaee
updated readme (#23692)
Jan 6, 2023
dc4e142
Merge branch 'master' into issue23692_auth
Jan 9, 2023
f33a4c2
addressing comments (#23692)
Jan 12, 2023
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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ tasks.rat {
"learning/tour-of-beam/frontend/**/*.gen.dart",
"learning/tour-of-beam/frontend/.metadata",
"learning/tour-of-beam/frontend/pubspec.lock",
"learning/tour-of-beam/frontend/lib/firebase_options.dart",

// Ignore .gitkeep file
"**/.gitkeep",
Expand Down
53 changes: 34 additions & 19 deletions learning/tour-of-beam/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,62 @@
under the License.
-->

# Tour of Beam
These are the main sources of the Tour of Beam website.
# Tour of Beam

# About
These are the main sources of the Tour of Beam website.

# About

## Getting started

Running, debugging, and testing all require this first step that fetches
dependencies and generates code:

```bash
cd ../../../playground/frontend/playground_components
flutter pub get
flutter pub run build_runner build
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work instead of these 3 lines?

./gradlew :playground:frontend:generateCode

Copy link
Contributor

Choose a reason for hiding this comment

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

Or rather

./gradlew :playground:frontend:playground_components:generateCode

Copy link
Contributor Author

@nausharipov nausharipov Jan 6, 2023

Choose a reason for hiding this comment

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

@alexeyinkin and I have updated README.

cd ../../../learning/tour-of-beam/frontend
flutter pub get
flutter pub run build_runner build
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert? Looks like it is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexeyinkin and I have updated README.

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the instructions, received the following error:

No .dart_tool/package_config.json file found, please run "flutter pub get".

Starting with Dart 2.7, the package_config.json file configures resolution of package import URIs; run "flutter pub get" to generate it.
pub finished with exit code 65

So ran, flutter pub get . FYI I saw a new file to be staged in git:

git status
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   pubspec.lock

Then followed the original instructions: flutter pub run build_runner build and received the error:

[SEVERE] Conflicting outputs were detected and the build is unable to prompt for permission to remove them. These outputs must be removed manually or the build can be run with `--delete-conflicting-outputs`. The outputs are: lib/models/unit_content.g.dart
lib/models/unit_progress.g.dart
lib/repositories/models/get_sdks_response.g.dart
lib/repositories/models/group.g.dart
lib/repositories/models/get_user_progress_response.g.dart
lib/repositories/models/node.g.dart
lib/repositories/models/module.g.dart
lib/repositories/models/unit.g.dart
lib/repositories/models/get_content_tree_response.g.dart
lib/auth/method.g.dart
pub finished with exit code 78

Steps to reproduce:

  1. git clone -b issue23692_auth https://github.com/akvelon/beam.git issue23692_auth
  2. Follow https://github.com/akvelon/beam/blob/dc4e142f25e1c7efa23b26a04158e1f208ea3864/learning/tour-of-beam/frontend/README.md?plain=1#L37-L39

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added flutter pub run build_runner build --delete-conflicting-outputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've committed a fresh pubspec.lock file.

Copy link
Contributor

Choose a reason for hiding this comment

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

@damondouglas this README is anyway temporary because Gradle tasks are also in the line for the review:

```

### Code Generation

This project relies on generated code for some functionality:
deserializers, constants for asset files, Firebase configuration, etc.

All generated files are version-controlled, so after checkout the project is immediately runnable.
However, after changes you may need to re-run code generation:
`flutter pub run build_runner build`

Manual for re-configuring Firebase:
https://firebase.google.com/docs/flutter/setup?platform=web

### Run

The following command is used to build and serve the frontend app locally:

`$ flutter run -d chrome`

# Deployment

# Tests

Install ChromeDriver to run integration tests in a browser: https://docs.flutter.dev/testing/integration-tests#running-in-a-browser
Run integration tests:
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/counter_test.dart \
-d web-server

# Deployment
# Packages

# Tests
Install ChromeDriver to run integration tests in a browser: https://docs.flutter.dev/testing/integration-tests#running-in-a-browser
Run integration tests:
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/counter_test.dart \
-d web-server
`flutter pub get`

# Packages
`flutter pub get`
# Contribution guide

# Contribution guide
For checks: `./gradlew rat`
For checks: `./gradlew rat`
Exclusions for file checks can be added in the Tour of Beam section of this file: `beam/build.gradle.kts`

# Additional resources
# Additional resources

# Troubleshooting
# Troubleshooting
27 changes: 27 additions & 0 deletions learning/tour-of-beam/frontend/lib/auth/method.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import 'package:enum_map/enum_map.dart';

part 'method.g.dart';

@unmodifiableEnumMap
enum AuthMethod {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we instead just rely on which https://pub.dev/documentation/firebase_auth_platform_interface/latest/firebase_auth_platform_interface/AuthProvider-class.html is referenced with a particular button action? If someone clicks the Google button, it initializes Auth flow via Google. If someone clicks the Github button, it initializes Auth flow via Github. The code only seems to use the AuthMethod.google.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the firebase_auth_platform_interface package and now logIn takes AuthProvider as an argument.

google,
github,
}
162 changes: 162 additions & 0 deletions learning/tour-of-beam/frontend/lib/auth/method.g.dart

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

50 changes: 50 additions & 0 deletions learning/tour-of-beam/frontend/lib/auth/notifier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import 'dart:async';

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'method.dart';

class AuthNotifier extends ChangeNotifier {
final _authProviders = UnmodifiableAuthMethodMap(
google: GoogleAuthProvider(),
github: GithubAuthProvider(),
);

AuthNotifier() {
FirebaseAuth.instance.authStateChanges().listen((user) {
notifyListeners();
});
}

bool get isAuthenticated => FirebaseAuth.instance.currentUser != null;

Future<String?> getToken() async {
return await FirebaseAuth.instance.currentUser?.getIdToken();
}

Future<void> logIn(AuthMethod authMethod) async {
await FirebaseAuth.instance.signInWithPopup(_authProviders.get(authMethod));
}

Future<void> logOut() async {
await FirebaseAuth.instance.signOut();
}
}
27 changes: 27 additions & 0 deletions learning/tour-of-beam/frontend/lib/cache/cache.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import 'package:flutter/material.dart';

import '../repositories/client/client.dart';

abstract class Cache extends ChangeNotifier {
final TobClient client;

Cache({required this.client});
}
14 changes: 5 additions & 9 deletions learning/tour-of-beam/frontend/lib/cache/content_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@

import 'dart:async';

import 'package:flutter/widgets.dart';

import '../models/content_tree.dart';
import '../repositories/client/client.dart';
import 'cache.dart';

class ContentTreeCache extends ChangeNotifier {
final TobClient client;
class ContentTreeCache extends Cache {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does a ContentTreeCache cache? Would code comments help explain this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a comment to the Cache class.

ContentTreeCache({
required super.client,
});

final _treesBySdkId = <String, ContentTreeModel>{};
final _futuresBySdkId = <String, Future<ContentTreeModel>>{};

ContentTreeCache({
required this.client,
});

ContentTreeModel? getContentTree(String sdkId) {
final future = _futuresBySdkId[sdkId];
Copy link
Contributor

Choose a reason for hiding this comment

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

What about containsKey?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (future == null) {
Expand Down
Loading