Skip to content

Commit

Permalink
Merge pull request #16753 from [BEAM-13837] [Playground] show graph o…
Browse files Browse the repository at this point in the history
…n the frontend

* [BEAM-13837] playground - show graph on the frontend

* [BEAM-13837] playground - remove unusued prints

* [BEAM-13837] playground - hide graph where not available

* [BEAM-13837] playground - remove unused imports
  • Loading branch information
ElessarST authored Feb 16, 2022
1 parent b3de798 commit 3fed305
Show file tree
Hide file tree
Showing 34 changed files with 1,336 additions and 26 deletions.
2 changes: 2 additions & 0 deletions playground/frontend/lib/constants/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Color kLightPrimaryBackground = Colors.white;
const Color kLightSecondaryBackground = Color(0xFFFCFCFC);
const Color kLightGrey = Color(0xFFE5E5E5);
const Color kLightGrey1 = Color(0xFFA0A4AB);
const Color kLightGrey2 = Color(0xFF45454E);
const Color kLightText = Color(0xFF242639);
const Color kLightPrimary = Color(0xFFE74D1A);
const Color kLightCode1 = Color(0xFFDA2833);
Expand All @@ -34,6 +35,7 @@ const Color kDarkPrimaryBackground = Color(0xFF18181B);
const Color kDarkSecondaryBackground = Color(0xFF2E2E34);
const Color kDarkGrey = Color(0xFF3F3F46);
const Color kDarkGrey1 = Color(0xFF606772);
const Color kDarkGrey2 = Color(0xFF45454E);
const Color kDarkText = Color(0xFFFFFFFF);
const Color kDarkPrimary = Color(0xFFF26628);
const Color kDarkCode1 = Color(0xFFFB8188);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ abstract class CodeClient {
String pipelineUuid,
RunCodeRequestWrapper request,
);

