Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Malarg committed Apr 18, 2023
1 parent a919d42 commit 1540961
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 deletions.
6 changes: 5 additions & 1 deletion learning/tour-of-beam/frontend/lib/pages/tour/screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class TourScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TobScaffold(
pageActions: [TobPipelineOptionsDropdown(tourNotifier: tourNotifier)],
pageActions: [
TobPipelineOptionsDropdown(
playgroundController: tourNotifier.playgroundController,
),
],
child: MediaQuery.of(context).size.width > ScreenBreakpoints.twoColumns
? _WideTour(tourNotifier)
: _NarrowTour(tourNotifier),
Expand Down
1 change: 1 addition & 0 deletions learning/tour-of-beam/frontend/lib/pages/tour/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class TourNotifier extends ChangeNotifier with PageStateMixin<void> {

Future<void> _setPlaygroundSnippet(String? snippetId) async {
if (snippetId == null) {
playgroundController.setEmpty();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,27 @@
import 'package:flutter/widgets.dart';
import 'package:playground_components/playground_components.dart';

import '../state.dart';

class TobPipelineOptionsDropdown extends StatelessWidget {
final TourNotifier tourNotifier;
final PlaygroundController playgroundController;

const TobPipelineOptionsDropdown({required this.tourNotifier});
const TobPipelineOptionsDropdown({
required this.playgroundController,
});

@override
Widget build(BuildContext context) {
final controller = tourNotifier.playgroundController;

return AnimatedBuilder(
animation: tourNotifier,
animation: playgroundController,
builder: (_, __) {
return AnimatedBuilder(
animation: controller,
builder: (_, __) {
if (!tourNotifier.isUnitContainsSnippet) {
return const SizedBox.shrink();
}
if (playgroundController.isEmpty) {
return const SizedBox.shrink();
}

return PipelineOptionsDropdown(
pipelineOptions:
controller.snippetEditingController?.pipelineOptions ?? '',
setPipelineOptions: controller.setPipelineOptions,
);
},
final pipelineOptions =
playgroundController.snippetEditingController?.pipelineOptions;
return PipelineOptionsDropdown(
pipelineOptions: pipelineOptions ?? '',
setPipelineOptions: playgroundController.setPipelineOptions,
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class PlaygroundDemoWidget extends StatelessWidget {
}

void _handleError(BuildContext context, PlaygroundController controller) {
//TODO: https://github.com/apache/beam/issues/26319
PlaygroundComponents.toastNotifier.add(
Toast(
description: controller.codeRunner.result?.errorMessage ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class CodeTextAreaWrapper extends StatelessWidget {
}

void _handleError(BuildContext context, PlaygroundController controller) {
//TODO: https://github.com/apache/beam/issues/26319
PlaygroundComponents.toastNotifier.add(
Toast(
description: controller.codeRunner.result?.errorMessage ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class BeamSizes {
static const double dividerHeight = 1;
static const double elevation = 2;
static const double headerButtonHeight = 46;
static const double labelFontSize = 16;
static const double loadingIndicator = 40;
static const double splitViewSeparator = BeamSizes.size8;
static const double tabBarHeight = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class ExamplesLoader {
_playgroundController = value;
}

void clearDescriptor() {
_descriptor = null;
}

/// Loads examples from [descriptor]'s immediate list.
///
/// Sets empty editor for SDKs of failed examples.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import '../models/example_loading_descriptors/user_shared_example_loading_descri
import '../models/intents.dart';
import '../models/sdk.dart';
import '../models/shortcut.dart';
import '../models/snippet_file.dart';
import '../repositories/code_repository.dart';
import '../services/symbols/loaders/map.dart';
import '../services/symbols/symbols_notifier.dart';
Expand Down Expand Up @@ -128,6 +129,11 @@ class PlaygroundController with ChangeNotifier {
selectedExample?.type != ExampleType.test &&
[Sdk.java, Sdk.python].contains(sdk);

bool get isEmpty =>
selectedExample == null ||
selectedExample?.path == '' &&
(selectedExample?.files.contains(SnippetFile.empty) ?? false);

/// If no SDK is selected, sets it to [sdk] and creates an empty state for it.
void setEmptyIfNoSdk(Sdk sdk) {
if (_sdk != null) {
Expand All @@ -141,6 +147,15 @@ class PlaygroundController with ChangeNotifier {
);
}

void setEmpty() {
examplesLoader.clearDescriptor();
setExample(
Example.empty(Sdk.java),
descriptor: const EmptyExampleLoadingDescriptor(sdk: Sdk.java),
setCurrentSdk: false,
);
}

/// If the state for [sdk] does not exists, creates an empty state for it.
void setEmptyIfNotExists(
Sdk sdk, {
Expand Down

0 comments on commit 1540961

Please sign in to comment.