alexeyinkin commented on code in PR #24283:
URL: https://github.com/apache/beam/pull/24283#discussion_r1033189284
##########
playground/frontend/lib/pages/embedded_playground/components/embedded_actions.dart:
##########
@@ -58,16 +59,26 @@ class EmbeddedActions extends StatelessWidget {
void _openStandalonePlayground(PlaygroundController controller) {
// The empty list forces the parsing of EmptyExampleLoadingDescriptor
// and prevents the glimpse of the default catalog example.
+
+ final loadingDescriptor = controller.getLoadingDescriptor();
+ final contentDescriptor =
+ loadingDescriptor.whereType<ContentExampleLoadingDescriptor>();
+ final standardDescriptor =
+ loadingDescriptor.whereType<StandardExampleLoadingDescriptor>();
Review Comment:
1. descriptor*s*
2. This does not cover 4 other descriptor types, not to mention possibly
future types.
##########
playground/frontend/playground_components/lib/src/controllers/snippet_editing_controller.dart:
##########
@@ -99,9 +101,12 @@ class SnippetEditingController extends ChangeNotifier {
/// Creates an [ExampleLoadingDescriptor] that can recover the
/// current content.
ExampleLoadingDescriptor getLoadingDescriptor() {
- // TODO: Return other classes for unchanged standard examples,
- // user-shared examples, and an empty editor,
- // https://github.com/apache/beam/issues/23252
+ if (codeController.fullText.isEmpty) {
+ return EmptyExampleLoadingDescriptor(sdk: sdk);
+ }
+ if (selectedExample != null && !isChanged) {
+ return StandardExampleLoadingDescriptor(path: _selectedExample!.path);
Review Comment:
This could be other example sources. The best way to handle this is to store
the original descriptor in this controller.
##########
playground/frontend/playground_components/test/src/controllers/snippet_editing_controllers_test.dart:
##########
@@ -0,0 +1,55 @@
+import 'package:flutter_test/flutter_test.dart';
+import
'package:playground_components/src/controllers/snippet_editing_controller.dart';
+import 'package:playground_components/src/models/sdk.dart';
+
+import '../common/examples.dart';
+
Review Comment:
`snippet_editing_controller_test.dart` without 's'.
##########
playground/frontend/playground_components/test/src/controllers/snippet_editing_controllers_test.dart:
##########
@@ -0,0 +1,55 @@
+import 'package:flutter_test/flutter_test.dart';
+import
'package:playground_components/src/controllers/snippet_editing_controller.dart';
+import 'package:playground_components/src/models/sdk.dart';
+
+import '../common/examples.dart';
+
+void main() {
+ group(
+ 'Snippet editing controllers',
+ () {
+ test(
+ 'Returns standard descriptor if code has not been changed',
+ () {
+ final controller = SnippetEditingController(sdk: Sdk.python);
+ controller.selectedExample = exampleMock1;
+
+ final descriptor = controller.getLoadingDescriptor();
+
+ expect(descriptor.toJson(), {'example':
'SDK_PYTHON/Category/Name1'});
+ },
+ );
+
+ test(
+ 'Returns content descriptor if code has been changed',
+ () {
+ final controller = SnippetEditingController(sdk: Sdk.python);
+ controller.selectedExample = exampleMock1;
+
+ controller.codeController.value = const TextEditingValue(text:
'ex4');
+ final descriptor = controller.getLoadingDescriptor();
+
+ expect(descriptor.toJson(), {
+ 'sdk': 'python',
+ 'content': 'ex4',
+ 'name': 'Example X1',
+ 'complexity': 'basic'
Review Comment:
`,`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]