From 4bd3c1a3a251296d8eaaf942c80763be2596cd34 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Fri, 16 Dec 2022 12:14:28 +0600 Subject: [PATCH 01/17] timer fix rough draft (#24617) --- .../shortcuts/constants/global_shortcuts.dart | 2 +- .../playground/components/close_listener.dart | 4 +- .../components/editor_textarea_wrapper.dart | 9 +- .../lib/src/controllers/code_runner.dart | 184 +++++++++++++++++ .../controllers/playground_controller.dart | 186 ++---------------- .../lib/src/widgets/output/output_area.dart | 4 +- .../lib/src/widgets/output/output_tabs.dart | 4 +- .../widgets/output/result_filter_bubble.dart | 7 +- .../lib/src/widgets/periodic_rebuilder.dart | 44 +++++ .../lib/src/widgets/reset_button.dart | 2 +- .../lib/src/widgets/run_button.dart | 116 +++++++---- .../lib/src/widgets/run_or_cancel_button.dart | 20 +- .../playground_controller_test.dart | 14 +- 13 files changed, 359 insertions(+), 237 deletions(-) create mode 100644 playground/frontend/playground_components/lib/src/controllers/code_runner.dart create mode 100644 playground/frontend/playground_components/lib/src/widgets/periodic_rebuilder.dart diff --git a/playground/frontend/lib/modules/shortcuts/constants/global_shortcuts.dart b/playground/frontend/lib/modules/shortcuts/constants/global_shortcuts.dart index 03797eaff3a0..ab9b195cdd5b 100644 --- a/playground/frontend/lib/modules/shortcuts/constants/global_shortcuts.dart +++ b/playground/frontend/lib/modules/shortcuts/constants/global_shortcuts.dart @@ -40,7 +40,7 @@ final kClearOutputShortcut = BeamShortcut( onInvoke: (_) => Provider.of( context, listen: false, - ).clearOutput(), + ).codeRunner.clearOutput(), ), ); diff --git a/playground/frontend/lib/pages/playground/components/close_listener.dart b/playground/frontend/lib/pages/playground/components/close_listener.dart index ba2a19a7ae22..0a370f1334c1 100644 --- a/playground/frontend/lib/pages/playground/components/close_listener.dart +++ b/playground/frontend/lib/pages/playground/components/close_listener.dart @@ -36,7 +36,9 @@ class _CloseListenerState extends State { void initState() { WidgetsBinding.instance.addPostFrameCallback((timeStamp) { html.window.onBeforeUnload.listen((event) async { - Provider.of(context, listen: false).cancelRun(); + Provider.of(context, listen: false) + .codeRunner + .cancelRun(); }); }); super.initState(); diff --git a/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart b/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart index 5d427f41d98f..3c684ec17fff 100644 --- a/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart +++ b/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart @@ -31,8 +31,9 @@ class CodeTextAreaWrapper extends StatelessWidget { @override Widget build(BuildContext context) { - return Consumer(builder: (context, controller, child) { - if (controller.result?.errorMessage?.isNotEmpty ?? false) { + return Consumer( + builder: (context, controller, child) { + if (controller.codeRunner.result?.errorMessage?.isNotEmpty ?? false) { WidgetsBinding.instance.addPostFrameCallback((_) { _handleError(context, controller); }); @@ -105,8 +106,8 @@ class CodeTextAreaWrapper extends StatelessWidget { NotificationManager.showError( context, AppLocalizations.of(context)!.runCode, - controller.result?.errorMessage ?? '', + controller.codeRunner.result?.errorMessage ?? '', ); - controller.resetError(); + controller.codeRunner.resetError(); } } diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart new file mode 100644 index 000000000000..3d5340007e7f --- /dev/null +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -0,0 +1,184 @@ +/* + * 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:flutter/material.dart'; + +import '../../playground_components.dart'; +import '../repositories/models/run_code_request.dart'; +import '../repositories/models/run_code_result.dart'; +import 'snippet_editing_controller.dart'; + +class CodeRunner extends ChangeNotifier { + final CodeRepository? _codeRepository; + final ValueGetter _snippetEditingController; + + CodeRunner({ + required ValueGetter snippetEditingController, + CodeRepository? codeRepository, + }) : _codeRepository = codeRepository, + _snippetEditingController = snippetEditingController; + + RunCodeResult? _result; + StreamSubscription? _runSubscription; + String outputResult = ''; + OutputType selectedOutputFilterType = OutputType.all; + DateTime? _runStartDate; + + String get pipelineOptions => _snippetEditingController().pipelineOptions; + RunCodeResult? get result => _result; + DateTime? get runStartDate => _runStartDate; + bool get isCodeRunning => !(_result?.isFinished ?? true); + + void clearResult() { + _result = null; + notifyListeners(); + } + + void runCode({void Function()? onFinish}) { + _runStartDate = DateTime.now(); + notifyListeners(); + + final parsedPipelineOptions = + parsePipelineOptions(_snippetEditingController().pipelineOptions); + if (parsedPipelineOptions == null) { + _result = const RunCodeResult( + status: RunCodeStatus.compileError, + errorMessage: kPipelineOptionsParseError, + ); + notifyListeners(); + return; + } + + if (!_snippetEditingController().isChanged && + _snippetEditingController().selectedExample?.outputs != null) { + unawaited(_showPrecompiledResult()); + } else { + final request = RunCodeRequest( + code: _snippetEditingController().codeController.fullText, + sdk: _snippetEditingController().sdk, + pipelineOptions: parsedPipelineOptions, + ); + _runSubscription = _codeRepository?.runCode(request).listen((event) { + _result = event; + filterOutput(selectedOutputFilterType); + + if (event.isFinished && onFinish != null) { + onFinish(); + } + }); + notifyListeners(); + } + } + + void filterOutput(OutputType type) { + final output = _result?.output ?? ''; + final log = _result?.log ?? ''; + + switch (type) { + case OutputType.all: + setOutputResult(log + output); + break; + case OutputType.log: + setOutputResult(log); + break; + case OutputType.output: + setOutputResult(output); + break; + case OutputType.graph: + setOutputResult(log + output); + break; + } + } + + void setOutputResult(String outputs) { + outputResult = outputs; + notifyListeners(); + } + + void clearOutput() { + _result = null; + notifyListeners(); + } + + void setSelectedOutputFilterType(OutputType type) { + selectedOutputFilterType = type; + notifyListeners(); + } + + void reset() { + _snippetEditingController().reset(); + outputResult = ''; + notifyListeners(); + } + + void resetError() { + if (result == null) { + return; + } + _result = RunCodeResult( + status: result!.status, + output: result!.output, + ); + notifyListeners(); + } + + Future cancelRun() async { + await _runSubscription?.cancel(); + final pipelineUuid = result?.pipelineUuid ?? ''; + + if (pipelineUuid.isNotEmpty) { + await _codeRepository?.cancelExecution(pipelineUuid); + } + + _result = RunCodeResult( + status: RunCodeStatus.finished, + output: _result?.output, + log: (_result?.log ?? '') + kExecutionCancelledText, + graph: _result?.graph, + ); + + final log = _result?.log ?? ''; + final output = _result?.output ?? ''; + setOutputResult(log + output); + notifyListeners(); + } + + Future _showPrecompiledResult() async { + _result = const RunCodeResult( + status: RunCodeStatus.preparation, + ); + final selectedExample = _snippetEditingController().selectedExample!; + + notifyListeners(); + // add a little delay to improve user experience + await Future.delayed(kPrecompiledDelay); + + final String logs = selectedExample.logs ?? ''; + _result = RunCodeResult( + status: RunCodeStatus.finished, + output: selectedExample.outputs, + log: kCachedResultsLog + logs, + graph: selectedExample.graph, + ); + + filterOutput(selectedOutputFilterType); + notifyListeners(); + } +} diff --git a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart index adf5e48cf2ae..2c541b7ac704 100644 --- a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart +++ b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart @@ -23,22 +23,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get_it/get_it.dart'; -import '../cache/example_cache.dart'; -import '../models/example.dart'; -import '../models/example_base.dart'; -import '../models/example_loading_descriptors/examples_loading_descriptor.dart'; -import '../models/intents.dart'; -import '../models/outputs.dart'; -import '../models/sdk.dart'; -import '../models/shortcut.dart'; -import '../repositories/code_repository.dart'; -import '../repositories/models/run_code_request.dart'; -import '../repositories/models/run_code_result.dart'; +import '../../playground_components.dart'; import '../repositories/models/shared_file.dart'; import '../services/symbols/loaders/map.dart'; import '../services/symbols/symbols_notifier.dart'; -import '../util/pipeline_options.dart'; -import 'example_loaders/examples_loader.dart'; +import 'code_runner.dart'; import 'snippet_editing_controller.dart'; const kTitleLength = 15; @@ -55,18 +44,14 @@ class PlaygroundController with ChangeNotifier { final ExampleCache exampleCache; final ExamplesLoader examplesLoader; + late final CodeRunner codeRunner; + final CodeRepository? _codeRepository; + final _snippetEditingControllers = {}; Sdk? _sdk; - final CodeRepository? _codeRepository; - - RunCodeResult? _result; - StreamSubscription? _runSubscription; - StreamController? _executionTime; // TODO(alexeyinkin): Extract along with run status, https://github.com/apache/beam/issues/23248 - OutputType selectedOutputFilterType = OutputType.all; - String outputResult = ''; PlaygroundController({ required this.exampleCache, @@ -74,6 +59,11 @@ class PlaygroundController with ChangeNotifier { CodeRepository? codeRepository, }) : _codeRepository = codeRepository { examplesLoader.setPlaygroundController(this); + + codeRunner = CodeRunner( + codeRepository: _codeRepository, + snippetEditingController: () => snippetEditingController!, + )..addListener(notifyListeners); } SnippetEditingController _getOrCreateSnippetEditingController( @@ -120,14 +110,6 @@ class PlaygroundController with ChangeNotifier { String? get source => snippetEditingController?.codeController.fullText; - bool get isCodeRunning => !(result?.isFinished ?? true); - - RunCodeResult? get result => _result; - - String? get pipelineOptions => snippetEditingController?.pipelineOptions; - - Stream? get executionTime => _executionTime?.stream; - bool get isExampleChanged { return snippetEditingController?.isChanged ?? false; } @@ -158,9 +140,8 @@ class PlaygroundController with ChangeNotifier { controller.selectedExample = example; } - _result = null; - _executionTime = null; - setOutputResult(''); + codeRunner.clearResult(); + codeRunner.setOutputResult(''); notifyListeners(); } @@ -197,125 +178,12 @@ class PlaygroundController with ChangeNotifier { controller.setSource(source); } - void setSelectedOutputFilterType(OutputType type) { - selectedOutputFilterType = type; - notifyListeners(); - } - - void setOutputResult(String outputs) { - outputResult = outputs; - notifyListeners(); - } - - void clearOutput() { - _result = null; - notifyListeners(); - } - - void reset() { - snippetEditingController?.reset(); - _executionTime = null; - outputResult = ''; - notifyListeners(); - } - - void resetError() { - if (result == null) { - return; - } - _result = RunCodeResult(status: result!.status, output: result!.output); - notifyListeners(); - } - void setPipelineOptions(String options) { final controller = requireSnippetEditingController(); controller.pipelineOptions = options; notifyListeners(); } - void runCode({void Function()? onFinish}) { - final controller = requireSnippetEditingController(); - final parsedPipelineOptions = - parsePipelineOptions(controller.pipelineOptions); - if (parsedPipelineOptions == null) { - _result = const RunCodeResult( - status: RunCodeStatus.compileError, - errorMessage: kPipelineOptionsParseError, - ); - notifyListeners(); - return; - } - _executionTime?.close(); - _executionTime = _createExecutionTimeStream(); - if (!isExampleChanged && controller.selectedExample?.outputs != null) { - _showPrecompiledResult(controller); - } else { - final request = RunCodeRequest( - code: controller.codeController.fullText, - sdk: controller.sdk, - pipelineOptions: parsedPipelineOptions, - ); - _runSubscription = _codeRepository?.runCode(request).listen((event) { - _result = event; - filterOutput(selectedOutputFilterType); - - if (event.isFinished && onFinish != null) { - onFinish(); - _executionTime?.close(); - } - notifyListeners(); - }); - notifyListeners(); - } - } - - Future cancelRun() async { - await _runSubscription?.cancel(); - final pipelineUuid = result?.pipelineUuid ?? ''; - - if (pipelineUuid.isNotEmpty) { - await _codeRepository?.cancelExecution(pipelineUuid); - } - - _result = RunCodeResult( - status: RunCodeStatus.finished, - output: _result?.output, - log: (_result?.log ?? '') + kExecutionCancelledText, - graph: _result?.graph, - ); - - final log = _result?.log ?? ''; - final output = _result?.output ?? ''; - setOutputResult(log + output); - await _executionTime?.close(); - notifyListeners(); - } - - Future _showPrecompiledResult( - SnippetEditingController snippetEditingController, - ) async { - _result = const RunCodeResult( - status: RunCodeStatus.preparation, - ); - final selectedExample = snippetEditingController.selectedExample!; - - notifyListeners(); - // add a little delay to improve user experience - await Future.delayed(kPrecompiledDelay); - - String logs = selectedExample.logs ?? ''; - _result = RunCodeResult( - status: RunCodeStatus.finished, - output: selectedExample.outputs, - log: kCachedResultsLog + logs, - graph: selectedExample.graph, - ); - - filterOutput(selectedOutputFilterType); - await _executionTime?.close(); - notifyListeners(); - } - StreamController _createExecutionTimeStream() { StreamController? streamController; Timer? timer; @@ -344,26 +212,6 @@ class PlaygroundController with ChangeNotifier { return streamController; } - void filterOutput(OutputType type) { - var output = result?.output ?? ''; - var log = result?.log ?? ''; - - switch (type) { - case OutputType.all: - setOutputResult(log + output); - break; - case OutputType.log: - setOutputResult(log); - break; - case OutputType.output: - setOutputResult(output); - break; - default: - setOutputResult(log + output); - break; - } - } - Future getSnippetId() { final controller = requireSnippetEditingController(); @@ -395,7 +243,7 @@ class PlaygroundController with ChangeNotifier { ), actionIntent: const RunIntent(), createAction: (BuildContext context) => CallbackAction( - onInvoke: (_) => runCode(), + onInvoke: (_) => codeRunner.runCode(), ), ); @@ -407,7 +255,7 @@ class PlaygroundController with ChangeNotifier { ), actionIntent: const ResetIntent(), createAction: (BuildContext context) => CallbackAction( - onInvoke: (_) => reset(), + onInvoke: (_) => codeRunner.reset(), ), ); @@ -415,4 +263,10 @@ class PlaygroundController with ChangeNotifier { runShortcut, resetShortcut, ]; + + @override + void dispose() { + super.dispose(); + codeRunner.removeListener(notifyListeners); + } } diff --git a/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart b/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart index f1bf48b2c260..0f453a3b4672 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart @@ -45,14 +45,14 @@ class OutputArea extends StatelessWidget { physics: const NeverScrollableScrollPhysics(), children: [ OutputResult( - text: playgroundController.outputResult, + text: playgroundController.codeRunner.outputResult, isSelected: tabController.index == 0, ), if (playgroundController.graphAvailable) sdk == null ? Container() : GraphTab( - graph: playgroundController.result?.graph ?? '', + graph: playgroundController.codeRunner.result?.graph ?? '', sdk: sdk, direction: graphDirection, ), diff --git a/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart b/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart index 80839296fbfa..27c01483e90b 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart @@ -43,7 +43,7 @@ class OutputTabs extends StatelessWidget { playgroundController: playgroundController, name: 'widgets.output.result'.tr(), isSelected: tabController.index == 0, - value: playgroundController.outputResult, + value: playgroundController.codeRunner.outputResult, hasFilter: true, ), if (playgroundController.graphAvailable) @@ -51,7 +51,7 @@ class OutputTabs extends StatelessWidget { playgroundController: playgroundController, name: 'widgets.output.graph'.tr(), isSelected: tabController.index == 2, - value: playgroundController.result?.graph ?? '', + value: playgroundController.codeRunner.result?.graph ?? '', ), ], ), diff --git a/playground/frontend/playground_components/lib/src/widgets/output/result_filter_bubble.dart b/playground/frontend/playground_components/lib/src/widgets/output/result_filter_bubble.dart index a18ddb01d81a..072f4bae4520 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/result_filter_bubble.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/result_filter_bubble.dart @@ -36,14 +36,15 @@ class ResultFilterBubble extends StatelessWidget { @override Widget build(BuildContext context) { - final isSelected = type == playgroundController.selectedOutputFilterType; + final isSelected = + type == playgroundController.codeRunner.selectedOutputFilterType; return BubbleWidget( isSelected: isSelected, onTap: () { if (!isSelected) { - playgroundController.setSelectedOutputFilterType(type); - playgroundController.filterOutput(type); + playgroundController.codeRunner.setSelectedOutputFilterType(type); + playgroundController.codeRunner.filterOutput(type); } }, title: name, diff --git a/playground/frontend/playground_components/lib/src/widgets/periodic_rebuilder.dart b/playground/frontend/playground_components/lib/src/widgets/periodic_rebuilder.dart new file mode 100644 index 000000000000..037f41008059 --- /dev/null +++ b/playground/frontend/playground_components/lib/src/widgets/periodic_rebuilder.dart @@ -0,0 +1,44 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; + +class PeriodicRebuilderWidget extends StatefulWidget { + final int rebuildFrequencyMls; + final Widget Function() builder; + + const PeriodicRebuilderWidget({ + super.key, + required this.rebuildFrequencyMls, + required this.builder, + }); + + @override + State createState() => + _PeriodicRebuilderWidgetState(); +} + +class _PeriodicRebuilderWidgetState extends State { + late Timer _timer; + + @override + void initState() { + super.initState(); + _timer = Timer.periodic( + Duration(milliseconds: widget.rebuildFrequencyMls), + (_) { + setState(() {}); + }, + ); + } + + @override + void dispose() { + super.dispose(); + _timer.cancel(); + } + + @override + Widget build(BuildContext context) { + return widget.builder(); + } +} diff --git a/playground/frontend/playground_components/lib/src/widgets/reset_button.dart b/playground/frontend/playground_components/lib/src/widgets/reset_button.dart index 6cca4cf80d22..66dc5726862b 100644 --- a/playground/frontend/playground_components/lib/src/widgets/reset_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/reset_button.dart @@ -49,7 +49,7 @@ class ResetButton extends StatelessWidget { label: 'widgets.resetButton.label'.tr(), onPressed: () { beforeReset?.call(); - playgroundController.reset(); + playgroundController.codeRunner.reset(); }, ), ); diff --git a/playground/frontend/playground_components/lib/src/widgets/run_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_button.dart index 66ac02247979..beb012c3a844 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_button.dart @@ -22,6 +22,7 @@ import 'package:flutter/material.dart'; import '../constants/sizes.dart'; import '../controllers/playground_controller.dart'; import '../theme/theme.dart'; +import 'periodic_rebuilder.dart'; import 'shortcut_tooltip.dart'; const kMsToSec = 1000; @@ -31,7 +32,6 @@ const _width = 150.0; class RunButton extends StatelessWidget { final PlaygroundController playgroundController; - final bool isRunning; final VoidCallback runCode; final VoidCallback cancelRun; final bool disabled; @@ -39,7 +39,6 @@ class RunButton extends StatelessWidget { const RunButton({ super.key, required this.playgroundController, - required this.isRunning, required this.runCode, required this.cancelRun, this.disabled = false, @@ -47,51 +46,86 @@ class RunButton extends StatelessWidget { @override Widget build(BuildContext context) { - return SizedBox( - width: _width, - height: BeamSizes.buttonHeight, - child: ShortcutTooltip( - shortcut: playgroundController.runShortcut, - child: ElevatedButton.icon( - style: const ButtonStyle( - padding: MaterialStatePropertyAll(EdgeInsets.zero), + return AnimatedBuilder( + animation: playgroundController.codeRunner, + builder: (context, child) { + final isRunning = playgroundController.codeRunner.isCodeRunning; + final runStartDate = playgroundController.codeRunner.runStartDate; + + return SizedBox( + width: _width, + height: BeamSizes.buttonHeight, + child: ShortcutTooltip( + shortcut: playgroundController.runShortcut, + child: ElevatedButton.icon( + style: const ButtonStyle( + padding: MaterialStatePropertyAll(EdgeInsets.zero), + ), + icon: isRunning + ? SizedBox( + width: BeamIconSizes.small, + height: BeamIconSizes.small, + child: CircularProgressIndicator( + color: Theme.of(context) + .extension()! + .primaryBackgroundTextColor, + ), + ) + : const Icon(Icons.play_arrow), + label: isRunning + ? PeriodicRebuilderWidget( + rebuildFrequencyMls: 1, + builder: () { + return _ButtonText( + isRunning: isRunning, + runStartDate: runStartDate, + ); + }, + ) + : _ButtonText( + isRunning: isRunning, + runStartDate: runStartDate, + ), + onPressed: _onPressHandler(), + ), ), - icon: isRunning - ? SizedBox( - width: BeamIconSizes.small, - height: BeamIconSizes.small, - child: CircularProgressIndicator( - color: Theme.of(context) - .extension()! - .primaryBackgroundTextColor, - ), - ) - : const Icon(Icons.play_arrow), - label: StreamBuilder( - stream: playgroundController.executionTime, - builder: (context, AsyncSnapshot state) { - final seconds = (state.data ?? 0) / kMsToSec; - final runText = 'widgets.runOrCancelButton.titles.run'.tr(); - final cancelText = - 'widgets.runOrCancelButton.titles.cancel'.tr(); - final buttonText = isRunning ? cancelText : runText; - if (seconds > 0) { - return Text( - '$buttonText (${seconds.toStringAsFixed(kSecondsFractions)} s)', - ); - } - return Text(buttonText); - }), - onPressed: onPressHandler(), - ), - ), + ); + }, ); } - onPressHandler() { + VoidCallback? _onPressHandler() { if (disabled) { return null; } - return !isRunning ? runCode : cancelRun; + return !playgroundController.codeRunner.isCodeRunning ? runCode : cancelRun; + } +} + +class _ButtonText extends StatelessWidget { + final bool isRunning; + final DateTime? runStartDate; + + const _ButtonText({ + required this.isRunning, + required this.runStartDate, + }); + + @override + Widget build(BuildContext context) { + final runText = 'widgets.runOrCancelButton.titles.run'.tr(); + final cancelText = 'widgets.runOrCancelButton.titles.cancel'.tr(); + final buttonText = isRunning ? cancelText : runText; + + final elapsedDuration = + DateTime.now().difference(runStartDate ?? DateTime.now()); + + if (elapsedDuration.inMilliseconds > 0) { + final seconds = elapsedDuration.inMilliseconds / kMsToSec; + return Text( + '$buttonText (${seconds.toStringAsFixed(kSecondsFractions)} s)', + ); + } + return Text(buttonText); } } diff --git a/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart index 7bbd204fcb2c..0e99877c0396 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart @@ -16,6 +16,8 @@ * limitations under the License. */ +import 'dart:async'; + import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/widgets.dart'; @@ -41,20 +43,20 @@ class RunOrCancelButton extends StatelessWidget { return RunButton( playgroundController: playgroundController, disabled: playgroundController.selectedExample?.isMultiFile ?? false, - isRunning: playgroundController.isCodeRunning, - cancelRun: () { + cancelRun: () async { beforeCancel?.call(); - playgroundController.cancelRun().catchError( + await playgroundController.codeRunner.cancelRun().catchError( (_) => NotificationManager.showError( - context, - 'widgets.runOrCancelButton.notificationTitles.runCode'.tr(), - 'widgets.runOrCancelButton.notificationTitles.cancelExecution'.tr(), - ), - ); + context, + 'widgets.runOrCancelButton.notificationTitles.runCode'.tr(), + 'widgets.runOrCancelButton.notificationTitles.cancelExecution' + .tr(), + ), + ); }, runCode: () { beforeRun?.call(); - playgroundController.runCode( + playgroundController.codeRunner.runCode( onFinish: onComplete, ); }, 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 f709cc587f4a..f0d0874f6962 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 @@ -51,13 +51,13 @@ Future main() async { }); test('Initial value of isCodeRunning should be false', () { - expect(state.isCodeRunning, false); + expect(state.codeRunner.isCodeRunning, false); }); test('Initial value of pipelineOptions should be empty string', () { - expect(state.pipelineOptions, null); + expect(state.codeRunner.pipelineOptions, null); state.setSdk(Sdk.go); - expect(state.pipelineOptions, ''); + expect(state.codeRunner.pipelineOptions, ''); }); test('Initial value of source should be empty string', () { @@ -126,14 +126,14 @@ Future main() async { state.addListener(() { expect(state.source, exampleMock1.source); }); - state.reset(); + state.codeRunner.reset(); }); test( 'If Playground state result is empty, then resetError should break the execution', () { - state.resetError(); - expect(state.result, null); + state.codeRunner.resetError(); + expect(state.codeRunner.result, null); }, ); @@ -142,7 +142,7 @@ Future main() async { () { state.setSdk(Sdk.go); state.addListener(() { - expect(state.pipelineOptions, 'test options'); + expect(state.codeRunner.pipelineOptions, 'test options'); }); state.setPipelineOptions('test options'); }, From 04266ac50555a0154ecbe41e64e89c32bc61085d Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Tue, 20 Dec 2022 11:44:54 +0600 Subject: [PATCH 02/17] comments (#24617) --- .../components/editor_textarea_wrapper.dart | 1 + .../lib/src/controllers/code_runner.dart | 25 +++++++++++-------- .../controllers/playground_controller.dart | 7 ++---- ...c_rebuilder.dart => periodic_builder.dart} | 17 ++++++------- .../lib/src/widgets/run_button.dart | 17 ++++++------- .../lib/src/widgets/run_or_cancel_button.dart | 19 +++++++------- 6 files changed, 43 insertions(+), 43 deletions(-) rename playground/frontend/playground_components/lib/src/widgets/{periodic_rebuilder.dart => periodic_builder.dart} (52%) diff --git a/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart b/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart index 3c684ec17fff..d1f9ddc8dec8 100644 --- a/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart +++ b/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart @@ -103,6 +103,7 @@ class CodeTextAreaWrapper extends StatelessWidget { } void _handleError(BuildContext context, PlaygroundController controller) { + // TODO(nausharipov): Remove NotificationManager https://github.com/apache/beam/issues/24690 NotificationManager.showError( context, AppLocalizations.of(context)!.runCode, diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index 3d5340007e7f..e3edefaa444e 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -27,21 +27,23 @@ import 'snippet_editing_controller.dart'; class CodeRunner extends ChangeNotifier { final CodeRepository? _codeRepository; - final ValueGetter _snippetEditingController; + final ValueGetter _snippetEditingControllerGetter; + SnippetEditingController? snippetEditingController; CodeRunner({ required ValueGetter snippetEditingController, CodeRepository? codeRepository, }) : _codeRepository = codeRepository, - _snippetEditingController = snippetEditingController; + _snippetEditingControllerGetter = snippetEditingController; RunCodeResult? _result; StreamSubscription? _runSubscription; String outputResult = ''; + // TODO(nausharipov): Move CodeRunner.outputType into a view https://github.com/apache/beam/issues/24691 OutputType selectedOutputFilterType = OutputType.all; DateTime? _runStartDate; - String get pipelineOptions => _snippetEditingController().pipelineOptions; + String? get pipelineOptions => snippetEditingController?.pipelineOptions; RunCodeResult? get result => _result; DateTime? get runStartDate => _runStartDate; bool get isCodeRunning => !(_result?.isFinished ?? true); @@ -54,9 +56,10 @@ class CodeRunner extends ChangeNotifier { void runCode({void Function()? onFinish}) { _runStartDate = DateTime.now(); notifyListeners(); + snippetEditingController = _snippetEditingControllerGetter(); final parsedPipelineOptions = - parsePipelineOptions(_snippetEditingController().pipelineOptions); + parsePipelineOptions(snippetEditingController!.pipelineOptions); if (parsedPipelineOptions == null) { _result = const RunCodeResult( status: RunCodeStatus.compileError, @@ -66,13 +69,13 @@ class CodeRunner extends ChangeNotifier { return; } - if (!_snippetEditingController().isChanged && - _snippetEditingController().selectedExample?.outputs != null) { + if (!snippetEditingController!.isChanged && + snippetEditingController!.selectedExample?.outputs != null) { unawaited(_showPrecompiledResult()); } else { final request = RunCodeRequest( - code: _snippetEditingController().codeController.fullText, - sdk: _snippetEditingController().sdk, + code: snippetEditingController!.codeController.fullText, + sdk: snippetEditingController!.sdk, pipelineOptions: parsedPipelineOptions, ); _runSubscription = _codeRepository?.runCode(request).listen((event) { @@ -81,6 +84,7 @@ class CodeRunner extends ChangeNotifier { if (event.isFinished && onFinish != null) { onFinish(); + snippetEditingController = null; } }); notifyListeners(); @@ -123,7 +127,7 @@ class CodeRunner extends ChangeNotifier { } void reset() { - _snippetEditingController().reset(); + _snippetEditingControllerGetter().reset(); outputResult = ''; notifyListeners(); } @@ -140,6 +144,7 @@ class CodeRunner extends ChangeNotifier { } Future cancelRun() async { + snippetEditingController = null; await _runSubscription?.cancel(); final pipelineUuid = result?.pipelineUuid ?? ''; @@ -164,7 +169,7 @@ class CodeRunner extends ChangeNotifier { _result = const RunCodeResult( status: RunCodeStatus.preparation, ); - final selectedExample = _snippetEditingController().selectedExample!; + final selectedExample = _snippetEditingControllerGetter().selectedExample!; notifyListeners(); // add a little delay to improve user experience diff --git a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart index 2c541b7ac704..5a663055817d 100644 --- a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart +++ b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart @@ -45,23 +45,20 @@ class PlaygroundController with ChangeNotifier { final ExamplesLoader examplesLoader; late final CodeRunner codeRunner; - final CodeRepository? _codeRepository; final _snippetEditingControllers = {}; Sdk? _sdk; - // TODO(alexeyinkin): Extract along with run status, https://github.com/apache/beam/issues/23248 - PlaygroundController({ required this.exampleCache, required this.examplesLoader, CodeRepository? codeRepository, - }) : _codeRepository = codeRepository { + }) { examplesLoader.setPlaygroundController(this); codeRunner = CodeRunner( - codeRepository: _codeRepository, + codeRepository: codeRepository, snippetEditingController: () => snippetEditingController!, )..addListener(notifyListeners); } diff --git a/playground/frontend/playground_components/lib/src/widgets/periodic_rebuilder.dart b/playground/frontend/playground_components/lib/src/widgets/periodic_builder.dart similarity index 52% rename from playground/frontend/playground_components/lib/src/widgets/periodic_rebuilder.dart rename to playground/frontend/playground_components/lib/src/widgets/periodic_builder.dart index 037f41008059..55317a5c7ded 100644 --- a/playground/frontend/playground_components/lib/src/widgets/periodic_rebuilder.dart +++ b/playground/frontend/playground_components/lib/src/widgets/periodic_builder.dart @@ -2,29 +2,28 @@ import 'dart:async'; import 'package:flutter/material.dart'; -class PeriodicRebuilderWidget extends StatefulWidget { - final int rebuildFrequencyMls; - final Widget Function() builder; +class PeriodicBuilderWidget extends StatefulWidget { + final Duration interval; + final ValueGetter builder; - const PeriodicRebuilderWidget({ + const PeriodicBuilderWidget({ super.key, - required this.rebuildFrequencyMls, + required this.interval, required this.builder, }); @override - State createState() => - _PeriodicRebuilderWidgetState(); + State createState() => _PeriodicBuilderWidgetState(); } -class _PeriodicRebuilderWidgetState extends State { +class _PeriodicBuilderWidgetState extends State { late Timer _timer; @override void initState() { super.initState(); _timer = Timer.periodic( - Duration(milliseconds: widget.rebuildFrequencyMls), + widget.interval, (_) { setState(() {}); }, diff --git a/playground/frontend/playground_components/lib/src/widgets/run_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_button.dart index beb012c3a844..8a330b1c1f54 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_button.dart @@ -22,7 +22,7 @@ import 'package:flutter/material.dart'; import '../constants/sizes.dart'; import '../controllers/playground_controller.dart'; import '../theme/theme.dart'; -import 'periodic_rebuilder.dart'; +import 'periodic_builder.dart'; import 'shortcut_tooltip.dart'; const kMsToSec = 1000; @@ -34,14 +34,14 @@ class RunButton extends StatelessWidget { final PlaygroundController playgroundController; final VoidCallback runCode; final VoidCallback cancelRun; - final bool disabled; + final bool isEnabled; const RunButton({ super.key, required this.playgroundController, required this.runCode, required this.cancelRun, - this.disabled = false, + this.isEnabled = false, }); @override @@ -73,8 +73,8 @@ class RunButton extends StatelessWidget { ) : const Icon(Icons.play_arrow), label: isRunning - ? PeriodicRebuilderWidget( - rebuildFrequencyMls: 1, + ? PeriodicBuilderWidget( + interval: const Duration(milliseconds: 1), builder: () { return _ButtonText( isRunning: isRunning, @@ -86,7 +86,7 @@ class RunButton extends StatelessWidget { isRunning: isRunning, runStartDate: runStartDate, ), - onPressed: _onPressHandler(), + onPressed: isEnabled ? _onPressed : null, ), ), ); @@ -94,10 +94,7 @@ class RunButton extends StatelessWidget { ); } - VoidCallback? _onPressHandler() { - if (disabled) { - return null; - } + VoidCallback _onPressed() { return !playgroundController.codeRunner.isCodeRunning ? runCode : cancelRun; } } diff --git a/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart index 0e99877c0396..ae5fa2692415 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart @@ -42,17 +42,18 @@ class RunOrCancelButton extends StatelessWidget { Widget build(BuildContext context) { return RunButton( playgroundController: playgroundController, - disabled: playgroundController.selectedExample?.isMultiFile ?? false, + isEnabled: playgroundController.selectedExample?.isMultiFile ?? false, cancelRun: () async { beforeCancel?.call(); - await playgroundController.codeRunner.cancelRun().catchError( - (_) => NotificationManager.showError( - context, - 'widgets.runOrCancelButton.notificationTitles.runCode'.tr(), - 'widgets.runOrCancelButton.notificationTitles.cancelExecution' - .tr(), - ), - ); + try { + await playgroundController.codeRunner.cancelRun(); + } on Exception catch (_) { + NotificationManager.showError( + context, + 'widgets.runOrCancelButton.notificationTitles.runCode'.tr(), + 'widgets.runOrCancelButton.notificationTitles.cancelExecution'.tr(), + ); + } }, runCode: () { beforeRun?.call(); From 6fab2b10e7b755d9ec61b4a912f6a61fd6df5423 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Wed, 21 Dec 2022 22:06:03 +0600 Subject: [PATCH 03/17] comments (1) (#24617) --- .../components/editor_textarea_wrapper.dart | 2 +- .../lib/src/controllers/code_runner.dart | 15 ++++--- .../controllers/playground_controller.dart | 39 +++++-------------- .../lib/src/widgets/reset_button.dart | 2 +- .../lib/src/widgets/run_button.dart | 25 ++++++------ .../lib/src/widgets/run_or_cancel_button.dart | 4 +- .../playground_controller_test.dart | 4 +- 7 files changed, 36 insertions(+), 55 deletions(-) diff --git a/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart b/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart index d1f9ddc8dec8..8114eadfe4f4 100644 --- a/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart +++ b/playground/frontend/lib/pages/playground/components/editor_textarea_wrapper.dart @@ -109,6 +109,6 @@ class CodeTextAreaWrapper extends StatelessWidget { AppLocalizations.of(context)!.runCode, controller.codeRunner.result?.errorMessage ?? '', ); - controller.codeRunner.resetError(); + controller.resetError(); } } diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index e3edefaa444e..c35b876cd8cd 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -126,19 +126,18 @@ class CodeRunner extends ChangeNotifier { notifyListeners(); } - void reset() { - _snippetEditingControllerGetter().reset(); + void resetOutputResult() { outputResult = ''; notifyListeners(); } - void resetError() { - if (result == null) { + void setResultAfterResetError() { + if (_result == null) { return; } _result = RunCodeResult( - status: result!.status, - output: result!.output, + status: _result!.status, + output: _result!.output, ); notifyListeners(); } @@ -146,7 +145,7 @@ class CodeRunner extends ChangeNotifier { Future cancelRun() async { snippetEditingController = null; await _runSubscription?.cancel(); - final pipelineUuid = result?.pipelineUuid ?? ''; + final pipelineUuid = _result?.pipelineUuid ?? ''; if (pipelineUuid.isNotEmpty) { await _codeRepository?.cancelExecution(pipelineUuid); @@ -169,7 +168,7 @@ class CodeRunner extends ChangeNotifier { _result = const RunCodeResult( status: RunCodeStatus.preparation, ); - final selectedExample = _snippetEditingControllerGetter().selectedExample!; + final selectedExample = snippetEditingController!.selectedExample!; notifyListeners(); // add a little delay to improve user experience diff --git a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart index 5a663055817d..805d2bd5707e 100644 --- a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart +++ b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart @@ -175,40 +175,21 @@ class PlaygroundController with ChangeNotifier { controller.setSource(source); } + void reset() { + snippetEditingController?.reset(); + codeRunner.resetOutputResult(); + } + + void resetError() { + codeRunner.setResultAfterResetError(); + } + void setPipelineOptions(String options) { final controller = requireSnippetEditingController(); controller.pipelineOptions = options; notifyListeners(); } - StreamController _createExecutionTimeStream() { - StreamController? streamController; - Timer? timer; - Duration timerInterval = const Duration(milliseconds: kExecutionTimeUpdate); - int ms = 0; - - void stopTimer() { - timer?.cancel(); - streamController?.close(); - } - - void tick(_) { - ms += kExecutionTimeUpdate; - streamController?.add(ms); - } - - void startTimer() { - timer = Timer.periodic(timerInterval, tick); - } - - streamController = StreamController.broadcast( - onListen: startTimer, - onCancel: stopTimer, - ); - - return streamController; - } - Future getSnippetId() { final controller = requireSnippetEditingController(); @@ -252,7 +233,7 @@ class PlaygroundController with ChangeNotifier { ), actionIntent: const ResetIntent(), createAction: (BuildContext context) => CallbackAction( - onInvoke: (_) => codeRunner.reset(), + onInvoke: (_) => reset(), ), ); diff --git a/playground/frontend/playground_components/lib/src/widgets/reset_button.dart b/playground/frontend/playground_components/lib/src/widgets/reset_button.dart index 66dc5726862b..6cca4cf80d22 100644 --- a/playground/frontend/playground_components/lib/src/widgets/reset_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/reset_button.dart @@ -49,7 +49,7 @@ class ResetButton extends StatelessWidget { label: 'widgets.resetButton.label'.tr(), onPressed: () { beforeReset?.call(); - playgroundController.codeRunner.reset(); + playgroundController.reset(); }, ), ); diff --git a/playground/frontend/playground_components/lib/src/widgets/run_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_button.dart index 8a330b1c1f54..96463486a4b0 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_button.dart @@ -25,11 +25,6 @@ import '../theme/theme.dart'; import 'periodic_builder.dart'; import 'shortcut_tooltip.dart'; -const kMsToSec = 1000; -const kSecondsFractions = 1; - -const _width = 150.0; - class RunButton extends StatelessWidget { final PlaygroundController playgroundController; final VoidCallback runCode; @@ -41,9 +36,12 @@ class RunButton extends StatelessWidget { required this.playgroundController, required this.runCode, required this.cancelRun, - this.isEnabled = false, + this.isEnabled = true, }); + static const _buttonTextRebuildInterval = 100; + static const _width = 150.0; + @override Widget build(BuildContext context) { return AnimatedBuilder( @@ -74,7 +72,9 @@ class RunButton extends StatelessWidget { : const Icon(Icons.play_arrow), label: isRunning ? PeriodicBuilderWidget( - interval: const Duration(milliseconds: 1), + interval: const Duration( + milliseconds: _buttonTextRebuildInterval, + ), builder: () { return _ButtonText( isRunning: isRunning, @@ -86,7 +86,7 @@ class RunButton extends StatelessWidget { isRunning: isRunning, runStartDate: runStartDate, ), - onPressed: isEnabled ? _onPressed : null, + onPressed: isEnabled ? _onPressed() : null, ), ), ); @@ -95,7 +95,7 @@ class RunButton extends StatelessWidget { } VoidCallback _onPressed() { - return !playgroundController.codeRunner.isCodeRunning ? runCode : cancelRun; + return playgroundController.codeRunner.isCodeRunning ? cancelRun : runCode; } } @@ -108,6 +108,9 @@ class _ButtonText extends StatelessWidget { required this.runStartDate, }); + static const _msToSec = 1000; + static const _secondsFractions = 1; + @override Widget build(BuildContext context) { final runText = 'widgets.runOrCancelButton.titles.run'.tr(); @@ -118,9 +121,9 @@ class _ButtonText extends StatelessWidget { DateTime.now().difference(runStartDate ?? DateTime.now()); if (elapsedDuration.inMilliseconds > 0) { - final seconds = elapsedDuration.inMilliseconds / kMsToSec; + final seconds = elapsedDuration.inMilliseconds / _msToSec; return Text( - '$buttonText (${seconds.toStringAsFixed(kSecondsFractions)} s)', + '$buttonText (${seconds.toStringAsFixed(_secondsFractions)} s)', ); } return Text(buttonText); diff --git a/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart index ae5fa2692415..71e73a419f1b 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_or_cancel_button.dart @@ -16,8 +16,6 @@ * limitations under the License. */ -import 'dart:async'; - import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/widgets.dart'; @@ -42,7 +40,7 @@ class RunOrCancelButton extends StatelessWidget { Widget build(BuildContext context) { return RunButton( playgroundController: playgroundController, - isEnabled: playgroundController.selectedExample?.isMultiFile ?? false, + isEnabled: !(playgroundController.selectedExample?.isMultiFile ?? false), cancelRun: () async { beforeCancel?.call(); try { 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 f0d0874f6962..9618b4b9717a 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 @@ -126,13 +126,13 @@ Future main() async { state.addListener(() { expect(state.source, exampleMock1.source); }); - state.codeRunner.reset(); + state.reset(); }); test( 'If Playground state result is empty, then resetError should break the execution', () { - state.codeRunner.resetError(); + state.resetError(); expect(state.codeRunner.result, null); }, ); From 73b76875e3f84136195dadb498555e47d20aeebb Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Thu, 29 Dec 2022 13:47:22 +0600 Subject: [PATCH 04/17] cancel run on reset (#24617) --- .../lib/src/controllers/playground_controller.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart index 483eaee3b3cb..b506d249b37a 100644 --- a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart +++ b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart @@ -220,7 +220,8 @@ class PlaygroundController with ChangeNotifier { controller.setSource(source); } - void reset() { + Future reset() async { + await codeRunner.cancelRun(); snippetEditingController?.reset(); codeRunner.resetOutputResult(); } From a92d86eacc8e33042eefc9106c8365a50f4160b4 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Thu, 29 Dec 2022 13:47:39 +0600 Subject: [PATCH 05/17] regenerated mocks (#24617) --- .../examples_loader_test.mocks.dart | 221 +++++++----------- 1 file changed, 78 insertions(+), 143 deletions(-) diff --git a/playground/frontend/playground_components/test/src/controllers/example_loaders/examples_loader_test.mocks.dart b/playground/frontend/playground_components/test/src/controllers/example_loaders/examples_loader_test.mocks.dart index e20ace76e455..22b98a7b664e 100644 --- a/playground/frontend/playground_components/test/src/controllers/example_loaders/examples_loader_test.mocks.dart +++ b/playground/frontend/playground_components/test/src/controllers/example_loaders/examples_loader_test.mocks.dart @@ -8,26 +8,26 @@ import 'dart:ui' as _i15; import 'package:mockito/mockito.dart' as _i1; import 'package:playground_components/src/cache/example_cache.dart' as _i2; +import 'package:playground_components/src/controllers/code_runner.dart' as _i4; import 'package:playground_components/src/controllers/example_loaders/examples_loader.dart' as _i3; import 'package:playground_components/src/controllers/playground_controller.dart' - as _i10; + as _i11; import 'package:playground_components/src/controllers/snippet_editing_controller.dart' - as _i5; + as _i6; import 'package:playground_components/src/models/category_with_examples.dart' as _i16; -import 'package:playground_components/src/models/example.dart' as _i9; -import 'package:playground_components/src/models/example_base.dart' as _i8; +import 'package:playground_components/src/models/example.dart' as _i10; +import 'package:playground_components/src/models/example_base.dart' as _i9; import 'package:playground_components/src/models/example_loading_descriptors/example_loading_descriptor.dart' as _i13; import 'package:playground_components/src/models/example_loading_descriptors/examples_loading_descriptor.dart' - as _i7; + as _i8; import 'package:playground_components/src/models/example_loading_descriptors/user_shared_example_loading_descriptor.dart' - as _i6; + as _i7; import 'package:playground_components/src/models/loading_status.dart' as _i17; -import 'package:playground_components/src/models/outputs.dart' as _i11; import 'package:playground_components/src/models/sdk.dart' as _i12; -import 'package:playground_components/src/models/shortcut.dart' as _i4; +import 'package:playground_components/src/models/shortcut.dart' as _i5; import 'package:playground_components/src/repositories/models/shared_file.dart' as _i18; @@ -45,26 +45,28 @@ class _FakeExampleCache_0 extends _i1.Fake implements _i2.ExampleCache {} class _FakeExamplesLoader_1 extends _i1.Fake implements _i3.ExamplesLoader {} -class _FakeBeamShortcut_2 extends _i1.Fake implements _i4.BeamShortcut {} +class _FakeCodeRunner_2 extends _i1.Fake implements _i4.CodeRunner {} + +class _FakeBeamShortcut_3 extends _i1.Fake implements _i5.BeamShortcut {} -class _FakeSnippetEditingController_3 extends _i1.Fake - implements _i5.SnippetEditingController {} +class _FakeSnippetEditingController_4 extends _i1.Fake + implements _i6.SnippetEditingController {} -class _FakeUserSharedExampleLoadingDescriptor_4 extends _i1.Fake - implements _i6.UserSharedExampleLoadingDescriptor {} +class _FakeUserSharedExampleLoadingDescriptor_5 extends _i1.Fake + implements _i7.UserSharedExampleLoadingDescriptor {} -class _FakeExamplesLoadingDescriptor_5 extends _i1.Fake - implements _i7.ExamplesLoadingDescriptor {} +class _FakeExamplesLoadingDescriptor_6 extends _i1.Fake + implements _i8.ExamplesLoadingDescriptor {} -class _FakeExampleBase_6 extends _i1.Fake implements _i8.ExampleBase {} +class _FakeExampleBase_7 extends _i1.Fake implements _i9.ExampleBase {} -class _FakeExample_7 extends _i1.Fake implements _i9.Example {} +class _FakeExample_8 extends _i1.Fake implements _i10.Example {} /// A class which mocks [PlaygroundController]. /// /// See the documentation for Mockito's code generation for more information. class MockPlaygroundController extends _i1.Mock - implements _i10.PlaygroundController { + implements _i11.PlaygroundController { MockPlaygroundController() { _i1.throwOnMissingStub(this); } @@ -80,39 +82,25 @@ class MockPlaygroundController extends _i1.Mock returnValue: _FakeExamplesLoader_1(), ) as _i3.ExamplesLoader); @override - _i11.OutputType get selectedOutputFilterType => (super.noSuchMethod( - Invocation.getter(#selectedOutputFilterType), - returnValue: _i11.OutputType.all, - ) as _i11.OutputType); - @override - set selectedOutputFilterType(_i11.OutputType? _selectedOutputFilterType) => - super.noSuchMethod( - Invocation.setter( - #selectedOutputFilterType, - _selectedOutputFilterType, - ), - returnValueForMissingStub: null, - ); - @override - String get outputResult => (super.noSuchMethod( - Invocation.getter(#outputResult), - returnValue: '', - ) as String); + _i4.CodeRunner get codeRunner => (super.noSuchMethod( + Invocation.getter(#codeRunner), + returnValue: _FakeCodeRunner_2(), + ) as _i4.CodeRunner); @override - set outputResult(String? _outputResult) => super.noSuchMethod( + set codeRunner(_i4.CodeRunner? _codeRunner) => super.noSuchMethod( Invocation.setter( - #outputResult, - _outputResult, + #codeRunner, + _codeRunner, ), returnValueForMissingStub: null, ); @override - _i4.BeamShortcut get runShortcut => (super.noSuchMethod( + _i5.BeamShortcut get runShortcut => (super.noSuchMethod( Invocation.getter(#runShortcut), - returnValue: _FakeBeamShortcut_2(), - ) as _i4.BeamShortcut); + returnValue: _FakeBeamShortcut_3(), + ) as _i5.BeamShortcut); @override - set runShortcut(_i4.BeamShortcut? _runShortcut) => super.noSuchMethod( + set runShortcut(_i5.BeamShortcut? _runShortcut) => super.noSuchMethod( Invocation.setter( #runShortcut, _runShortcut, @@ -120,12 +108,12 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - _i4.BeamShortcut get resetShortcut => (super.noSuchMethod( + _i5.BeamShortcut get resetShortcut => (super.noSuchMethod( Invocation.getter(#resetShortcut), - returnValue: _FakeBeamShortcut_2(), - ) as _i4.BeamShortcut); + returnValue: _FakeBeamShortcut_3(), + ) as _i5.BeamShortcut); @override - set resetShortcut(_i4.BeamShortcut? _resetShortcut) => super.noSuchMethod( + set resetShortcut(_i5.BeamShortcut? _resetShortcut) => super.noSuchMethod( Invocation.setter( #resetShortcut, _resetShortcut, @@ -138,11 +126,6 @@ class MockPlaygroundController extends _i1.Mock returnValue: '', ) as String); @override - bool get isCodeRunning => (super.noSuchMethod( - Invocation.getter(#isCodeRunning), - returnValue: false, - ) as bool); - @override bool get isExampleChanged => (super.noSuchMethod( Invocation.getter(#isExampleChanged), returnValue: false, @@ -153,24 +136,24 @@ class MockPlaygroundController extends _i1.Mock returnValue: false, ) as bool); @override - List<_i4.BeamShortcut> get shortcuts => (super.noSuchMethod( + List<_i5.BeamShortcut> get shortcuts => (super.noSuchMethod( Invocation.getter(#shortcuts), - returnValue: <_i4.BeamShortcut>[], - ) as List<_i4.BeamShortcut>); + returnValue: <_i5.BeamShortcut>[], + ) as List<_i5.BeamShortcut>); @override bool get hasListeners => (super.noSuchMethod( Invocation.getter(#hasListeners), returnValue: false, ) as bool); @override - _i5.SnippetEditingController requireSnippetEditingController() => + _i6.SnippetEditingController requireSnippetEditingController() => (super.noSuchMethod( Invocation.method( #requireSnippetEditingController, [], ), - returnValue: _FakeSnippetEditingController_3(), - ) as _i5.SnippetEditingController); + returnValue: _FakeSnippetEditingController_4(), + ) as _i6.SnippetEditingController); @override void setEmptyIfNoSdk(_i12.Sdk? sdk) => super.noSuchMethod( Invocation.method( @@ -194,7 +177,7 @@ class MockPlaygroundController extends _i1.Mock ); @override void setExample( - _i9.Example? example, { + _i10.Example? example, { _i13.ExampleLoadingDescriptor? descriptor, bool? setCurrentSdk, }) => @@ -231,37 +214,14 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - void setSelectedOutputFilterType(_i11.OutputType? type) => super.noSuchMethod( - Invocation.method( - #setSelectedOutputFilterType, - [type], - ), - returnValueForMissingStub: null, - ); - @override - void setOutputResult(String? outputs) => super.noSuchMethod( - Invocation.method( - #setOutputResult, - [outputs], - ), - returnValueForMissingStub: null, - ); - @override - void clearOutput() => super.noSuchMethod( - Invocation.method( - #clearOutput, - [], - ), - returnValueForMissingStub: null, - ); - @override - void reset() => super.noSuchMethod( + _i14.Future reset() => (super.noSuchMethod( Invocation.method( #reset, [], ), - returnValueForMissingStub: null, - ); + returnValue: Future.value(), + returnValueForMissingStub: Future.value(), + ) as _i14.Future); @override void resetError() => super.noSuchMethod( Invocation.method( @@ -279,50 +239,32 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - void runCode({void Function()? onFinish}) => super.noSuchMethod( + _i14.Future<_i7.UserSharedExampleLoadingDescriptor> saveSnippet() => + (super.noSuchMethod( Invocation.method( - #runCode, + #saveSnippet, [], - {#onFinish: onFinish}, ), - returnValueForMissingStub: null, - ); + returnValue: Future<_i7.UserSharedExampleLoadingDescriptor>.value( + _FakeUserSharedExampleLoadingDescriptor_5()), + ) as _i14.Future<_i7.UserSharedExampleLoadingDescriptor>); @override - _i14.Future cancelRun() => (super.noSuchMethod( + _i8.ExamplesLoadingDescriptor getLoadingDescriptor() => (super.noSuchMethod( Invocation.method( - #cancelRun, + #getLoadingDescriptor, [], ), - returnValue: Future.value(), - returnValueForMissingStub: Future.value(), - ) as _i14.Future); + returnValue: _FakeExamplesLoadingDescriptor_6(), + ) as _i8.ExamplesLoadingDescriptor); @override - void filterOutput(_i11.OutputType? type) => super.noSuchMethod( + void dispose() => super.noSuchMethod( Invocation.method( - #filterOutput, - [type], + #dispose, + [], ), returnValueForMissingStub: null, ); @override - _i14.Future<_i6.UserSharedExampleLoadingDescriptor> saveSnippet() => - (super.noSuchMethod( - Invocation.method( - #saveSnippet, - [], - ), - returnValue: Future<_i6.UserSharedExampleLoadingDescriptor>.value( - _FakeUserSharedExampleLoadingDescriptor_4()), - ) as _i14.Future<_i6.UserSharedExampleLoadingDescriptor>); - @override - _i7.ExamplesLoadingDescriptor getLoadingDescriptor() => (super.noSuchMethod( - Invocation.method( - #getLoadingDescriptor, - [], - ), - returnValue: _FakeExamplesLoadingDescriptor_5(), - ) as _i7.ExamplesLoadingDescriptor); - @override void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, @@ -339,14 +281,6 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - void dispose() => super.noSuchMethod( - Invocation.method( - #dispose, - [], - ), - returnValueForMissingStub: null, - ); - @override void notifyListeners() => super.noSuchMethod( Invocation.method( #notifyListeners, @@ -371,10 +305,10 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { returnValue: <_i12.Sdk, List<_i16.CategoryWithExamples>>{}, ) as Map<_i12.Sdk, List<_i16.CategoryWithExamples>>); @override - Map<_i12.Sdk, _i9.Example> get defaultExamplesBySdk => (super.noSuchMethod( + Map<_i12.Sdk, _i10.Example> get defaultExamplesBySdk => (super.noSuchMethod( Invocation.getter(#defaultExamplesBySdk), - returnValue: <_i12.Sdk, _i9.Example>{}, - ) as Map<_i12.Sdk, _i9.Example>); + returnValue: <_i12.Sdk, _i10.Example>{}, + ) as Map<_i12.Sdk, _i10.Example>); @override bool get isSelectorOpened => (super.noSuchMethod( Invocation.getter(#isSelectorOpened), @@ -422,7 +356,7 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { returnValue: <_i16.CategoryWithExamples>[], ) as List<_i16.CategoryWithExamples>); @override - _i14.Future<_i8.ExampleBase> getPrecompiledObject( + _i14.Future<_i9.ExampleBase> getPrecompiledObject( String? path, _i12.Sdk? sdk, ) => @@ -434,16 +368,17 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { sdk, ], ), - returnValue: Future<_i8.ExampleBase>.value(_FakeExampleBase_6()), - ) as _i14.Future<_i8.ExampleBase>); + returnValue: Future<_i9.ExampleBase>.value(_FakeExampleBase_7()), + ) as _i14.Future<_i9.ExampleBase>); @override - _i14.Future<_i9.Example> loadSharedExample(String? id) => (super.noSuchMethod( + _i14.Future<_i10.Example> loadSharedExample(String? id) => + (super.noSuchMethod( Invocation.method( #loadSharedExample, [id], ), - returnValue: Future<_i9.Example>.value(_FakeExample_7()), - ) as _i14.Future<_i9.Example>); + returnValue: Future<_i10.Example>.value(_FakeExample_8()), + ) as _i14.Future<_i10.Example>); @override _i14.Future saveSnippet({ List<_i18.SharedFile>? files, @@ -463,14 +398,14 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { returnValue: Future.value(''), ) as _i14.Future); @override - _i14.Future<_i9.Example> loadExampleInfo(_i8.ExampleBase? example) => + _i14.Future<_i10.Example> loadExampleInfo(_i9.ExampleBase? example) => (super.noSuchMethod( Invocation.method( #loadExampleInfo, [example], ), - returnValue: Future<_i9.Example>.value(_FakeExample_7()), - ) as _i14.Future<_i9.Example>); + returnValue: Future<_i10.Example>.value(_FakeExample_8()), + ) as _i14.Future<_i10.Example>); @override void setSelectorOpened(bool? value) => super.noSuchMethod( Invocation.method( @@ -480,14 +415,14 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { returnValueForMissingStub: null, ); @override - _i14.Future<_i9.Example?> getDefaultExampleBySdk(_i12.Sdk? sdk) => + _i14.Future<_i10.Example?> getDefaultExampleBySdk(_i12.Sdk? sdk) => (super.noSuchMethod( Invocation.method( #getDefaultExampleBySdk, [sdk], ), - returnValue: Future<_i9.Example?>.value(), - ) as _i14.Future<_i9.Example?>); + returnValue: Future<_i10.Example?>.value(), + ) as _i14.Future<_i10.Example?>); @override _i14.Future loadDefaultPrecompiledObjects() => (super.noSuchMethod( Invocation.method( @@ -507,14 +442,14 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { returnValueForMissingStub: Future.value(), ) as _i14.Future); @override - _i14.Future<_i8.ExampleBase?> getCatalogExampleByPath(String? path) => + _i14.Future<_i9.ExampleBase?> getCatalogExampleByPath(String? path) => (super.noSuchMethod( Invocation.method( #getCatalogExampleByPath, [path], ), - returnValue: Future<_i8.ExampleBase?>.value(), - ) as _i14.Future<_i8.ExampleBase?>); + returnValue: Future<_i9.ExampleBase?>.value(), + ) as _i14.Future<_i9.ExampleBase?>); @override void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( From 86048dfae75a8edda53470c36d2144125cc98124 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Thu, 29 Dec 2022 17:02:46 +0600 Subject: [PATCH 06/17] runStopDate (#24617) --- .../lib/src/controllers/code_runner.dart | 13 +++++++++++-- .../lib/src/widgets/run_button.dart | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index c35b876cd8cd..a6de2e77fc71 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -42,10 +42,12 @@ class CodeRunner extends ChangeNotifier { // TODO(nausharipov): Move CodeRunner.outputType into a view https://github.com/apache/beam/issues/24691 OutputType selectedOutputFilterType = OutputType.all; DateTime? _runStartDate; + DateTime? _runStopDate; String? get pipelineOptions => snippetEditingController?.pipelineOptions; RunCodeResult? get result => _result; DateTime? get runStartDate => _runStartDate; + DateTime? get runStopDate => _runStopDate; bool get isCodeRunning => !(_result?.isFinished ?? true); void clearResult() { @@ -55,6 +57,7 @@ class CodeRunner extends ChangeNotifier { void runCode({void Function()? onFinish}) { _runStartDate = DateTime.now(); + _runStopDate = null; notifyListeners(); snippetEditingController = _snippetEditingControllerGetter(); @@ -65,6 +68,7 @@ class CodeRunner extends ChangeNotifier { status: RunCodeStatus.compileError, errorMessage: kPipelineOptionsParseError, ); + _runStopDate = DateTime.now(); notifyListeners(); return; } @@ -82,9 +86,12 @@ class CodeRunner extends ChangeNotifier { _result = event; filterOutput(selectedOutputFilterType); - if (event.isFinished && onFinish != null) { - onFinish(); + if (event.isFinished) { + if (onFinish != null) { + onFinish(); + } snippetEditingController = null; + _runStopDate = DateTime.now(); } }); notifyListeners(); @@ -161,6 +168,7 @@ class CodeRunner extends ChangeNotifier { final log = _result?.log ?? ''; final output = _result?.output ?? ''; setOutputResult(log + output); + _runStopDate = DateTime.now(); notifyListeners(); } @@ -183,6 +191,7 @@ class CodeRunner extends ChangeNotifier { ); filterOutput(selectedOutputFilterType); + _runStopDate = DateTime.now(); notifyListeners(); } } diff --git a/playground/frontend/playground_components/lib/src/widgets/run_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_button.dart index 96463486a4b0..d6326de6d0af 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_button.dart @@ -49,6 +49,7 @@ class RunButton extends StatelessWidget { builder: (context, child) { final isRunning = playgroundController.codeRunner.isCodeRunning; final runStartDate = playgroundController.codeRunner.runStartDate; + final runStopDate = playgroundController.codeRunner.runStopDate; return SizedBox( width: _width, @@ -79,12 +80,14 @@ class RunButton extends StatelessWidget { return _ButtonText( isRunning: isRunning, runStartDate: runStartDate, + runStopDate: runStopDate, ); }, ) : _ButtonText( isRunning: isRunning, runStartDate: runStartDate, + runStopDate: runStopDate, ), onPressed: isEnabled ? _onPressed() : null, ), @@ -102,10 +105,12 @@ class RunButton extends StatelessWidget { class _ButtonText extends StatelessWidget { final bool isRunning; final DateTime? runStartDate; + final DateTime? runStopDate; const _ButtonText({ required this.isRunning, required this.runStartDate, + required this.runStopDate, }); static const _msToSec = 1000; @@ -116,9 +121,10 @@ class _ButtonText extends StatelessWidget { final runText = 'widgets.runOrCancelButton.titles.run'.tr(); final cancelText = 'widgets.runOrCancelButton.titles.cancel'.tr(); final buttonText = isRunning ? cancelText : runText; + final runStopDateOrNow = runStopDate ?? DateTime.now(); final elapsedDuration = - DateTime.now().difference(runStartDate ?? DateTime.now()); + runStopDateOrNow.difference(runStartDate ?? DateTime.now()); if (elapsedDuration.inMilliseconds > 0) { final seconds = elapsedDuration.inMilliseconds / _msToSec; From 8e428640fe1d9f724e41d1b51c6a184120c1d1ef Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Fri, 30 Dec 2022 14:51:12 +0600 Subject: [PATCH 07/17] OutputFilterTypeController (#24617) --- .../lib/src/controllers/code_runner.dart | 48 ++------------- .../output_filter_type_controller.dart | 30 ++++++++++ .../controllers/playground_controller.dart | 6 +- .../lib/src/models/outputs.dart | 1 - .../lib/src/widgets/output/output_area.dart | 60 ++++++++++++------- .../lib/src/widgets/output/output_tabs.dart | 2 +- .../widgets/output/result_filter_bubble.dart | 5 +- .../widgets/output/result_filter_popover.dart | 2 +- 8 files changed, 81 insertions(+), 73 deletions(-) create mode 100644 playground/frontend/playground_components/lib/src/controllers/output_filter_type_controller.dart diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index a6de2e77fc71..3bfb04307345 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -38,9 +38,6 @@ class CodeRunner extends ChangeNotifier { RunCodeResult? _result; StreamSubscription? _runSubscription; - String outputResult = ''; - // TODO(nausharipov): Move CodeRunner.outputType into a view https://github.com/apache/beam/issues/24691 - OutputType selectedOutputFilterType = OutputType.all; DateTime? _runStartDate; DateTime? _runStopDate; @@ -50,6 +47,10 @@ class CodeRunner extends ChangeNotifier { DateTime? get runStopDate => _runStopDate; bool get isCodeRunning => !(_result?.isFinished ?? true); + String get resultLog => _result?.log ?? ''; + String get resultOutput => _result?.output ?? ''; + String get resultLogOutput => resultLog + resultOutput; + void clearResult() { _result = null; notifyListeners(); @@ -84,7 +85,7 @@ class CodeRunner extends ChangeNotifier { ); _runSubscription = _codeRepository?.runCode(request).listen((event) { _result = event; - filterOutput(selectedOutputFilterType); + notifyListeners(); if (event.isFinished) { if (onFinish != null) { @@ -98,46 +99,11 @@ class CodeRunner extends ChangeNotifier { } } - void filterOutput(OutputType type) { - final output = _result?.output ?? ''; - final log = _result?.log ?? ''; - - switch (type) { - case OutputType.all: - setOutputResult(log + output); - break; - case OutputType.log: - setOutputResult(log); - break; - case OutputType.output: - setOutputResult(output); - break; - case OutputType.graph: - setOutputResult(log + output); - break; - } - } - - void setOutputResult(String outputs) { - outputResult = outputs; - notifyListeners(); - } - void clearOutput() { _result = null; notifyListeners(); } - void setSelectedOutputFilterType(OutputType type) { - selectedOutputFilterType = type; - notifyListeners(); - } - - void resetOutputResult() { - outputResult = ''; - notifyListeners(); - } - void setResultAfterResetError() { if (_result == null) { return; @@ -165,9 +131,6 @@ class CodeRunner extends ChangeNotifier { graph: _result?.graph, ); - final log = _result?.log ?? ''; - final output = _result?.output ?? ''; - setOutputResult(log + output); _runStopDate = DateTime.now(); notifyListeners(); } @@ -190,7 +153,6 @@ class CodeRunner extends ChangeNotifier { graph: selectedExample.graph, ); - filterOutput(selectedOutputFilterType); _runStopDate = DateTime.now(); notifyListeners(); } diff --git a/playground/frontend/playground_components/lib/src/controllers/output_filter_type_controller.dart b/playground/frontend/playground_components/lib/src/controllers/output_filter_type_controller.dart new file mode 100644 index 000000000000..d245e800b016 --- /dev/null +++ b/playground/frontend/playground_components/lib/src/controllers/output_filter_type_controller.dart @@ -0,0 +1,30 @@ +/* + * 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 '../../playground_components.dart'; + +class OutputFilterTypeController extends ChangeNotifier { + OutputType outputFilterType = OutputType.all; + + void setOutputFilterType(OutputType type) { + outputFilterType = type; + notifyListeners(); + } +} diff --git a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart index b506d249b37a..e1b28f257aa7 100644 --- a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart +++ b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart @@ -40,6 +40,7 @@ import '../services/symbols/loaders/map.dart'; import '../services/symbols/symbols_notifier.dart'; import 'code_runner.dart'; import 'example_loaders/examples_loader.dart'; +import 'output_filter_type_controller.dart'; import 'snippet_editing_controller.dart'; const kTitleLength = 25; @@ -56,6 +57,8 @@ const kCachedResultsLog = class PlaygroundController with ChangeNotifier { final ExampleCache exampleCache; final ExamplesLoader examplesLoader; + final OutputFilterTypeController outputTypeController = + OutputFilterTypeController(); late final CodeRunner codeRunner; @@ -183,7 +186,6 @@ class PlaygroundController with ChangeNotifier { } codeRunner.clearResult(); - codeRunner.setOutputResult(''); notifyListeners(); } @@ -223,7 +225,7 @@ class PlaygroundController with ChangeNotifier { Future reset() async { await codeRunner.cancelRun(); snippetEditingController?.reset(); - codeRunner.resetOutputResult(); + codeRunner.clearResult(); } void resetError() { diff --git a/playground/frontend/playground_components/lib/src/models/outputs.dart b/playground/frontend/playground_components/lib/src/models/outputs.dart index fa1a360063c0..4d56e19b2178 100644 --- a/playground/frontend/playground_components/lib/src/models/outputs.dart +++ b/playground/frontend/playground_components/lib/src/models/outputs.dart @@ -20,7 +20,6 @@ enum OutputType { all, log, output, - graph, } class Outputs { diff --git a/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart b/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart index 0f453a3b4672..77b0fdbd0b60 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart @@ -17,7 +17,7 @@ */ import 'package:flutter/material.dart'; -import 'package:playground_components/playground_components.dart'; +import '../../../playground_components.dart'; import 'graph/graph.dart'; import 'output_result.dart'; @@ -28,35 +28,51 @@ class OutputArea extends StatelessWidget { final Axis graphDirection; const OutputArea({ - Key? key, + super.key, required this.playgroundController, required this.tabController, required this.graphDirection, - }) : super(key: key); + }); + + String _getResultOutput() { + final outputType = + playgroundController.outputTypeController.outputFilterType; + if (outputType == OutputType.log) { + return playgroundController.codeRunner.resultLog; + } + if (outputType == OutputType.output) { + return playgroundController.codeRunner.resultOutput; + } + return playgroundController.codeRunner.resultLogOutput; + } @override Widget build(BuildContext context) { final sdk = playgroundController.sdk; - return Container( - color: Theme.of(context).backgroundColor, - child: TabBarView( - controller: tabController, - physics: const NeverScrollableScrollPhysics(), - children: [ - OutputResult( - text: playgroundController.codeRunner.outputResult, - isSelected: tabController.index == 0, - ), - if (playgroundController.graphAvailable) - sdk == null - ? Container() - : GraphTab( - graph: playgroundController.codeRunner.result?.graph ?? '', - sdk: sdk, - direction: graphDirection, - ), - ], + return AnimatedBuilder( + animation: playgroundController.outputTypeController, + builder: (context, child) => ColoredBox( + color: Theme.of(context).backgroundColor, + child: TabBarView( + controller: tabController, + physics: const NeverScrollableScrollPhysics(), + children: [ + OutputResult( + text: _getResultOutput(), + isSelected: tabController.index == 0, + ), + if (playgroundController.graphAvailable) + sdk == null + ? Container() + : GraphTab( + graph: + playgroundController.codeRunner.result?.graph ?? '', + sdk: sdk, + direction: graphDirection, + ), + ], + ), ), ); } diff --git a/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart b/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart index 27c01483e90b..caf8d80180ed 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart @@ -43,7 +43,7 @@ class OutputTabs extends StatelessWidget { playgroundController: playgroundController, name: 'widgets.output.result'.tr(), isSelected: tabController.index == 0, - value: playgroundController.codeRunner.outputResult, + value: playgroundController.codeRunner.resultLogOutput, hasFilter: true, ), if (playgroundController.graphAvailable) diff --git a/playground/frontend/playground_components/lib/src/widgets/output/result_filter_bubble.dart b/playground/frontend/playground_components/lib/src/widgets/output/result_filter_bubble.dart index 072f4bae4520..2a93919e0e5c 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/result_filter_bubble.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/result_filter_bubble.dart @@ -37,14 +37,13 @@ class ResultFilterBubble extends StatelessWidget { @override Widget build(BuildContext context) { final isSelected = - type == playgroundController.codeRunner.selectedOutputFilterType; + type == playgroundController.outputTypeController.outputFilterType; return BubbleWidget( isSelected: isSelected, onTap: () { if (!isSelected) { - playgroundController.codeRunner.setSelectedOutputFilterType(type); - playgroundController.codeRunner.filterOutput(type); + playgroundController.outputTypeController.setOutputFilterType(type); } }, title: name, diff --git a/playground/frontend/playground_components/lib/src/widgets/output/result_filter_popover.dart b/playground/frontend/playground_components/lib/src/widgets/output/result_filter_popover.dart index a74c67e2fa17..671f7c566139 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/result_filter_popover.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/result_filter_popover.dart @@ -52,7 +52,7 @@ class ResultFilterPopover extends StatelessWidget { vertical: BeamSizes.size4, ), child: AnimatedBuilder( - animation: playgroundController, + animation: playgroundController.outputTypeController, builder: (context, child) => Row( children: [ ResultFilterBubble( From db37f84970e4c3c91db74e5fa274e14090651cc8 Mon Sep 17 00:00:00 2001 From: Darkhan Nausharipov <31556582+nausharipov@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:32:32 +0600 Subject: [PATCH 08/17] resetErrorMessageText (#24617) Co-authored-by: alexeyinkin --- .../lib/src/controllers/code_runner.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index 3bfb04307345..1a373e011165 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -104,7 +104,11 @@ class CodeRunner extends ChangeNotifier { notifyListeners(); } - void setResultAfterResetError() { + /// Resets the error message text so that on the next rebuild + /// of `CodeTextAreaWrapper` it is not picked up and not shown as a toast. + // TODO: Listen to this object outside of widgets, + // emit toasts from notifications, then remove this method. + void resetErrorMessageText() { if (_result == null) { return; } From e84d96b8ae9fe2f8eced91dd9f4f18337e2e17dc Mon Sep 17 00:00:00 2001 From: Darkhan Nausharipov <31556582+nausharipov@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:32:52 +0600 Subject: [PATCH 09/17] resetErrorMessageText (#24617) Co-authored-by: alexeyinkin --- .../lib/src/controllers/playground_controller.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart index e1b28f257aa7..e1d493e5ff33 100644 --- a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart +++ b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart @@ -228,7 +228,7 @@ class PlaygroundController with ChangeNotifier { codeRunner.clearResult(); } - void resetError() { + void resetErrorMessageText() { codeRunner.setResultAfterResetError(); } From d79b2f53e5313d081c9ca9056a5ec9740256a2b9 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Fri, 30 Dec 2022 17:47:02 +0600 Subject: [PATCH 10/17] comments (#24617) --- .../shortcuts/constants/global_shortcuts.dart | 2 +- .../widgets/editor_textarea_wrapper.dart | 2 +- .../lib/src/controllers/code_runner.dart | 5 ----- .../src/controllers/playground_controller.dart | 2 +- .../lib/src/widgets/output/output_area.dart | 16 +++++++++------- .../lib/src/widgets/output/output_tab.dart | 10 ++++++---- .../lib/src/widgets/output/output_tabs.dart | 5 +++-- .../lib/src/widgets/run_button.dart | 6 ++++-- .../controllers/playground_controller_test.dart | 2 +- 9 files changed, 26 insertions(+), 24 deletions(-) diff --git a/playground/frontend/lib/modules/shortcuts/constants/global_shortcuts.dart b/playground/frontend/lib/modules/shortcuts/constants/global_shortcuts.dart index ab9b195cdd5b..006872717734 100644 --- a/playground/frontend/lib/modules/shortcuts/constants/global_shortcuts.dart +++ b/playground/frontend/lib/modules/shortcuts/constants/global_shortcuts.dart @@ -40,7 +40,7 @@ final kClearOutputShortcut = BeamShortcut( onInvoke: (_) => Provider.of( context, listen: false, - ).codeRunner.clearOutput(), + ).codeRunner.clearResult(), ), ); diff --git a/playground/frontend/lib/pages/standalone_playground/widgets/editor_textarea_wrapper.dart b/playground/frontend/lib/pages/standalone_playground/widgets/editor_textarea_wrapper.dart index cc2cf90fcc2d..c6ebfe7f6c36 100644 --- a/playground/frontend/lib/pages/standalone_playground/widgets/editor_textarea_wrapper.dart +++ b/playground/frontend/lib/pages/standalone_playground/widgets/editor_textarea_wrapper.dart @@ -114,6 +114,6 @@ class CodeTextAreaWrapper extends StatelessWidget { type: ToastType.error, ), ); - controller.resetError(); + controller.resetErrorMessageText(); } } diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index 1a373e011165..8fe0f82f6a75 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -99,11 +99,6 @@ class CodeRunner extends ChangeNotifier { } } - void clearOutput() { - _result = null; - notifyListeners(); - } - /// Resets the error message text so that on the next rebuild /// of `CodeTextAreaWrapper` it is not picked up and not shown as a toast. // TODO: Listen to this object outside of widgets, diff --git a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart index e1d493e5ff33..006112fa3fbb 100644 --- a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart +++ b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart @@ -229,7 +229,7 @@ class PlaygroundController with ChangeNotifier { } void resetErrorMessageText() { - codeRunner.setResultAfterResetError(); + codeRunner.resetErrorMessageText(); } void setPipelineOptions(String options) { diff --git a/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart b/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart index 77b0fdbd0b60..d0ac762f858a 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/output_area.dart @@ -17,8 +17,9 @@ */ import 'package:flutter/material.dart'; -import '../../../playground_components.dart'; +import '../../controllers/playground_controller.dart'; +import '../../models/outputs.dart'; import 'graph/graph.dart'; import 'output_result.dart'; @@ -37,13 +38,14 @@ class OutputArea extends StatelessWidget { String _getResultOutput() { final outputType = playgroundController.outputTypeController.outputFilterType; - if (outputType == OutputType.log) { - return playgroundController.codeRunner.resultLog; + switch (outputType) { + case OutputType.log: + return playgroundController.codeRunner.resultLog; + case OutputType.output: + return playgroundController.codeRunner.resultOutput; + case OutputType.all: + return playgroundController.codeRunner.resultLogOutput; } - if (outputType == OutputType.output) { - return playgroundController.codeRunner.resultOutput; - } - return playgroundController.codeRunner.resultLogOutput; } @override diff --git a/playground/frontend/playground_components/lib/src/widgets/output/output_tab.dart b/playground/frontend/playground_components/lib/src/widgets/output/output_tab.dart index 326b1c72448f..2fb40e9ecd1a 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/output_tab.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/output_tab.dart @@ -27,7 +27,9 @@ class OutputTab extends StatefulWidget { final PlaygroundController playgroundController; final String name; final bool isSelected; - final String value; + + /// Used to check if an update marker should be added on the tab + final String maxPossibleContent; final bool hasFilter; const OutputTab({ @@ -35,7 +37,7 @@ class OutputTab extends StatefulWidget { required this.playgroundController, required this.name, required this.isSelected, - required this.value, + required this.maxPossibleContent, this.hasFilter = false, }); @@ -53,8 +55,8 @@ class _OutputTabState extends State { hasNewContent = false; }); } else if (!widget.isSelected && - widget.value.isNotEmpty && - oldWidget.value != widget.value) { + widget.maxPossibleContent.isNotEmpty && + oldWidget.maxPossibleContent != widget.maxPossibleContent) { setState(() { hasNewContent = true; }); diff --git a/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart b/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart index caf8d80180ed..f36a6389fc23 100644 --- a/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart +++ b/playground/frontend/playground_components/lib/src/widgets/output/output_tabs.dart @@ -43,7 +43,7 @@ class OutputTabs extends StatelessWidget { playgroundController: playgroundController, name: 'widgets.output.result'.tr(), isSelected: tabController.index == 0, - value: playgroundController.codeRunner.resultLogOutput, + maxPossibleContent: playgroundController.codeRunner.resultLogOutput, hasFilter: true, ), if (playgroundController.graphAvailable) @@ -51,7 +51,8 @@ class OutputTabs extends StatelessWidget { playgroundController: playgroundController, name: 'widgets.output.graph'.tr(), isSelected: tabController.index == 2, - value: playgroundController.codeRunner.result?.graph ?? '', + maxPossibleContent: + playgroundController.codeRunner.result?.graph ?? '', ), ], ), diff --git a/playground/frontend/playground_components/lib/src/widgets/run_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_button.dart index d6326de6d0af..c3cdaea4553b 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_button.dart @@ -72,6 +72,8 @@ class RunButton extends StatelessWidget { ) : const Icon(Icons.play_arrow), label: isRunning + // TODO(nausharipov): fix bug + // It is also rebuilt on every codeRunner notification ? PeriodicBuilderWidget( interval: const Duration( milliseconds: _buttonTextRebuildInterval, @@ -114,7 +116,7 @@ class _ButtonText extends StatelessWidget { }); static const _msToSec = 1000; - static const _secondsFractions = 1; + static const _secondsFractionDigits = 1; @override Widget build(BuildContext context) { @@ -129,7 +131,7 @@ class _ButtonText extends StatelessWidget { if (elapsedDuration.inMilliseconds > 0) { final seconds = elapsedDuration.inMilliseconds / _msToSec; return Text( - '$buttonText (${seconds.toStringAsFixed(_secondsFractions)} s)', + '$buttonText (${seconds.toStringAsFixed(_secondsFractionDigits)} s)', ); } return Text(buttonText); 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 787603b3a606..e4aa78f1725d 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 @@ -152,7 +152,7 @@ Future main() async { test( 'If Playground state result is empty, then resetError should break the execution', () { - controller.resetError(); + controller.resetErrorMessageText(); expect(controller.codeRunner.result, null); }, ); From ac2c66fdcab0b9c03c105a320263a4e4f17a3a87 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Wed, 4 Jan 2023 15:31:32 +0600 Subject: [PATCH 11/17] missing license (#24617) --- .../lib/src/widgets/periodic_builder.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/playground/frontend/playground_components/lib/src/widgets/periodic_builder.dart b/playground/frontend/playground_components/lib/src/widgets/periodic_builder.dart index 55317a5c7ded..aed7d8c21b8e 100644 --- a/playground/frontend/playground_components/lib/src/widgets/periodic_builder.dart +++ b/playground/frontend/playground_components/lib/src/widgets/periodic_builder.dart @@ -1,3 +1,21 @@ +/* + * 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:flutter/material.dart'; From b716fa496555b4c4daf756398ac26db5dbfbb0d5 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Mon, 9 Jan 2023 12:44:55 +0600 Subject: [PATCH 12/17] a commit for re-running rat check on github --- .../playground_components/lib/src/controllers/code_runner.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index 8fe0f82f6a75..5d558255a88f 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -16,6 +16,8 @@ * limitations under the License. */ +// a commit for re-running rat check on github + import 'dart:async'; import 'package:flutter/material.dart'; From 97837afbde0fc96a48b57f406f4c3c571ab75621 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Mon, 9 Jan 2023 12:45:30 +0600 Subject: [PATCH 13/17] deleted comment "a commit for re-running rat check on github" --- .../playground_components/lib/src/controllers/code_runner.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index 5d558255a88f..8fe0f82f6a75 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -16,8 +16,6 @@ * limitations under the License. */ -// a commit for re-running rat check on github - import 'dart:async'; import 'package:flutter/material.dart'; From f46a09310506aa31cc611a8e86955848a27e5684 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Mon, 9 Jan 2023 20:31:03 +0600 Subject: [PATCH 14/17] fixes after merge with master (#24617) --- .../pages/tour/widgets/playground_demo.dart | 1 - .../assets/symbols/go.g.yaml | 82 +++- .../assets/symbols/java.g.yaml | 357 ++++++++++++++++-- .../assets/symbols/python.g.yaml | 36 +- .../lib/src/controllers/code_runner.dart | 1 + .../examples_loader_test.mocks.dart | 246 ++++++------ 6 files changed, 540 insertions(+), 183 deletions(-) diff --git a/learning/tour-of-beam/frontend/lib/pages/tour/widgets/playground_demo.dart b/learning/tour-of-beam/frontend/lib/pages/tour/widgets/playground_demo.dart index 4b5347a24810..c8016a120caf 100644 --- a/learning/tour-of-beam/frontend/lib/pages/tour/widgets/playground_demo.dart +++ b/learning/tour-of-beam/frontend/lib/pages/tour/widgets/playground_demo.dart @@ -48,7 +48,6 @@ class PlaygroundDemoWidget extends StatelessWidget { first: SnippetEditor( controller: snippetController, isEditable: true, - goToContextLine: false, ), second: OutputWidget( playgroundController: playgroundController, diff --git a/playground/frontend/playground_components/assets/symbols/go.g.yaml b/playground/frontend/playground_components/assets/symbols/go.g.yaml index 4df541c1a86e..bcc281716f1d 100644 --- a/playground/frontend/playground_components/assets/symbols/go.g.yaml +++ b/playground/frontend/playground_components/assets/symbols/go.g.yaml @@ -242,6 +242,7 @@ - Fatalf - Fatalln - FetchSize + - FieldIndexByTag - File - Flatten - FreeDiskSpace @@ -348,6 +349,7 @@ - ImpulseValue - InboundTagToNode - Include + - InferFieldNames - Info - Infof - Infoln @@ -751,6 +753,7 @@ - SkipK - SkipPtr - SkipW + - SklearnModel - Smallest - SmallestPerKey - Source @@ -887,11 +890,18 @@ - Warnf - Warnln - WindowInto + - WithArgs - WithContext - WithContextf - WithExpansionAddr + - WithExtraPackages - WithIndexes - WithQueryLocation + - WithReadBucketAuto + - WithReadBundleSize + - WithReadFilter + - WithWriteBatchSize + - WithWriteOrdered - Wrap - WrapIterable - WrapMethods @@ -1749,6 +1759,25 @@ Discard: - Up properties: - UID +DiscoverSchemaTransformRequest: + methods: + - Descriptor + - ProtoMessage + - ProtoReflect + - Reset + - String +DiscoverSchemaTransformResponse: + methods: + - Descriptor + - GetError + - GetSchemaTransformConfigs + - ProtoMessage + - ProtoReflect + - Reset + - String + properties: + - Error + - SchemaTransformConfigs DisplayData: methods: - Descriptor @@ -2173,6 +2202,7 @@ ExpansionResponse: - Transform ExpansionServiceClient: methods: + - DiscoverSchemaTransform - Expand ExpansionServiceRunner: methods: @@ -2182,6 +2212,7 @@ ExpansionServiceRunner: - String ExpansionServiceServer: methods: + - DiscoverSchemaTransform - Expand ExternalConfigurationPayload: methods: @@ -3195,6 +3226,7 @@ JobOptions: - Region - RetainDocker - ServiceAccountEmail + - Streaming - Subnetwork - TeardownPolicy - TempLocation @@ -3203,7 +3235,6 @@ JobOptions: - Update - Worker - WorkerHarnessThreads - - WorkerJar - WorkerRegion - WorkerZone - Zone @@ -4237,6 +4268,10 @@ PlanSnapshot: Port: properties: - URL +PredictionResult: + properties: + - Example + - Inference PrepareJobRequest: methods: - Descriptor @@ -4694,6 +4729,11 @@ ReadModifyWriteStateSpec: - String properties: - CoderId +ReadOption: + properties: + - BucketAuto + - BundleSize + - Filter ReadOptions: properties: - IDAttribute @@ -4947,6 +4987,34 @@ SchemaProvider: - BuildDecoder - BuildEncoder - FromLogicalType +SchemaTransformConfig: + methods: + - Descriptor + - GetConfigSchema + - GetInputPcollectionNames + - GetOutputPcollectionNames + - ProtoMessage + - ProtoReflect + - Reset + - String + properties: + - ConfigSchema + - InputPcollectionNames + - OutputPcollectionNames +SchemaTransformPayload: + methods: + - Descriptor + - GetConfigurationRow + - GetConfigurationSchema + - GetIdentifier + - ProtoMessage + - ProtoReflect + - Reset + - String + properties: + - ConfigurationRow + - ConfigurationSchema + - Identifier Scope: methods: - ID @@ -5153,6 +5221,7 @@ SplitResult: - RI - RS - TId + - Unsuccessful SplittableDoFn: methods: - CreateInitialRestrictionFn @@ -6304,7 +6373,6 @@ TypeMismatchError: - Error properties: - Got -U: {} UnimplementedArtifactRetrievalServiceServer: methods: - GetArtifact @@ -6334,6 +6402,7 @@ UnimplementedBeamFnWorkerStatusServer: - WorkerStatus UnimplementedExpansionServiceServer: methods: + - DiscoverSchemaTransform - Expand UnimplementedJobServiceServer: methods: @@ -6397,7 +6466,6 @@ UserFn: UserStateAdapter: methods: - NewStateProvider -V: {} Value: methods: - Clear @@ -6409,7 +6477,6 @@ Value: - Write properties: - Key -W: {} WallTimeWatermarkEstimator: methods: - CurrentWatermark @@ -6560,9 +6627,10 @@ WriteFilesPayload: - SideInputs - Sink - WindowedWrites +WriteOption: + properties: + - BatchSize + - Ordered Writer: methods: - SaveData -X: {} -"Y": {} -Z: {} diff --git a/playground/frontend/playground_components/assets/symbols/java.g.yaml b/playground/frontend/playground_components/assets/symbols/java.g.yaml index 1fe009d43672..557799d17369 100644 --- a/playground/frontend/playground_components/assets/symbols/java.g.yaml +++ b/playground/frontend/playground_components/assets/symbols/java.g.yaml @@ -474,6 +474,7 @@ AvroIO: - withSchema - withShardNameTemplate - withSuffix + - withSyncInterval - withTempDirectory - withUsesReshuffle - withWindowedWrites @@ -683,9 +684,11 @@ BatchContextImpl: methods: - addProperties - addTags + - asMap - createDataset - datasetExists - discardDataset + - get - getArguments - getDataset - getFailureCollector @@ -703,6 +706,8 @@ BatchContextImpl: - getPluginProperties - getServiceURL - getStageName + - has + - iterator - loadPluginClass - newPluginInstance - provide @@ -711,6 +716,10 @@ BatchContextImpl: - removeMetadata - removeProperties - removeTags + - set + properties: + - DEFAULT_SCHEMA_FIELD_NAME + - DEFAULT_SCHEMA_RECORD_NAME BatchSinkContextImpl: methods: - addOutput @@ -1328,11 +1337,13 @@ BeamSqlPipelineOptionsRegistrar: - getPipelineOptions BeamSqlRelUtils: methods: + - explainLazily - getBeamRelInput - getErrorRowSchema - getInput - getNodeStats - toPCollection + - toString properties: - ERROR - ROW @@ -1600,7 +1611,6 @@ BigQueryDirectReadSchemaTransformProvider: - buildTransform - builder - expand - - getBigQueryServices - getQuery - getRowRestriction - getSelectedFields @@ -1791,6 +1801,27 @@ BigQueryStorageTableSource: - create - getEstimatedSizeBytes - populateDisplayData +BigQueryStorageWriteApiSchemaTransformProvider: + methods: + - build + - buildTransform + - builder + - expand + - getCreateDisposition + - getTable + - getTriggeringFrequencySeconds + - getUseAtLeastOnceSemantics + - getWriteDisposition + - identifier + - inputCollectionNames + - outputCollectionNames + - setBigQueryServices + - setCreateDisposition + - setTable + - setTriggeringFrequencySeconds + - setUseAtLeastOnceSemantics + - setWriteDisposition + - validate BigQueryTableProvider: methods: - buildBeamSqlTable @@ -1935,6 +1966,7 @@ BlockBasedSource: - getCurrentRecord - getFractionConsumed - getFractionOfBlockConsumed + - isAtSplitPoint - readNextBlock - readNextRecord BlockingCommitterImpl: @@ -2533,6 +2565,8 @@ CdapIO: - withKeyClass - withLocksDirPath - withPluginConfig + - withPullFrequencySec + - withStartOffset - withValueClass - write ChangeStreamDao: @@ -3584,10 +3618,34 @@ DebeziumIO: - withFormatFunction - withHostName - withMaxNumberOfRecords + - withMaxTimeToRun - withPassword - withPort - withSourceConnector - withUsername +DebeziumReadSchemaTransformProvider: + methods: + - build + - buildTransform + - builder + - expand + - getDatabase + - getDebeziumConnectionProperties + - getHost + - getPassword + - getPort + - getTable + - getUsername + - identifier + - inputCollectionNames + - outputCollectionNames + - setDatabase + - setDebeziumConnectionProperties + - setHost + - setPassword + - setPort + - setTable + - setUsername DebeziumTransformRegistrar: methods: - buildExternal @@ -3631,6 +3689,7 @@ DefaultBlobstoreClientBuilderFactory: - createBuilder DefaultFilenamePolicy: methods: + - constructName - decode - encode - equals @@ -3996,6 +4055,7 @@ DoFnSignatures: - usesBagState - usesBundleFinalizer - usesMapState + - usesMultimapState - usesOrderedListState - usesSetState - usesState @@ -4863,6 +4923,48 @@ FileSystems: - filteredExistingSrcs - resultDestinations - resultSources +FileWriteSchemaTransformConfiguration: + methods: + - build + - builder + - csvConfigurationBuilder + - getCharset + - getCompression + - getCompressionCodecName + - getCsvConfiguration + - getCsvFormat + - getFilenamePrefix + - getFilenameSuffix + - getFormat + - getNumShards + - getParquetConfiguration + - getPreamble + - getRootElement + - getRowGroupSize + - getShardNameTemplate + - getXmlConfiguration + - parquetConfigurationBuilder + - setCharset + - setCompression + - setCompressionCodecName + - setCsvConfiguration + - setCsvFormat + - setFilenamePrefix + - setFilenameSuffix + - setFormat + - setNumShards + - setParquetConfiguration + - setPreamble + - setRootElement + - setRowGroupSize + - setShardNameTemplate + - setXmlConfiguration + - xmlConfigurationBuilder +FileWriteSchemaTransformFormatProviders: + methods: + - buildTransform + - identifier + - loadProviders FillGaps: methods: - expand @@ -5113,6 +5215,7 @@ FnApiStateAccessor: - bindCombining - bindCombiningWithContext - bindMap + - bindMultimap - bindOrderedList - bindSet - bindValue @@ -5495,6 +5598,7 @@ GroupIntoBatches: methods: - apply - create + - createDefault - expand - getBatchSize - getBatchSizeBytes @@ -5509,8 +5613,11 @@ GroupIntoBatches: - onWindowExpiration - onWindowTimer - processElement + - toString + - withByteSize - withMaxBufferingDuration - withShardedKey + - withSize GrowableOffsetRangeTracker: methods: - getProgress @@ -6370,6 +6477,7 @@ JsonToRow: JsonUtils: methods: - apply + - beamSchemaFromJsonSchema - getJsonBytesToRowFunction - getJsonStringToRowFunction - getRowToJsonBytesFunction @@ -6400,6 +6508,12 @@ KafkaCommitOffset: methods: - expand - processElement +KafkaConnectUtils: + methods: + - beamRowFromSourceRecordFn + - beamSchemaFromKafkaConnectSchema + - beamSchemaTypeFromKafkaType + - mapSourceRecord KafkaIO: methods: - apply @@ -6490,58 +6604,58 @@ KafkaIO: - URN - URN_WITHOUT_METADATA - URN_WITH_METADATA -KafkaRecord: - methods: - - equals - - getHeaders - - getKV - - getOffset - - getPartition - - getTimestamp - - getTimestampType - - getTopic - - hashCode -KafkaRecordCoder: - methods: - - consistentWithEquals - - decode - - encode - - getCoderArguments - - isRegisterByteSizeObserverCheap - - of - - structuralValue - - verifyDeterministic -KafkaSchemaTransformReadConfiguration: +KafkaReadSchemaTransformConfiguration: methods: - build - builder - getAutoOffsetResetConfig - - getAvroSchema - getBootstrapServers - getConfluentSchemaRegistrySubject - getConfluentSchemaRegistryUrl - getConsumerConfigUpdates - getDataFormat + - getSchema - getTopic - setAutoOffsetResetConfig - - setAvroSchema - setBootstrapServers - setConfluentSchemaRegistrySubject - setConfluentSchemaRegistryUrl - setConsumerConfigUpdates - setDataFormat + - setSchema - setTopic - validate properties: - VALID_DATA_FORMATS - VALID_START_OFFSET_VALUES -KafkaSchemaTransformReadProvider: +KafkaReadSchemaTransformProvider: methods: - buildTransform - expand - identifier - inputCollectionNames - outputCollectionNames +KafkaRecord: + methods: + - equals + - getHeaders + - getKV + - getOffset + - getPartition + - getTimestamp + - getTimestampType + - getTopic + - hashCode +KafkaRecordCoder: + methods: + - consistentWithEquals + - decode + - encode + - getCoderArguments + - isRegisterByteSizeObserverCheap + - of + - structuralValue + - verifyDeterministic KafkaSourceConsumerFn: methods: - checkDone @@ -6566,7 +6680,7 @@ KafkaSourceConsumerFn: - fetchedRecords - history - maxRecords - - minutesToRun + - milisToRun - offset KafkaSourceDescriptor: methods: @@ -6576,6 +6690,25 @@ KafkaTableProvider: methods: - buildBeamSqlTable - getTableType +KafkaWriteSchemaTransformProvider: + methods: + - build + - buildTransform + - builder + - expand + - getBootstrapServers + - getFormat + - getProducerConfigUpdates + - getTopic + - identifier + - inputCollectionNames + - outputCollectionNames + - setBootstrapServers + - setFormat + - setProducerConfigUpdates + - setTopic + properties: + - SUPPORTED_FORMATS KeyPairUtils: methods: - preparePrivateKey @@ -6905,9 +7038,7 @@ MapperFactory: methods: - changeStreamRecordMapper - partitionMetadataMapper -MappingUtils: - methods: - - registerStreamingPlugin +MappingUtils: {} MatchResult: methods: - build @@ -7422,6 +7553,7 @@ Neo4jIO: - readAll - setup - startBundle + - tearDown - withBatchSize - withCoder - withConfig @@ -8070,6 +8202,7 @@ ParDo: - dispatchBag - dispatchCombining - dispatchMap + - dispatchMultimap - dispatchOrderedList - dispatchSet - dispatchValue @@ -8422,10 +8555,14 @@ Plugin: - getContext - getFormatClass - getFormatProviderClass + - getGetOffsetFn + - getGetReceiverArgsFromConfigFn - getHadoopConfiguration - getPluginClass - getPluginConfig - getPluginType + - getReceiverBuilder + - getReceiverClass - initContext - initPluginType - isUnbounded @@ -8433,8 +8570,11 @@ Plugin: - setContext - setFormatClass - setFormatProviderClass + - setGetOffsetFn + - setGetReceiverArgsFromConfigFn - setPluginClass - setPluginType + - setReceiverClass - withConfig - withHadoopConfiguration PluginConfigInstantiationUtils: {} @@ -8684,9 +8824,12 @@ PubsubClient: - ackDeadlineSeconds - ackId - acknowledge + - apply - createRandomSubscription + - createSchema - createSubscription - createTopic + - deleteSchema - deleteSubscription - deleteTopic - equals @@ -8694,6 +8837,9 @@ PubsubClient: - getId - getName - getPath + - getProjectId + - getSchema + - getSchemaPath - hashCode - isEOF - listSubscriptions @@ -8707,6 +8853,8 @@ PubsubClient: - pull - recordId - requestTimeMsSinceEpoch + - schemaPathFromId + - schemaPathFromPath - subscriptionPathFromName - subscriptionPathFromPath - timestampMsSinceEpoch @@ -8726,11 +8874,15 @@ PubsubGrpcClient: - ackDeadlineSeconds - acknowledge - close + - createSchema - createSubscription - createTopic + - deleteSchema - deleteSubscription - deleteTopic - getKind + - getSchema + - getSchemaPath - isEOF - listSubscriptions - listTopics @@ -8796,11 +8948,15 @@ PubsubJsonClient: - ackDeadlineSeconds - acknowledge - close + - createSchema - createSubscription - createTopic + - deleteSchema - deleteSubscription - deleteTopic - getKind + - getSchema + - getSchemaPath - isEOF - listSubscriptions - listTopics @@ -8817,6 +8973,26 @@ PubsubLiteIO: - expand - read - write +PubsubLiteReadSchemaTransformProvider: + methods: + - build + - buildTransform + - builder + - expand + - from + - getDataFormat + - getLocation + - getProject + - getSchema + - getSubscriptionName + - identifier + - inputCollectionNames + - outputCollectionNames + - setDataFormat + - setLocation + - setProject + - setSchema + - setSubscriptionName PubsubLiteSink: methods: - finishBundle @@ -8826,6 +9002,25 @@ PubsubLiteTableProvider: methods: - buildBeamSqlTable - getTableType +PubsubLiteWriteSchemaTransformProvider: + methods: + - build + - buildTransform + - builder + - expand + - getFormat + - getLocation + - getProject + - getTopicName + - identifier + - inputCollectionNames + - outputCollectionNames + - setFormat + - setLocation + - setProject + - setTopicName + properties: + - SUPPORTED_FORMATS PubsubMessage: methods: - equals @@ -8913,17 +9108,6 @@ PubsubSchemaTransformReadProvider: - inputCollectionNames - outputCollectionNames - validate -PubsubSchemaTransformWriteConfiguration: - methods: - - build - - getFormat - - getIdAttribute - - getTimestampAttribute - - getTopic - - setFormat - - setIdAttribute - - setTimestampAttribute - - setTopic PubsubTableProvider: methods: - getSchemaIOProvider @@ -8935,14 +9119,19 @@ PubsubTestClient: - advance - close - createFactoryForCreateSubscription + - createFactoryForGetSchema - createFactoryForPublish - createFactoryForPull - createFactoryForPullAndPublish + - createSchema - createSubscription - createTopic + - deleteSchema - deleteSubscription - deleteTopic - getKind + - getSchema + - getSchemaPath - isEOF - listSubscriptions - listTopics @@ -9006,6 +9195,40 @@ PubsubUnboundedSource: - validate properties: - outer +PubsubWriteSchemaTransformConfiguration: + methods: + - build + - builder + - getAttributesFieldName + - getFormat + - getIdAttribute + - getPayloadFieldName + - getSource + - getTarget + - getTimestampAttributeKey + - getTimestampFieldName + - getTopic + - setAttributesFieldName + - setFormat + - setIdAttribute + - setPayloadFieldName + - setSource + - setTarget + - setTimestampAttributeKey + - setTimestampFieldName + - setTopic + - sourceConfigurationBuilder + - targetConfigurationBuilder + properties: + - DEFAULT_TIMESTAMP_ATTRIBUTE +PubsubWriteSchemaTransformProvider: + methods: + - buildTransform + - expand + - identifier + - inputCollectionNames + - outputCollectionNames + - process PulsarIO: methods: - expand @@ -9330,6 +9553,8 @@ ReadAllViaFileBasedSource: - apply - expand - process + properties: + - DEFAULT_USES_RESHUFFLE ReadBuilder: methods: - buildExternal @@ -10180,6 +10405,7 @@ Schema: - setOptions - setType - setUUID + - sorted - toBuilder - toSchema - toString @@ -10542,7 +10768,9 @@ SingleStoreIO: - process - processElement - read + - readRows - readWithPartitions + - readWithPartitionsRows - run - splitRange - withBatchSize @@ -10558,6 +10786,49 @@ SingleStoreIO: - withUserDataMapper - withUsername - write + - writeRows +SingleStoreSchemaTransformReadConfiguration: + methods: + - build + - builder + - getDataSourceConfiguration + - getOutputParallelization + - getQuery + - getTable + - getWithPartitions + - setDataSourceConfiguration + - setOutputParallelization + - setQuery + - setTable + - setWithPartitions + - toBeamRow +SingleStoreSchemaTransformReadProvider: + methods: + - buildTransform + - expand + - identifier + - inputCollectionNames + - outputCollectionNames +SingleStoreSchemaTransformWriteConfiguration: + methods: + - build + - builder + - getBatchSize + - getDataSourceConfiguration + - getTable + - setBatchSize + - setDataSourceConfiguration + - setTable + - toBeamRow +SingleStoreSchemaTransformWriteProvider: + methods: + - buildTransform + - expand + - identifier + - inputCollectionNames + - outputCollectionNames + properties: + - INPUT_TAG SingleValueCollector: methods: - asContext @@ -11152,7 +11423,9 @@ SparkReceiverIO: - read - validateTransform - withGetOffsetFn + - withPullFrequencySec - withSparkReceiverBuilder + - withStartOffset - withTimestampFn Split: methods: @@ -11391,10 +11664,12 @@ StateSpecs: - hashCode - map - match + - multimap - offerCoders - orderedList - rowBag - rowMap + - rowMultimap - rowOrderedList - rowSet - rowValue diff --git a/playground/frontend/playground_components/assets/symbols/python.g.yaml b/playground/frontend/playground_components/assets/symbols/python.g.yaml index 01d5afbf2d89..a47447225a68 100644 --- a/playground/frontend/playground_components/assets/symbols/python.g.yaml +++ b/playground/frontend/playground_components/assets/symbols/python.g.yaml @@ -899,6 +899,9 @@ BigqueryMatcher: methods: - describe_mismatch - describe_to +BigQueryMetricsFetcher: + methods: + - fetch BigQueryMetricsPublisher: methods: - publish @@ -1273,6 +1276,7 @@ BlobStorageIO: - delete_tree - exists - last_updated + - list_files - list_prefix - open - rename @@ -4824,6 +4828,7 @@ GcsIO: - get_project_number - kms_key - last_updated + - list_files - list_prefix - open - rename @@ -4987,6 +4992,16 @@ GitHubEventsConfig: - owner - pullRequest - push +GitHubIssueMetaData: + properties: + - change_point + - change_point_timestamp + - issue_number + - issue_timestamp + - issue_url + - metric_name + - test_id + - test_name GitRepoSource: properties: - bitbucketServerConfig @@ -5795,10 +5810,6 @@ JoinIndex: JoinPersonAuctionFn: methods: - process -JrhReadPTransformOverride: - methods: - - get_replacement_transform_for_applied_ptransform - - matches JsonCoder: methods: - decode @@ -5832,6 +5843,7 @@ JustBids: JustPerson: methods: - expand +KafkaIOTestOptions: {} Key: methods: - from_client_key @@ -6332,6 +6344,7 @@ MetricsPublisher: - publish MetricsReader: methods: + - get_counter_metric - publish_metrics - publish_values MetricStructuredName: @@ -7877,6 +7890,7 @@ PythonCallable: - urn PythonCallableWithSource: methods: + - default_label - get_source - load_from_expression - load_from_fully_qualified_name @@ -8686,6 +8700,7 @@ S3IO: - delete_tree - exists - last_updated + - list_files - list_prefix - open - rename @@ -10294,6 +10309,18 @@ TestBQJobNames: - test_matches_template - test_random_in_name - test_simple_names +TestChangePointAnalysis: + methods: + - setUp + - test_alert_on_data_with_change_point + - test_alert_on_data_with_reported_change_point + - test_change_point_outside_inspection_window_is_not_a_valid_alert + - test_duplicate_change_point + - test_duplicate_change_points_are_not_valid_alerts + - test_edivisive_means + - test_is_changepoint_in_valid_window + - test_no_alerts_when_no_change_points + - test_validate_config TestCheckSchemaEqual: methods: - test_descriptions @@ -11356,6 +11383,7 @@ TriggerCopyJobs: - display_data - finish_bundle - process + - process_one - start_bundle properties: - TRIGGER_DELETE_TEMP_TABLES diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index 8fe0f82f6a75..2fd0e188eccb 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -82,6 +82,7 @@ class CodeRunner extends ChangeNotifier { code: snippetEditingController!.codeController.fullText, sdk: snippetEditingController!.sdk, pipelineOptions: parsedPipelineOptions, + datasets: snippetEditingController?.selectedExample?.datasets ?? [], ); _runSubscription = _codeRepository?.runCode(request).listen((event) { _result = event; diff --git a/playground/frontend/playground_components/test/src/controllers/example_loaders/examples_loader_test.mocks.dart b/playground/frontend/playground_components/test/src/controllers/example_loaders/examples_loader_test.mocks.dart index 4a122cbd7652..1c09938be30f 100644 --- a/playground/frontend/playground_components/test/src/controllers/example_loaders/examples_loader_test.mocks.dart +++ b/playground/frontend/playground_components/test/src/controllers/example_loaders/examples_loader_test.mocks.dart @@ -3,33 +3,35 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i13; -import 'dart:ui' as _i15; +import 'dart:async' as _i14; +import 'dart:ui' as _i16; import 'package:mockito/mockito.dart' as _i1; import 'package:playground_components/src/cache/example_cache.dart' as _i2; -import 'package:playground_components/src/controllers/code_runner.dart' as _i4; +import 'package:playground_components/src/controllers/code_runner.dart' as _i5; import 'package:playground_components/src/controllers/example_loaders/examples_loader.dart' as _i3; +import 'package:playground_components/src/controllers/output_filter_type_controller.dart' + as _i4; import 'package:playground_components/src/controllers/playground_controller.dart' - as _i11; + as _i12; import 'package:playground_components/src/controllers/snippet_editing_controller.dart' - as _i6; + as _i7; import 'package:playground_components/src/models/category_with_examples.dart' - as _i16; -import 'package:playground_components/src/models/example.dart' as _i10; -import 'package:playground_components/src/models/example_base.dart' as _i9; + as _i17; +import 'package:playground_components/src/models/example.dart' as _i11; +import 'package:playground_components/src/models/example_base.dart' as _i10; import 'package:playground_components/src/models/example_loading_descriptors/example_loading_descriptor.dart' - as _i14; + as _i15; import 'package:playground_components/src/models/example_loading_descriptors/examples_loading_descriptor.dart' - as _i8; + as _i9; import 'package:playground_components/src/models/example_loading_descriptors/user_shared_example_loading_descriptor.dart' - as _i7; -import 'package:playground_components/src/models/loading_status.dart' as _i17; -import 'package:playground_components/src/models/sdk.dart' as _i12; -import 'package:playground_components/src/models/shortcut.dart' as _i5; + as _i8; +import 'package:playground_components/src/models/loading_status.dart' as _i18; +import 'package:playground_components/src/models/sdk.dart' as _i13; +import 'package:playground_components/src/models/shortcut.dart' as _i6; import 'package:playground_components/src/repositories/models/shared_file.dart' - as _i18; + as _i19; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -45,28 +47,31 @@ class _FakeExampleCache_0 extends _i1.Fake implements _i2.ExampleCache {} class _FakeExamplesLoader_1 extends _i1.Fake implements _i3.ExamplesLoader {} -class _FakeCodeRunner_2 extends _i1.Fake implements _i4.CodeRunner {} +class _FakeOutputFilterTypeController_2 extends _i1.Fake + implements _i4.OutputFilterTypeController {} -class _FakeBeamShortcut_3 extends _i1.Fake implements _i5.BeamShortcut {} +class _FakeCodeRunner_3 extends _i1.Fake implements _i5.CodeRunner {} -class _FakeSnippetEditingController_4 extends _i1.Fake - implements _i6.SnippetEditingController {} +class _FakeBeamShortcut_4 extends _i1.Fake implements _i6.BeamShortcut {} -class _FakeUserSharedExampleLoadingDescriptor_5 extends _i1.Fake - implements _i7.UserSharedExampleLoadingDescriptor {} +class _FakeSnippetEditingController_5 extends _i1.Fake + implements _i7.SnippetEditingController {} -class _FakeExamplesLoadingDescriptor_6 extends _i1.Fake - implements _i8.ExamplesLoadingDescriptor {} +class _FakeUserSharedExampleLoadingDescriptor_6 extends _i1.Fake + implements _i8.UserSharedExampleLoadingDescriptor {} -class _FakeExampleBase_7 extends _i1.Fake implements _i9.ExampleBase {} +class _FakeExamplesLoadingDescriptor_7 extends _i1.Fake + implements _i9.ExamplesLoadingDescriptor {} -class _FakeExample_8 extends _i1.Fake implements _i10.Example {} +class _FakeExampleBase_8 extends _i1.Fake implements _i10.ExampleBase {} + +class _FakeExample_9 extends _i1.Fake implements _i11.Example {} /// A class which mocks [PlaygroundController]. /// /// See the documentation for Mockito's code generation for more information. class MockPlaygroundController extends _i1.Mock - implements _i11.PlaygroundController { + implements _i12.PlaygroundController { MockPlaygroundController() { _i1.throwOnMissingStub(this); } @@ -82,12 +87,18 @@ class MockPlaygroundController extends _i1.Mock returnValue: _FakeExamplesLoader_1(), ) as _i3.ExamplesLoader); @override - _i4.CodeRunner get codeRunner => (super.noSuchMethod( + _i4.OutputFilterTypeController get outputTypeController => + (super.noSuchMethod( + Invocation.getter(#outputTypeController), + returnValue: _FakeOutputFilterTypeController_2(), + ) as _i4.OutputFilterTypeController); + @override + _i5.CodeRunner get codeRunner => (super.noSuchMethod( Invocation.getter(#codeRunner), - returnValue: _FakeCodeRunner_2(), - ) as _i4.CodeRunner); + returnValue: _FakeCodeRunner_3(), + ) as _i5.CodeRunner); @override - set codeRunner(_i4.CodeRunner? _codeRunner) => super.noSuchMethod( + set codeRunner(_i5.CodeRunner? _codeRunner) => super.noSuchMethod( Invocation.setter( #codeRunner, _codeRunner, @@ -95,12 +106,12 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - _i5.BeamShortcut get runShortcut => (super.noSuchMethod( + _i6.BeamShortcut get runShortcut => (super.noSuchMethod( Invocation.getter(#runShortcut), - returnValue: _FakeBeamShortcut_3(), - ) as _i5.BeamShortcut); + returnValue: _FakeBeamShortcut_4(), + ) as _i6.BeamShortcut); @override - set runShortcut(_i5.BeamShortcut? _runShortcut) => super.noSuchMethod( + set runShortcut(_i6.BeamShortcut? _runShortcut) => super.noSuchMethod( Invocation.setter( #runShortcut, _runShortcut, @@ -108,12 +119,12 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - _i5.BeamShortcut get resetShortcut => (super.noSuchMethod( + _i6.BeamShortcut get resetShortcut => (super.noSuchMethod( Invocation.getter(#resetShortcut), - returnValue: _FakeBeamShortcut_3(), - ) as _i5.BeamShortcut); + returnValue: _FakeBeamShortcut_4(), + ) as _i6.BeamShortcut); @override - set resetShortcut(_i5.BeamShortcut? _resetShortcut) => super.noSuchMethod( + set resetShortcut(_i6.BeamShortcut? _resetShortcut) => super.noSuchMethod( Invocation.setter( #resetShortcut, _resetShortcut, @@ -136,26 +147,26 @@ class MockPlaygroundController extends _i1.Mock returnValue: false, ) as bool); @override - List<_i5.BeamShortcut> get shortcuts => (super.noSuchMethod( + List<_i6.BeamShortcut> get shortcuts => (super.noSuchMethod( Invocation.getter(#shortcuts), - returnValue: <_i5.BeamShortcut>[], - ) as List<_i5.BeamShortcut>); + returnValue: <_i6.BeamShortcut>[], + ) as List<_i6.BeamShortcut>); @override bool get hasListeners => (super.noSuchMethod( Invocation.getter(#hasListeners), returnValue: false, ) as bool); @override - _i6.SnippetEditingController requireSnippetEditingController() => + _i7.SnippetEditingController requireSnippetEditingController() => (super.noSuchMethod( Invocation.method( #requireSnippetEditingController, [], ), - returnValue: _FakeSnippetEditingController_4(), - ) as _i6.SnippetEditingController); + returnValue: _FakeSnippetEditingController_5(), + ) as _i7.SnippetEditingController); @override - void setEmptyIfNoSdk(_i12.Sdk? sdk) => super.noSuchMethod( + void setEmptyIfNoSdk(_i13.Sdk? sdk) => super.noSuchMethod( Invocation.method( #setEmptyIfNoSdk, [sdk], @@ -164,7 +175,7 @@ class MockPlaygroundController extends _i1.Mock ); @override void setEmptyIfNotExists( - _i12.Sdk? sdk, { + _i13.Sdk? sdk, { bool? setCurrentSdk, }) => super.noSuchMethod( @@ -176,7 +187,7 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - _i13.Future setExampleBase(_i8.ExampleBase? exampleBase) => + _i14.Future setExampleBase(_i10.ExampleBase? exampleBase) => (super.noSuchMethod( Invocation.method( #setExampleBase, @@ -184,11 +195,11 @@ class MockPlaygroundController extends _i1.Mock ), returnValue: Future.value(), returnValueForMissingStub: Future.value(), - ) as _i13.Future); + ) as _i14.Future); @override void setExample( - _i9.Example? example, { - _i14.ExampleLoadingDescriptor? descriptor, + _i11.Example? example, { + _i15.ExampleLoadingDescriptor? descriptor, bool? setCurrentSdk, }) => super.noSuchMethod( @@ -204,7 +215,7 @@ class MockPlaygroundController extends _i1.Mock ); @override void setSdk( - _i12.Sdk? sdk, { + _i13.Sdk? sdk, { bool? notify = true, }) => super.noSuchMethod( @@ -233,9 +244,9 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: Future.value(), ) as _i14.Future); @override - void resetError() => super.noSuchMethod( + void resetErrorMessageText() => super.noSuchMethod( Invocation.method( - #resetError, + #resetErrorMessageText, [], ), returnValueForMissingStub: null, @@ -249,49 +260,23 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - void runCode({void Function()? onFinish}) => super.noSuchMethod( - Invocation.method( - #runCode, - [], - {#onFinish: onFinish}, - ), - returnValueForMissingStub: null, - ); - @override - _i13.Future cancelRun() => (super.noSuchMethod( - Invocation.method( - #cancelRun, - [], - ), - returnValue: Future.value(), - returnValueForMissingStub: Future.value(), - ) as _i13.Future); - @override - void filterOutput(_i11.OutputType? type) => super.noSuchMethod( - Invocation.method( - #filterOutput, - [type], - ), - returnValueForMissingStub: null, - ); - @override - _i13.Future<_i6.UserSharedExampleLoadingDescriptor> saveSnippet() => + _i14.Future<_i8.UserSharedExampleLoadingDescriptor> saveSnippet() => (super.noSuchMethod( Invocation.method( #saveSnippet, [], ), - returnValue: Future<_i6.UserSharedExampleLoadingDescriptor>.value( - _FakeUserSharedExampleLoadingDescriptor_4()), - ) as _i13.Future<_i6.UserSharedExampleLoadingDescriptor>); + returnValue: Future<_i8.UserSharedExampleLoadingDescriptor>.value( + _FakeUserSharedExampleLoadingDescriptor_6()), + ) as _i14.Future<_i8.UserSharedExampleLoadingDescriptor>); @override - _i8.ExamplesLoadingDescriptor getLoadingDescriptor() => (super.noSuchMethod( + _i9.ExamplesLoadingDescriptor getLoadingDescriptor() => (super.noSuchMethod( Invocation.method( #getLoadingDescriptor, [], ), - returnValue: _FakeExamplesLoadingDescriptor_6(), - ) as _i8.ExamplesLoadingDescriptor); + returnValue: _FakeExamplesLoadingDescriptor_7(), + ) as _i9.ExamplesLoadingDescriptor); @override void dispose() => super.noSuchMethod( Invocation.method( @@ -301,7 +286,7 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i16.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -309,7 +294,7 @@ class MockPlaygroundController extends _i1.Mock returnValueForMissingStub: null, ); @override - void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i16.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], @@ -335,16 +320,16 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { } @override - Map<_i12.Sdk, List<_i16.CategoryWithExamples>> get categoryListsBySdk => + Map<_i13.Sdk, List<_i17.CategoryWithExamples>> get categoryListsBySdk => (super.noSuchMethod( Invocation.getter(#categoryListsBySdk), - returnValue: <_i12.Sdk, List<_i16.CategoryWithExamples>>{}, - ) as Map<_i12.Sdk, List<_i16.CategoryWithExamples>>); + returnValue: <_i13.Sdk, List<_i17.CategoryWithExamples>>{}, + ) as Map<_i13.Sdk, List<_i17.CategoryWithExamples>>); @override - Map<_i12.Sdk, _i10.Example> get defaultExamplesBySdk => (super.noSuchMethod( + Map<_i13.Sdk, _i11.Example> get defaultExamplesBySdk => (super.noSuchMethod( Invocation.getter(#defaultExamplesBySdk), - returnValue: <_i12.Sdk, _i10.Example>{}, - ) as Map<_i12.Sdk, _i10.Example>); + returnValue: <_i13.Sdk, _i11.Example>{}, + ) as Map<_i13.Sdk, _i11.Example>); @override bool get isSelectorOpened => (super.noSuchMethod( Invocation.getter(#isSelectorOpened), @@ -359,42 +344,42 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { returnValueForMissingStub: null, ); @override - _i13.Future get allExamplesFuture => (super.noSuchMethod( + _i14.Future get allExamplesFuture => (super.noSuchMethod( Invocation.getter(#allExamplesFuture), returnValue: Future.value(), - ) as _i13.Future); + ) as _i14.Future); @override - _i17.LoadingStatus get catalogStatus => (super.noSuchMethod( + _i18.LoadingStatus get catalogStatus => (super.noSuchMethod( Invocation.getter(#catalogStatus), - returnValue: _i17.LoadingStatus.loading, - ) as _i17.LoadingStatus); + returnValue: _i18.LoadingStatus.loading, + ) as _i18.LoadingStatus); @override bool get hasListeners => (super.noSuchMethod( Invocation.getter(#hasListeners), returnValue: false, ) as bool); @override - _i13.Future loadAllPrecompiledObjectsIfNot() => (super.noSuchMethod( + _i14.Future loadAllPrecompiledObjectsIfNot() => (super.noSuchMethod( Invocation.method( #loadAllPrecompiledObjectsIfNot, [], ), returnValue: Future.value(), returnValueForMissingStub: Future.value(), - ) as _i13.Future); + ) as _i14.Future); @override - List<_i16.CategoryWithExamples> getCategories(_i12.Sdk? sdk) => + List<_i17.CategoryWithExamples> getCategories(_i13.Sdk? sdk) => (super.noSuchMethod( Invocation.method( #getCategories, [sdk], ), - returnValue: <_i16.CategoryWithExamples>[], - ) as List<_i16.CategoryWithExamples>); + returnValue: <_i17.CategoryWithExamples>[], + ) as List<_i17.CategoryWithExamples>); @override - _i13.Future<_i8.ExampleBase> getPrecompiledObject( + _i14.Future<_i10.ExampleBase> getPrecompiledObject( String? path, - _i12.Sdk? sdk, + _i13.Sdk? sdk, ) => (super.noSuchMethod( Invocation.method( @@ -404,20 +389,21 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { sdk, ], ), - returnValue: Future<_i8.ExampleBase>.value(_FakeExampleBase_6()), - ) as _i13.Future<_i8.ExampleBase>); + returnValue: Future<_i10.ExampleBase>.value(_FakeExampleBase_8()), + ) as _i14.Future<_i10.ExampleBase>); @override - _i13.Future<_i9.Example> loadSharedExample(String? id) => (super.noSuchMethod( + _i14.Future<_i11.Example> loadSharedExample(String? id) => + (super.noSuchMethod( Invocation.method( #loadSharedExample, [id], ), - returnValue: Future<_i9.Example>.value(_FakeExample_7()), - ) as _i13.Future<_i9.Example>); + returnValue: Future<_i11.Example>.value(_FakeExample_9()), + ) as _i14.Future<_i11.Example>); @override - _i13.Future saveSnippet({ - List<_i18.SharedFile>? files, - _i12.Sdk? sdk, + _i14.Future saveSnippet({ + List<_i19.SharedFile>? files, + _i13.Sdk? sdk, String? pipelineOptions, }) => (super.noSuchMethod( @@ -431,16 +417,16 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { }, ), returnValue: Future.value(''), - ) as _i13.Future); + ) as _i14.Future); @override - _i13.Future<_i9.Example> loadExampleInfo(_i8.ExampleBase? example) => + _i14.Future<_i11.Example> loadExampleInfo(_i10.ExampleBase? example) => (super.noSuchMethod( Invocation.method( #loadExampleInfo, [example], ), - returnValue: Future<_i9.Example>.value(_FakeExample_7()), - ) as _i13.Future<_i9.Example>); + returnValue: Future<_i11.Example>.value(_FakeExample_9()), + ) as _i14.Future<_i11.Example>); @override void setSelectorOpened(bool? value) => super.noSuchMethod( Invocation.method( @@ -450,43 +436,43 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { returnValueForMissingStub: null, ); @override - _i13.Future<_i9.Example?> getDefaultExampleBySdk(_i12.Sdk? sdk) => + _i14.Future<_i11.Example?> getDefaultExampleBySdk(_i13.Sdk? sdk) => (super.noSuchMethod( Invocation.method( #getDefaultExampleBySdk, [sdk], ), - returnValue: Future<_i9.Example?>.value(), - ) as _i13.Future<_i9.Example?>); + returnValue: Future<_i11.Example?>.value(), + ) as _i14.Future<_i11.Example?>); @override - _i13.Future loadDefaultPrecompiledObjects() => (super.noSuchMethod( + _i14.Future loadDefaultPrecompiledObjects() => (super.noSuchMethod( Invocation.method( #loadDefaultPrecompiledObjects, [], ), returnValue: Future.value(), returnValueForMissingStub: Future.value(), - ) as _i13.Future); + ) as _i14.Future); @override - _i13.Future loadDefaultPrecompiledObjectsIfNot() => (super.noSuchMethod( + _i14.Future loadDefaultPrecompiledObjectsIfNot() => (super.noSuchMethod( Invocation.method( #loadDefaultPrecompiledObjectsIfNot, [], ), returnValue: Future.value(), returnValueForMissingStub: Future.value(), - ) as _i13.Future); + ) as _i14.Future); @override - _i13.Future<_i8.ExampleBase?> getCatalogExampleByPath(String? path) => + _i14.Future<_i10.ExampleBase?> getCatalogExampleByPath(String? path) => (super.noSuchMethod( Invocation.method( #getCatalogExampleByPath, [path], ), - returnValue: Future<_i8.ExampleBase?>.value(), - ) as _i13.Future<_i8.ExampleBase?>); + returnValue: Future<_i10.ExampleBase?>.value(), + ) as _i14.Future<_i10.ExampleBase?>); @override - void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i16.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -494,7 +480,7 @@ class MockExampleCache extends _i1.Mock implements _i2.ExampleCache { returnValueForMissingStub: null, ); @override - void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i16.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], From 56ea583c89b589c655f89a86403a17e455a3ab8c Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Mon, 16 Jan 2023 12:28:33 +0600 Subject: [PATCH 15/17] merge fixes (#24617) --- playground/frontend/lib/utils/analytics_utils.dart | 2 +- .../lib/src/controllers/code_runner.dart | 14 +++++++++----- .../controllers/playground_controller_test.dart | 8 ++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/playground/frontend/lib/utils/analytics_utils.dart b/playground/frontend/lib/utils/analytics_utils.dart index 786b54ff382f..b5c2ba0dc354 100644 --- a/playground/frontend/lib/utils/analytics_utils.dart +++ b/playground/frontend/lib/utils/analytics_utils.dart @@ -20,7 +20,7 @@ import 'package:playground_components/playground_components.dart'; String getAnalyticsExampleName(PlaygroundController controller) { final customCodeName = 'Custom code, sdk ${controller.sdk?.title}'; - if (controller.isExampleChanged) { + if (controller.codeRunner.isExampleChanged) { return customCodeName; } return controller.selectedExample?.path ?? customCodeName; diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index 2fd0e188eccb..e918951fefb6 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -51,6 +51,10 @@ class CodeRunner extends ChangeNotifier { String get resultOutput => _result?.output ?? ''; String get resultLogOutput => resultLog + resultOutput; + bool get isExampleChanged { + return snippetEditingController?.isChanged ?? false; + } + void clearResult() { _result = null; notifyListeners(); @@ -74,15 +78,15 @@ class CodeRunner extends ChangeNotifier { return; } - if (!snippetEditingController!.isChanged && - snippetEditingController!.selectedExample?.outputs != null) { + if (!isExampleChanged && + snippetEditingController!.example?.outputs != null) { unawaited(_showPrecompiledResult()); } else { final request = RunCodeRequest( - code: snippetEditingController!.codeController.fullText, + datasets: snippetEditingController?.example?.datasets ?? [], + files: snippetEditingController!.getFiles(), sdk: snippetEditingController!.sdk, pipelineOptions: parsedPipelineOptions, - datasets: snippetEditingController?.selectedExample?.datasets ?? [], ); _runSubscription = _codeRepository?.runCode(request).listen((event) { _result = event; @@ -139,7 +143,7 @@ class CodeRunner extends ChangeNotifier { _result = const RunCodeResult( status: RunCodeStatus.preparation, ); - final selectedExample = snippetEditingController!.selectedExample!; + final selectedExample = snippetEditingController!.example!; notifyListeners(); // add a little delay to improve user experience 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 6e004f43af6e..469014a5af6c 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 @@ -80,10 +80,10 @@ Future main() async { descriptor: emptyDescriptor, setCurrentSdk: true, ); - expect(controller.isExampleChanged, false); + expect(controller.codeRunner.isExampleChanged, false); controller.snippetEditingController?.fileControllers.first .codeController.text = 'test'; - expect(controller.isExampleChanged, true); + expect(controller.codeRunner.isExampleChanged, true); }, ); @@ -95,9 +95,9 @@ Future main() async { descriptor: emptyDescriptor, setCurrentSdk: true, ); - expect(controller.isExampleChanged, false); + expect(controller.codeRunner.isExampleChanged, false); controller.setPipelineOptions('test options'); - expect(controller.isExampleChanged, true); + expect(controller.codeRunner.isExampleChanged, true); }, ); }); From 93798ea44d21c780c8db69fdccf1aca82a5ba106 Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Mon, 16 Jan 2023 12:28:55 +0600 Subject: [PATCH 16/17] regenerated yaml files (#24617) --- .../assets/symbols/go.g.yaml | 7 ++- .../assets/symbols/java.g.yaml | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/playground/frontend/playground_components/assets/symbols/go.g.yaml b/playground/frontend/playground_components/assets/symbols/go.g.yaml index bcc281716f1d..cf3b2a0c9c9b 100644 --- a/playground/frontend/playground_components/assets/symbols/go.g.yaml +++ b/playground/frontend/playground_components/assets/symbols/go.g.yaml @@ -1411,6 +1411,10 @@ CancelJobResponse: - String properties: - State +Checkpoint: + properties: + - Reapply + - SR Class: methods: - String @@ -1678,7 +1682,6 @@ DataSink: - UID DataSource: methods: - - Checkpoint - Down - FinishBundle - ID @@ -3412,6 +3415,7 @@ LockRTracker: - GetRestriction - IsBounded - IsDone + - String - TryClaim - TrySplit properties: @@ -6085,6 +6089,7 @@ Tracker: - GetRestriction - IsBounded - IsDone + - String - TryClaim - TrySplit Transaction: diff --git a/playground/frontend/playground_components/assets/symbols/java.g.yaml b/playground/frontend/playground_components/assets/symbols/java.g.yaml index 557799d17369..345e11071b96 100644 --- a/playground/frontend/playground_components/assets/symbols/java.g.yaml +++ b/playground/frontend/playground_components/assets/symbols/java.g.yaml @@ -6319,6 +6319,36 @@ JdbcIO: - withWriteResults - write - writeVoid +JdbcReadSchemaTransformProvider: + methods: + - build + - buildTransform + - builder + - expand + - getConnectionInitSql + - getConnectionProperties + - getDriverClassName + - getFetchSize + - getJdbcUrl + - getLocation + - getOutputParallelization + - getPassword + - getReadQuery + - getUsername + - identifier + - inputCollectionNames + - outputCollectionNames + - setConnectionInitSql + - setConnectionProperties + - setDriverClassName + - setFetchSize + - setJdbcUrl + - setLocation + - setOutputParallelization + - setPassword + - setReadQuery + - setUsername + - validate JdbcSchemaIOProvider: methods: - buildReader @@ -6333,6 +6363,34 @@ JdbcSchemaIOProvider: JdbcWriteResult: methods: - create +JdbcWriteSchemaTransformProvider: + methods: + - build + - buildTransform + - builder + - expand + - getAutosharding + - getConnectionInitSql + - getConnectionProperties + - getDriverClassName + - getJdbcUrl + - getLocation + - getPassword + - getUsername + - getWriteStatement + - identifier + - inputCollectionNames + - outputCollectionNames + - setAutosharding + - setConnectionInitSql + - setConnectionProperties + - setDriverClassName + - setJdbcUrl + - setLocation + - setPassword + - setUsername + - setWriteStatement + - validate JmsIO: methods: - advance From d261b2aaba69a134e287b5ed9c194d119906fcbb Mon Sep 17 00:00:00 2001 From: "darkhan.nausharipov" Date: Thu, 19 Jan 2023 14:13:12 +0600 Subject: [PATCH 17/17] snippetEditingControllerGetter refinement (#24617) --- .../lib/src/controllers/code_runner.dart | 10 ++++++---- .../lib/src/controllers/playground_controller.dart | 2 +- .../src/controllers/playground_controller_test.dart | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart index e918951fefb6..ad2df180d940 100644 --- a/playground/frontend/playground_components/lib/src/controllers/code_runner.dart +++ b/playground/frontend/playground_components/lib/src/controllers/code_runner.dart @@ -31,17 +31,19 @@ class CodeRunner extends ChangeNotifier { SnippetEditingController? snippetEditingController; CodeRunner({ - required ValueGetter snippetEditingController, + required ValueGetter + snippetEditingControllerGetter, CodeRepository? codeRepository, }) : _codeRepository = codeRepository, - _snippetEditingControllerGetter = snippetEditingController; + _snippetEditingControllerGetter = snippetEditingControllerGetter; RunCodeResult? _result; StreamSubscription? _runSubscription; DateTime? _runStartDate; DateTime? _runStopDate; - String? get pipelineOptions => snippetEditingController?.pipelineOptions; + String? get pipelineOptions => + _snippetEditingControllerGetter().pipelineOptions; RunCodeResult? get result => _result; DateTime? get runStartDate => _runStartDate; DateTime? get runStopDate => _runStopDate; @@ -52,7 +54,7 @@ class CodeRunner extends ChangeNotifier { String get resultLogOutput => resultLog + resultOutput; bool get isExampleChanged { - return snippetEditingController?.isChanged ?? false; + return _snippetEditingControllerGetter().isChanged; } void clearResult() { diff --git a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart index 84ff60aed6a5..de8ee9112ed0 100644 --- a/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart +++ b/playground/frontend/playground_components/lib/src/controllers/playground_controller.dart @@ -74,7 +74,7 @@ class PlaygroundController with ChangeNotifier { codeRunner = CodeRunner( codeRepository: codeRepository, - snippetEditingController: () => snippetEditingController!, + snippetEditingControllerGetter: requireSnippetEditingController, )..addListener(notifyListeners); } 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 469014a5af6c..628b1cc9443a 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 @@ -58,7 +58,6 @@ Future main() async { }); test('Initial value of pipelineOptions should be empty string', () { - expect(controller.codeRunner.pipelineOptions, null); controller.setSdk(Sdk.go); expect(controller.codeRunner.pipelineOptions, ''); });