You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/11/08 13:38:04 UTC

[GitHub] [beam] Malarg commented on a diff in pull request #24031: Configure flutter_code_editor options with Hugo shortcode (#23926)

Malarg commented on code in PR #24031:
URL: https://github.com/apache/beam/pull/24031#discussion_r1016552272


##########
playground/frontend/lib/modules/examples/models/example_token_type.dart:
##########
@@ -19,11 +19,18 @@
 import 'package:playground_components/playground_components.dart';
 
 enum ExampleTokenType {

Review Comment:
   May be `ExampleTokenSourceType`?



##########
playground/frontend/playground_components/lib/src/controllers/example_loaders/http_example_loader.dart:
##########
@@ -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 'package:collection/collection.dart';
+import 'package:http/http.dart' as http;
+
+import '../../cache/example_cache.dart';
+import '../../models/example.dart';
+import '../../models/example_base.dart';
+import '../../models/example_loading_descriptors/http_example_loading_descriptor.dart';
+import 'example_loader.dart';
+
+class HttpExampleLoader extends ExampleLoader {

Review Comment:
   Would be nice if `ExampleLoader` and it's descendants were covered by the documentation



##########
playground/frontend/playground_components/lib/src/models/example_base.dart:
##########
@@ -48,32 +49,35 @@ extension ExampleTypeToString on ExampleType {
 /// and other large fields.
 /// These objects are fetched as lists from [ExampleRepository].
 class ExampleBase with Comparable<ExampleBase>, EquatableMixin {
-  final Sdk sdk;
-  final List<String> tags;
-  final ExampleType type;
-  final String name;
-  final String path;
-  final String description;
+  final Complexity? complexity;
   final int contextLine;
+  final String description;
   final bool isMultiFile;
   final String? link;
+  final String name;
+  final String path;
   final String pipelineOptions;
-  final Complexity complexity;
+  final Sdk sdk;
+  final List<String> tags;
+  final ExampleType type;
+  final ExampleViewOptions viewOptions;
 
   const ExampleBase({
-    required this.sdk,
     required this.name,
     required this.path,
-    required this.description,
-    required this.tags,
+    required this.sdk,
     required this.type,
+    this.complexity,
     this.contextLine = 1,
+    this.description = '',
     this.isMultiFile = false,
     this.link,
-    required this.pipelineOptions,
-    required this.complexity,
+    this.pipelineOptions = '',
+    this.tags = const [],
+    this.viewOptions = ExampleViewOptions.empty,
   });
 
+  // TODO(alexeyinkin): Use all fields, https://github.com/apache/beam/issues/23979

Review Comment:
   Is this a big feature that we can't do here?



##########
playground/frontend/playground_components/lib/src/controllers/example_loaders/empty_example_loader.dart:
##########
@@ -34,14 +34,11 @@ class EmptyExampleLoader extends ExampleLoader {
 

Review Comment:
   unused import



##########
playground/frontend/playground_components/lib/src/controllers/example_loaders/http_example_loader.dart:
##########
@@ -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 'package:collection/collection.dart';
+import 'package:http/http.dart' as http;
+
+import '../../cache/example_cache.dart';
+import '../../models/example.dart';
+import '../../models/example_base.dart';
+import '../../models/example_loading_descriptors/http_example_loading_descriptor.dart';
+import 'example_loader.dart';
+
+class HttpExampleLoader extends ExampleLoader {
+  final HttpExampleLoadingDescriptor descriptor;
+
+  const HttpExampleLoader({
+    required this.descriptor,
+    // TODO(alexeyinkin): Remove when this lands: https://github.com/dart-lang/language/issues/1813
+    required ExampleCache exampleCache,
+  });
+
+  @override
+  Future<Example> get future async {
+    final response = await http.get(descriptor.uri);

Review Comment:
   What if request fails?



##########
playground/frontend/playground_components/lib/src/widgets/editor_textarea.dart:
##########
@@ -149,15 +149,12 @@ class _EditorTextAreaState extends State<EditorTextArea> {
   }
 
   int _getIndexOfContextLine() {
-    int ctxLineNumber = widget.example!.contextLine;
-    String contextLine = widget.codeController.text.split('\n')[ctxLineNumber];
+    final contextLine = widget.example!.contextLine;

Review Comment:
   Are you sure, that there won't be a situation, when example is null. After code investigation i seen that it could be if we haven't selected example. Are this situation possible?



##########
playground/frontend/playground_components/lib/src/models/example_loading_descriptors/http_example_loading_descriptor.dart:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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 '../sdk.dart';
+import 'example_loading_descriptor.dart';
+
+class HttpExampleLoadingDescriptor extends ExampleLoadingDescriptor {

Review Comment:
   I think `ExampleLoadingDescriptor` also should be covered by docs



##########
playground/frontend/playground_components/lib/src/controllers/snippet_editing_controller.dart:
##########
@@ -29,22 +28,39 @@ class SnippetEditingController extends ChangeNotifier {
   final Sdk sdk;
   final CodeController codeController;
   Example? _selectedExample;
-  String _pipelineOptions;
+  String _pipelineOptions = '';
 
   SnippetEditingController({
     required this.sdk,
-    Example? selectedExample,
-    String pipelineOptions = '',
-  })  : codeController = CodeController(
+  }) : codeController = CodeController(
           language: sdk.highlightMode,
+          namedSectionParser: const BracketsStartEndNamedSectionParser(),
           webSpaceFix: false,
-        ),
-        _selectedExample = selectedExample,
-        _pipelineOptions = pipelineOptions;
+        );
 
   set selectedExample(Example? value) {
     _selectedExample = value;
     setSource(_selectedExample?.source ?? '');
+

Review Comment:
   We can check value on null here before configuring controller:
   ```
       final viewOptions = value?.viewOptions;
       if (viewOptions != null) {
         final readOnlySectionNames = viewOptions.readOnlySectionNames;       <- extracted just for not exceed 80 chars :)
         codeController.readOnlySectionNames = readOnlySectionNames.toSet();
   
         codeController.visibleSectionNames = viewOptions.showSectionNames.toSet();
   
         if (viewOptions.foldCommentAtLineZero) {
           codeController.foldCommentAtLineZero();
         }
   
         if (viewOptions.foldImports) {
           codeController.foldImports();
         }
   
         final unfolded = viewOptions.unfoldSectionNames;
         if (unfolded.isNotEmpty) {
           codeController.foldOutsideSections(unfolded);
         }
       }
   ```



##########
playground/frontend/lib/modules/examples/components/example_list/example_item_actions.dart:
##########
@@ -36,8 +36,8 @@ class ExampleItemActions extends StatelessWidget {
     return Row(
       children: [
         if (example.isMultiFile) multifilePopover,
-        if (example.complexity != Complexity.unspecified)
-          ComplexityWidget(complexity: example.complexity),
+        if (example.complexity != null)

Review Comment:
   Why did you changed this logic?



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org