Future<OutputResponse> getGraphOutput(
String pipelineUuid,
RunCodeRequestWrapper request,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class GrpcCodeClient implements CodeClient {

@override
Future<void> cancelExecution(String pipelineUuid) {
return _runSafely(() => _defaultClient
.cancel(grpc.CancelRequest(pipelineUuid: pipelineUuid)));
return _runSafely(() =>
_defaultClient.cancel(grpc.CancelRequest(pipelineUuid: pipelineUuid)));
}

@override
Expand Down Expand Up @@ -140,6 +140,20 @@ class GrpcCodeClient implements CodeClient {
.then((response) => _toOutputResponse(response.output)));
}

@override
Future<OutputResponse> getGraphOutput(
String pipelineUuid,
RunCodeRequestWrapper request,
) {
return _runSafely(() => _defaultClient
.getGraph(grpc.GetGraphRequest(pipelineUuid: pipelineUuid))
.then((response) => OutputResponse(response.graph))
.catchError((err) {
print(err);
return _toOutputResponse('');
}));
}

Future<T> _runSafely<T>(Future<T> Function() invoke) async {
try {
return await invoke();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import 'package:playground/modules/editor/repository/code_repository/code_client/code_client.dart';
import 'package:playground/modules/editor/repository/code_repository/code_client/output_response.dart';
import 'package:playground/modules/editor/repository/code_repository/run_code_error.dart';
import 'package:playground/modules/editor/repository/code_repository/run_code_request.dart';
import 'package:playground/modules/editor/repository/code_repository/run_code_result.dart';
Expand Down Expand Up @@ -108,6 +109,7 @@ class CodeRepository {
) async {
final prevOutput = prevResult?.output ?? '';
final prevLog = prevResult?.log ?? '';
final prevGraph = prevResult?.graph ?? '';
switch (status) {
case RunCodeStatus.compileError:
final compileOutput = await _client.getCompileOutput(
Expand All @@ -119,6 +121,7 @@ class CodeRepository {
status: status,
output: compileOutput.output,
log: prevLog,
graph: prevGraph,
);
case RunCodeStatus.timeout:
return RunCodeResult(
Expand All @@ -127,6 +130,7 @@ class CodeRepository {
errorMessage: kTimeoutErrorText,
output: kTimeoutErrorText,
log: prevLog,
graph: prevGraph,
);
case RunCodeStatus.runError:
final output = await _client.getRunErrorOutput(pipelineUuid, request);
Expand All @@ -135,6 +139,7 @@ class CodeRepository {
status: status,
output: output.output,
log: prevLog,
graph: prevGraph,
);
case RunCodeStatus.validationError:
final output =
Expand All @@ -143,6 +148,7 @@ class CodeRepository {
status: status,
output: output.output,
log: prevLog,
graph: prevGraph,
);
case RunCodeStatus.preparationError:
final output =
Expand All @@ -151,6 +157,7 @@ class CodeRepository {
status: status,
output: output.output,
log: prevLog,
graph: prevGraph,
);
case RunCodeStatus.unknownError:
return RunCodeResult(
Expand All @@ -159,40 +166,52 @@ class CodeRepository {
errorMessage: kUnknownErrorText,
output: kUnknownErrorText,
log: prevLog,
graph: prevGraph,
);
case RunCodeStatus.executing:
final responses = await Future.wait([
_client.getRunOutput(pipelineUuid, request),
_client.getLogOutput(pipelineUuid, request),
prevGraph.isEmpty
? _client.getGraphOutput(pipelineUuid, request)
: Future.value(OutputResponse(prevGraph)),
]);
final output = responses[0];
final log = responses[1];
final graph = responses[2];
return RunCodeResult(
pipelineUuid: pipelineUuid,
status: status,
output: prevOutput + output.output,
log: prevLog + log.output,
graph: graph.output,
);
case RunCodeStatus.finished:
final responses = await Future.wait([
_client.getRunOutput(pipelineUuid, request),
_client.getLogOutput(pipelineUuid, request),
_client.getRunErrorOutput(pipelineUuid, request)
_client.getRunErrorOutput(pipelineUuid, request),
prevGraph.isEmpty
? _client.getGraphOutput(pipelineUuid, request)
: Future.value(OutputResponse(prevGraph)),
]);
final output = responses[0];
final log = responses[1];
final error = responses[2];
final graph = responses[3];
return RunCodeResult(
pipelineUuid: pipelineUuid,
status: status,
output: prevOutput + output.output + error.output,
log: prevLog + log.output,
graph: graph.output,
);
default:
return RunCodeResult(
pipelineUuid: pipelineUuid,
log: prevLog,
status: status,
graph: prevGraph,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class RunCodeResult {
final String? pipelineUuid;
final String? output;
final String? log;
final String? graph;
final String? errorMessage;

RunCodeResult({
Expand All @@ -55,6 +56,7 @@ class RunCodeResult {
this.output,
this.log,
this.errorMessage,
this.graph,
});

bool get isFinished {
Expand All @@ -70,11 +72,12 @@ class RunCodeResult {
status == other.status &&
output == other.output &&
log == other.log &&
graph == other.graph &&
errorMessage == other.errorMessage;

@override
int get hashCode =>
hashValues(pipelineUuid, status, output, log, errorMessage);
hashValues(pipelineUuid, status, output, log, errorMessage, graph);

@override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ExampleModel with Comparable<ExampleModel> {
String? outputs;
String? logs;
String? pipelineOptions;
String? graph;

ExampleModel({
required this.name,
Expand All @@ -57,6 +58,7 @@ class ExampleModel with Comparable<ExampleModel> {
this.outputs,
this.logs,
this.pipelineOptions,
this.graph,
});

setSource(String source) {
Expand All @@ -71,6 +73,10 @@ class ExampleModel with Comparable<ExampleModel> {
this.logs = logs;
}

setGraph(String graph) {
this.graph = graph;
}

bool isInfoFetched() {
// checking only source, because outputs/logs can be empty
return source?.isNotEmpty ?? false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ abstract class ExampleClient {
Future<OutputResponse> getExampleOutput(GetExampleRequestWrapper request);

Future<OutputResponse> getExampleLogs(GetExampleRequestWrapper request);

Future<OutputResponse> getExampleGraph(GetExampleRequestWrapper request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class GrpcExampleClient implements ExampleClient {
OutputResponse(replaceIncorrectSymbols(response.output)))
.catchError((err) {
print(err);
OutputResponse('');
return OutputResponse('');
}),
);
}
Expand All @@ -89,7 +89,21 @@ class GrpcExampleClient implements ExampleClient {
OutputResponse(replaceIncorrectSymbols(response.output)))
.catchError((err) {
print(err);
OutputResponse('');
return OutputResponse('');
}),
);
}

@override
Future<OutputResponse> getExampleGraph(GetExampleRequestWrapper request) {
return _runSafely(
() => _defaultClient
.getPrecompiledObjectGraph(
_getExampleGraphRequestToGrpcRequest(request))
.then((response) => OutputResponse(response.graph))
.catchError((err) {
print(err);
return OutputResponse('');
}),
);
}
Expand Down Expand Up @@ -130,6 +144,12 @@ class GrpcExampleClient implements ExampleClient {
return grpc.GetPrecompiledObjectLogsRequest()..cloudPath = request.path;
}

grpc.GetPrecompiledObjectGraphRequest _getExampleGraphRequestToGrpcRequest(
GetExampleRequestWrapper request,
) {
return grpc.GetPrecompiledObjectGraphRequest()..cloudPath = request.path;
}

grpc.Sdk _getGrpcSdk(SDK sdk) {
switch (sdk) {
case SDK.java:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ class ExampleRepository {
final result = await _client.getExampleLogs(request);
return result.output;
}

Future<String> getExampleGraph(
GetExampleRequestWrapper request,
) async {
final result = await _client.getExampleGraph(request);
return result.output;
}
}
Loading

0 comments on commit 3fed305

Please sign in to comment.