From 3c623abd631b493c8a71d05fe591065754c75d0c Mon Sep 17 00:00:00 2001 From: Alexander Zhuravlev Date: Mon, 6 Jun 2022 22:53:06 +0400 Subject: [PATCH] [Playground] [Hotfix] Remove autoscrolling from embedded editor (#21717) * [Playground] Removed autoscrolling from embedded editor * [Playground] Fixed GRPC getGraph errors in console, removed unnecessary requests from embedded iframe --- playground/frontend/lib/constants/params.dart | 1 + .../editor/components/editor_textarea.dart | 6 +++++- .../components/embedded_editor.dart | 1 + .../components/playground_page_providers.dart | 3 ++- .../playground/states/examples_state.dart | 20 ++++++++++++++++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/playground/frontend/lib/constants/params.dart b/playground/frontend/lib/constants/params.dart index 430782d66d07..9d14e44c3cd5 100644 --- a/playground/frontend/lib/constants/params.dart +++ b/playground/frontend/lib/constants/params.dart @@ -20,5 +20,6 @@ const kExampleParam = 'example'; const kIsEditable = 'enabled'; const kSourceCode = 'code'; const kContextLine = 'line'; +const kIsEmbedded = 'embedded'; const kQuickStartCategoryName = 'quick start'; diff --git a/playground/frontend/lib/modules/editor/components/editor_textarea.dart b/playground/frontend/lib/modules/editor/components/editor_textarea.dart index bf06302decd2..cb75c35de13d 100644 --- a/playground/frontend/lib/modules/editor/components/editor_textarea.dart +++ b/playground/frontend/lib/modules/editor/components/editor_textarea.dart @@ -46,6 +46,7 @@ class EditorTextArea extends StatefulWidget { final bool enabled; final void Function(String)? onSourceChange; final bool isEditable; + final bool isEmbedded; const EditorTextArea({ Key? key, @@ -54,6 +55,7 @@ class EditorTextArea extends StatefulWidget { this.onSourceChange, required this.enabled, required this.isEditable, + this.isEmbedded = false, }) : super(key: key); @override @@ -97,7 +99,9 @@ class _EditorTextAreaState extends State { @override Widget build(BuildContext context) { - WidgetsBinding.instance.addPostFrameCallback((_) => _setTextScrolling()); + if (!widget.isEmbedded) { + WidgetsBinding.instance.addPostFrameCallback((_) => _setTextScrolling()); + } return Semantics( container: true, diff --git a/playground/frontend/lib/pages/embedded_playground/components/embedded_editor.dart b/playground/frontend/lib/pages/embedded_playground/components/embedded_editor.dart index 1a190b895e33..094a12fe6187 100644 --- a/playground/frontend/lib/pages/embedded_playground/components/embedded_editor.dart +++ b/playground/frontend/lib/pages/embedded_playground/components/embedded_editor.dart @@ -36,6 +36,7 @@ class EmbeddedEditor extends StatelessWidget { example: state.selectedExample, onSourceChange: state.setSource, isEditable: isEditable, + isEmbedded: true, ); } } diff --git a/playground/frontend/lib/pages/playground/components/playground_page_providers.dart b/playground/frontend/lib/pages/playground/components/playground_page_providers.dart index 3fc209ffb3e5..e2455f4f0b15 100644 --- a/playground/frontend/lib/pages/playground/components/playground_page_providers.dart +++ b/playground/frontend/lib/pages/playground/components/playground_page_providers.dart @@ -57,7 +57,8 @@ class PlaygroundPageProviders extends StatelessWidget { return PlaygroundState(codeRepository: kCodeRepository); } - if (playground.selectedExample == null) { + if (playground.selectedExample == null && + !Uri.base.toString().contains(kIsEmbedded)) { final newPlayground = PlaygroundState( codeRepository: kCodeRepository, sdk: playground.sdk, diff --git a/playground/frontend/lib/pages/playground/states/examples_state.dart b/playground/frontend/lib/pages/playground/states/examples_state.dart index 9875adfdeeb8..3e7bdf952585 100644 --- a/playground/frontend/lib/pages/playground/states/examples_state.dart +++ b/playground/frontend/lib/pages/playground/states/examples_state.dart @@ -17,6 +17,7 @@ */ import 'package:flutter/material.dart'; +import 'package:playground/constants/params.dart'; import 'package:playground/modules/examples/models/category_model.dart'; import 'package:playground/modules/examples/models/example_model.dart'; import 'package:playground/modules/examples/repositories/example_repository.dart'; @@ -34,7 +35,9 @@ class ExampleState with ChangeNotifier { ExampleState(this._exampleRepository); init() { - _loadCategories(); + if (!Uri.base.toString().contains(kIsEmbedded)) { + _loadCategories(); + } } setSdkCategories(Map> map) { @@ -80,6 +83,21 @@ class ExampleState with ChangeNotifier { if (example.isInfoFetched()) { return example; } + + //GRPC GetPrecompiledGraph errors hotfix + if (example.name == 'MinimalWordCount' && + (sdk == SDK.go || sdk == SDK.scio)) { + final exampleData = await Future.wait([ + getExampleSource(example.path, sdk), + getExampleOutput(example.path, sdk), + getExampleLogs(example.path, sdk), + ]); + example.setSource(exampleData[0]); + example.setOutputs(exampleData[1]); + example.setLogs(exampleData[2]); + return example; + } + final exampleData = await Future.wait([ getExampleSource(example.path, sdk), getExampleOutput(example.path, sdk),