You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by pa...@apache.org on 2022/10/10 22:10:09 UTC
[beam] branch master updated: [Playground] complexity indicator (#23477)
This is an automated email from the ASF dual-hosted git repository.
pabloem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new d28fde68aff [Playground] complexity indicator (#23477)
d28fde68aff is described below
commit d28fde68aff6bf4a577d179a1dfd79533b9cf1ae
Author: Dmitry Repin <mr...@gmail.com>
AuthorDate: Tue Oct 11 02:10:02 2022 +0400
[Playground] complexity indicator (#23477)
* pg_22339 add complexity widget
* pg_22339 clean code
* pg_22339 clean code
* fix formatting
---
.../example_list/example_item_actions.dart | 2 ++
.../lib/src/cache/example_cache.dart | 3 ++-
.../example_loaders/content_example_loader.dart | 17 ++++++-------
.../example_loaders/empty_example_loader.dart | 2 ++
.../controllers/snippet_editing_controller.dart | 2 ++
.../lib/src/enums/complexity.dart | 17 +++++++++++++
.../lib/src/models/example.dart | 2 ++
.../lib/src/models/example_base.dart | 3 +++
.../content_example_loading_descriptor.dart | 19 +++++++++++----
...esponse.dart => complexity_grpc_extension.dart} | 28 ++++++++++++----------
.../example_client/grpc_example_client.dart | 3 +++
.../repositories/models/get_snippet_response.dart | 3 +++
.../test/src/common/examples.dart | 6 +++++
.../controllers/playground_controller_test.dart | 14 +++++++++--
.../messages/models/set_content_message_test.dart | 6 +++++
15 files changed, 100 insertions(+), 27 deletions(-)
diff --git a/playground/frontend/lib/modules/examples/components/example_list/example_item_actions.dart b/playground/frontend/lib/modules/examples/components/example_list/example_item_actions.dart
index 584b4c15731..d02e27eec61 100644
--- a/playground/frontend/lib/modules/examples/components/example_list/example_item_actions.dart
+++ b/playground/frontend/lib/modules/examples/components/example_list/example_item_actions.dart
@@ -36,6 +36,8 @@ class ExampleItemActions extends StatelessWidget {
return Row(
children: [
if (example.isMultiFile) multifilePopover,
+ if (example.complexity != Complexity.unspecified)
+ ComplexityWidget(complexity: example.complexity),
descriptionPopover,
],
);
diff --git a/playground/frontend/playground_components/lib/src/cache/example_cache.dart b/playground/frontend/playground_components/lib/src/cache/example_cache.dart
index 04d1425ec80..5e600591fe9 100644
--- a/playground/frontend/playground_components/lib/src/cache/example_cache.dart
+++ b/playground/frontend/playground_components/lib/src/cache/example_cache.dart
@@ -29,9 +29,9 @@ import '../repositories/example_repository.dart';
import '../repositories/models/get_default_precompiled_object_request.dart';
import '../repositories/models/get_precompiled_object_request.dart';
import '../repositories/models/get_precompiled_objects_request.dart';
-import '../repositories/models/shared_file.dart';
import '../repositories/models/get_snippet_request.dart';
import '../repositories/models/save_snippet_request.dart';
+import '../repositories/models/shared_file.dart';
/// A runtime cache for examples fetched from a repository.
class ExampleCache extends ChangeNotifier {
@@ -117,6 +117,7 @@ class ExampleCache extends ChangeNotifier {
type: ExampleType.example,
source: result.files.first.code,
pipelineOptions: result.pipelineOptions,
+ complexity: result.complexity,
);
}
diff --git a/playground/frontend/playground_components/lib/src/controllers/example_loaders/content_example_loader.dart b/playground/frontend/playground_components/lib/src/controllers/example_loaders/content_example_loader.dart
index a196d7122a7..a66e9fa69ad 100644
--- a/playground/frontend/playground_components/lib/src/controllers/example_loaders/content_example_loader.dart
+++ b/playground/frontend/playground_components/lib/src/controllers/example_loaders/content_example_loader.dart
@@ -33,12 +33,13 @@ class ContentExampleLoader extends ExampleLoader {
@override
Future<Example> get future async => Example(
- sdk: descriptor.sdk,
- name: descriptor.name ?? 'Embedded_Example',
- path: '',
- description: '',
- type: ExampleType.example,
- source: descriptor.content,
- pipelineOptions: '',
- );
+ sdk: descriptor.sdk,
+ name: descriptor.name ?? 'Embedded_Example',
+ path: '',
+ description: '',
+ type: ExampleType.example,
+ source: descriptor.content,
+ pipelineOptions: '',
+ complexity: descriptor.complexity,
+ );
}
diff --git a/playground/frontend/playground_components/lib/src/controllers/example_loaders/empty_example_loader.dart b/playground/frontend/playground_components/lib/src/controllers/example_loaders/empty_example_loader.dart
index 8f3b3d07e4c..0303444c76a 100644
--- a/playground/frontend/playground_components/lib/src/controllers/example_loaders/empty_example_loader.dart
+++ b/playground/frontend/playground_components/lib/src/controllers/example_loaders/empty_example_loader.dart
@@ -17,6 +17,7 @@
*/
import '../../cache/example_cache.dart';
+import '../../enums/complexity.dart';
import '../../models/example.dart';
import '../../models/example_base.dart';
import '../../models/example_loading_descriptors/empty_example_loading_descriptor.dart';
@@ -40,5 +41,6 @@ class EmptyExampleLoader extends ExampleLoader {
type: ExampleType.example,
source: '',
pipelineOptions: '',
+ complexity: Complexity.unspecified,
);
}
diff --git a/playground/frontend/playground_components/lib/src/controllers/snippet_editing_controller.dart b/playground/frontend/playground_components/lib/src/controllers/snippet_editing_controller.dart
index e687a16d451..9e36eed809b 100644
--- a/playground/frontend/playground_components/lib/src/controllers/snippet_editing_controller.dart
+++ b/playground/frontend/playground_components/lib/src/controllers/snippet_editing_controller.dart
@@ -19,6 +19,7 @@
import 'package:code_text_field/code_text_field.dart';
import 'package:flutter/widgets.dart';
+import '../enums/complexity.dart';
import '../models/example.dart';
import '../models/example_loading_descriptors/content_example_loading_descriptor.dart';
import '../models/example_loading_descriptors/example_loading_descriptor.dart';
@@ -83,6 +84,7 @@ class SnippetEditingController extends ChangeNotifier {
return ContentExampleLoadingDescriptor(
content: codeController.text,
name: _selectedExample?.name,
+ complexity: _selectedExample?.complexity ?? Complexity.unspecified,
sdk: sdk,
);
}
diff --git a/playground/frontend/playground_components/lib/src/enums/complexity.dart b/playground/frontend/playground_components/lib/src/enums/complexity.dart
index f43ffae19fe..e8e675b34ff 100644
--- a/playground/frontend/playground_components/lib/src/enums/complexity.dart
+++ b/playground/frontend/playground_components/lib/src/enums/complexity.dart
@@ -19,10 +19,27 @@
import 'package:json_annotation/json_annotation.dart';
enum Complexity {
+ @JsonValue('UNSPECIFIED')
+ unspecified,
@JsonValue('BASIC')
basic,
@JsonValue('MEDIUM')
medium,
@JsonValue('ADVANCED')
advanced,
+ ;
+
+ static Complexity fromString(String complexity) {
+ switch (complexity) {
+ case 'basic':
+ return Complexity.basic;
+ case 'medium':
+ return Complexity.medium;
+ case 'advanced':
+ return Complexity.advanced;
+ case 'unspecified':
+ return Complexity.unspecified;
+ }
+ throw Exception('Unknown complexity: $complexity');
+ }
}
diff --git a/playground/frontend/playground_components/lib/src/models/example.dart b/playground/frontend/playground_components/lib/src/models/example.dart
index a598b6b6446..2c072d100b2 100644
--- a/playground/frontend/playground_components/lib/src/models/example.dart
+++ b/playground/frontend/playground_components/lib/src/models/example.dart
@@ -39,6 +39,7 @@ class Example extends ExampleBase {
this.outputs,
this.logs,
this.graph,
+ required super.complexity,
});
Example.fromBase(
@@ -57,5 +58,6 @@ class Example extends ExampleBase {
isMultiFile: example.isMultiFile,
link: example.link,
pipelineOptions: example.pipelineOptions,
+ complexity: example.complexity,
);
}
diff --git a/playground/frontend/playground_components/lib/src/models/example_base.dart b/playground/frontend/playground_components/lib/src/models/example_base.dart
index 2c493edf79f..10a55e1be0b 100644
--- a/playground/frontend/playground_components/lib/src/models/example_base.dart
+++ b/playground/frontend/playground_components/lib/src/models/example_base.dart
@@ -18,6 +18,7 @@
import 'package:equatable/equatable.dart';
+import '../enums/complexity.dart';
import '../repositories/example_repository.dart';
import 'sdk.dart';
@@ -56,6 +57,7 @@ class ExampleBase with Comparable<ExampleBase>, EquatableMixin {
final bool isMultiFile;
final String? link;
final String pipelineOptions;
+ final Complexity complexity;
const ExampleBase({
required this.sdk,
@@ -67,6 +69,7 @@ class ExampleBase with Comparable<ExampleBase>, EquatableMixin {
this.isMultiFile = false,
this.link,
required this.pipelineOptions,
+ required this.complexity,
});
@override
diff --git a/playground/frontend/playground_components/lib/src/models/example_loading_descriptors/content_example_loading_descriptor.dart b/playground/frontend/playground_components/lib/src/models/example_loading_descriptors/content_example_loading_descriptor.dart
index 13be92a506d..dbc9a7e8567 100644
--- a/playground/frontend/playground_components/lib/src/models/example_loading_descriptors/content_example_loading_descriptor.dart
+++ b/playground/frontend/playground_components/lib/src/models/example_loading_descriptors/content_example_loading_descriptor.dart
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import '../../enums/complexity.dart';
import '../sdk.dart';
import 'example_loading_descriptor.dart';
@@ -26,12 +27,15 @@ class ContentExampleLoadingDescriptor extends ExampleLoadingDescriptor {
/// The name of the example, if any, to show in the dropdown.
final String? name;
+ final Complexity complexity;
+
final Sdk sdk;
const ContentExampleLoadingDescriptor({
required this.content,
required this.name,
required this.sdk,
+ required this.complexity,
});
static ContentExampleLoadingDescriptor? tryParse(Map eventData) {
@@ -49,6 +53,7 @@ class ContentExampleLoadingDescriptor extends ExampleLoadingDescriptor {
content: content,
name: _tryParseName(eventData),
sdk: sdk,
+ complexity: _parseComplexity(eventData),
);
}
@@ -64,13 +69,19 @@ class ContentExampleLoadingDescriptor extends ExampleLoadingDescriptor {
return Sdk.tryParse(map['sdk']);
}
+ static Complexity _parseComplexity(Map map) {
+ final complexityString = map['complexity'];
+ return Complexity.fromString(complexityString);
+ }
+
@override
List<Object> get props => [content, sdk.id];
@override
Map<String, dynamic> toJson() => {
- 'content': content,
- 'name': name,
- 'sdk': sdk.id,
- };
+ 'content': content,
+ 'name': name,
+ 'sdk': sdk.id,
+ 'complexity': complexity.name,
+ };
}
diff --git a/playground/frontend/playground_components/lib/src/repositories/models/get_snippet_response.dart b/playground/frontend/playground_components/lib/src/repositories/complexity_grpc_extension.dart
similarity index 59%
copy from playground/frontend/playground_components/lib/src/repositories/models/get_snippet_response.dart
copy to playground/frontend/playground_components/lib/src/repositories/complexity_grpc_extension.dart
index 9cb9c8ec128..c9edb542983 100644
--- a/playground/frontend/playground_components/lib/src/repositories/models/get_snippet_response.dart
+++ b/playground/frontend/playground_components/lib/src/repositories/complexity_grpc_extension.dart
@@ -16,17 +16,21 @@
* limitations under the License.
*/
-import '../../models/sdk.dart';
-import 'shared_file.dart';
+import '../api/v1/api.pbgrpc.dart' as g;
+import '../enums/complexity.dart';
-class GetSnippetResponse {
- final List<SharedFile> files;
- final Sdk sdk;
- final String pipelineOptions;
-
- const GetSnippetResponse({
- required this.files,
- required this.sdk,
- required this.pipelineOptions,
- });
+extension GrpcComplecity on g.Complexity {
+ Complexity get model {
+ switch (this) {
+ case g.Complexity.COMPLEXITY_BASIC:
+ return Complexity.basic;
+ case g.Complexity.COMPLEXITY_MEDIUM:
+ return Complexity.medium;
+ case g.Complexity.COMPLEXITY_ADVANCED:
+ return Complexity.advanced;
+ case g.Complexity.COMPLEXITY_UNSPECIFIED:
+ return Complexity.unspecified;
+ }
+ throw Exception('Unknown complexity: $this');
+ }
}
diff --git a/playground/frontend/playground_components/lib/src/repositories/example_client/grpc_example_client.dart b/playground/frontend/playground_components/lib/src/repositories/example_client/grpc_example_client.dart
index ceaa08a9bdf..6292fcb77c5 100644
--- a/playground/frontend/playground_components/lib/src/repositories/example_client/grpc_example_client.dart
+++ b/playground/frontend/playground_components/lib/src/repositories/example_client/grpc_example_client.dart
@@ -24,6 +24,7 @@ import '../../models/category_with_examples.dart';
import '../../models/example_base.dart';
import '../../models/sdk.dart';
import '../../util/replace_incorrect_symbols.dart';
+import '../complexity_grpc_extension.dart';
import '../models/get_default_precompiled_object_request.dart';
import '../models/get_precompiled_object_code_response.dart';
import '../models/get_precompiled_object_request.dart';
@@ -203,6 +204,7 @@ class GrpcExampleClient implements ExampleClient {
files: _convertToSharedFileList(response.files),
sdk: response.sdk.model,
pipelineOptions: response.pipelineOptions,
+ complexity: response.complexity.model,
);
}
@@ -338,6 +340,7 @@ class GrpcExampleClient implements ExampleClient {
pipelineOptions: example.pipelineOptions,
isMultiFile: example.multifile,
link: example.link,
+ complexity: example.complexity.model,
);
}
diff --git a/playground/frontend/playground_components/lib/src/repositories/models/get_snippet_response.dart b/playground/frontend/playground_components/lib/src/repositories/models/get_snippet_response.dart
index 9cb9c8ec128..460b215c4f4 100644
--- a/playground/frontend/playground_components/lib/src/repositories/models/get_snippet_response.dart
+++ b/playground/frontend/playground_components/lib/src/repositories/models/get_snippet_response.dart
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import '../../enums/complexity.dart';
import '../../models/sdk.dart';
import 'shared_file.dart';
@@ -23,10 +24,12 @@ class GetSnippetResponse {
final List<SharedFile> files;
final Sdk sdk;
final String pipelineOptions;
+ final Complexity complexity;
const GetSnippetResponse({
required this.files,
required this.sdk,
required this.pipelineOptions,
+ required this.complexity,
});
}
diff --git a/playground/frontend/playground_components/test/src/common/examples.dart b/playground/frontend/playground_components/test/src/common/examples.dart
index a522668827d..e8590e87b36 100644
--- a/playground/frontend/playground_components/test/src/common/examples.dart
+++ b/playground/frontend/playground_components/test/src/common/examples.dart
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import 'package:playground_components/src/enums/complexity.dart';
import 'package:playground_components/src/models/example.dart';
import 'package:playground_components/src/models/example_base.dart';
import 'package:playground_components/src/models/sdk.dart';
@@ -28,6 +29,7 @@ const exampleMock1 = Example(
description: 'description',
path: 'SDK_PYTHON/Category/Name',
pipelineOptions: '',
+ complexity: Complexity.basic,
);
const exampleMock2 = Example(
@@ -38,6 +40,7 @@ const exampleMock2 = Example(
description: 'description',
path: 'SDK_PYTHON/Category/Name',
pipelineOptions: '',
+ complexity: Complexity.basic,
);
const exampleWithoutSourceMock = ExampleBase(
@@ -47,6 +50,7 @@ const exampleWithoutSourceMock = ExampleBase(
description: 'description',
path: 'SDK_PYTHON/Category/Name',
pipelineOptions: '',
+ complexity: Complexity.basic,
);
const exampleWithAllAdditionsMock = Example(
@@ -60,6 +64,7 @@ const exampleWithAllAdditionsMock = Example(
logs: 'test outputs',
graph: 'test outputs',
pipelineOptions: '',
+ complexity: Complexity.basic,
);
const exampleMockGo = Example(
@@ -70,4 +75,5 @@ const exampleMockGo = Example(
description: 'description',
path: 'SDK_GO/Category/Name',
pipelineOptions: '',
+ complexity: Complexity.medium,
);
diff --git a/playground/frontend/playground_components/test/src/controllers/playground_controller_test.dart b/playground/frontend/playground_components/test/src/controllers/playground_controller_test.dart
index 506102cce5c..567a5535178 100644
--- a/playground/frontend/playground_components/test/src/controllers/playground_controller_test.dart
+++ b/playground/frontend/playground_components/test/src/controllers/playground_controller_test.dart
@@ -159,8 +159,18 @@ void main() {
descriptor.toJson(),
{
'descriptors': [
- {'sdk': 'python', 'content': 'ex2', 'name': 'Kata'},
- {'sdk': 'go', 'content': 'ex1', 'name': 'Example'},
+ {
+ 'sdk': 'python',
+ 'content': 'ex2',
+ 'name': 'Kata',
+ 'complexity': 'basic'
+ },
+ {
+ 'sdk': 'go',
+ 'content': 'ex1',
+ 'name': 'Example',
+ 'complexity': 'medium'
+ },
],
},
);
diff --git a/playground/frontend/test/modules/messages/models/set_content_message_test.dart b/playground/frontend/test/modules/messages/models/set_content_message_test.dart
index a552501b84a..aeb26809f38 100644
--- a/playground/frontend/test/modules/messages/models/set_content_message_test.dart
+++ b/playground/frontend/test/modules/messages/models/set_content_message_test.dart
@@ -92,15 +92,18 @@ void main() {
'content': _content,
'name': 'name',
'sdk': _sdk.id,
+ 'complexity': 'basic',
},
{
'content': _content,
'name': null,
'sdk': _sdk.id,
+ 'complexity': 'medium',
},
{
'content': _content,
'sdk': _sdk.id,
+ 'complexity': 'advanced',
},
],
},
@@ -117,16 +120,19 @@ void main() {
content: _content,
name: 'name',
sdk: _sdk,
+ complexity: Complexity.basic,
),
ContentExampleLoadingDescriptor(
content: _content,
name: null,
sdk: _sdk,
+ complexity: Complexity.medium,
),
ContentExampleLoadingDescriptor(
content: _content,
name: null,
sdk: _sdk,
+ complexity: Complexity.advanced,
),
],
),