-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General mechanism for displaying different kinds of structured output
- Loading branch information
1 parent
cf84a47
commit 9fa4465
Showing
9 changed files
with
113 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="error">@Result.OutputToString</div> | ||
|
||
@code { | ||
[Parameter] public ExecuteResult Result { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.error { | ||
color: white; | ||
white-space: pre; | ||
font-family: monospace; | ||
--bgcol: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@switch (OutputToString) | ||
{ | ||
case null: | ||
<div>(no output)</div> | ||
break; | ||
case "": | ||
<div>(empty string)</div> | ||
break; | ||
default: | ||
<div>@OutputToString</div> | ||
break; | ||
} | ||
|
||
@code { | ||
[Parameter] public string OutputToString { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@if (Result != null) | ||
{ | ||
if (Result.OutputType == "error") | ||
{ | ||
<ErrorDisplay Result="Result" /> | ||
} | ||
else | ||
{ | ||
switch (_deserializedOutput) | ||
{ | ||
default: | ||
<FallbackDisplay OutputToString="@Result.OutputToString" /> | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@code { | ||
[Parameter] public ExecuteResult Result { get; set; } | ||
|
||
private object _deserializedOutput; | ||
|
||
protected override void OnParametersSet() | ||
{ | ||
if (Result?.OutputJson != null && Result.OutputType != "error") | ||
{ | ||
try | ||
{ | ||
var type = Type.GetType(Result.OutputType); | ||
_deserializedOutput = System.Text.Json.JsonSerializer.Deserialize(Result.OutputJson, type); | ||
} | ||
catch | ||
{ | ||
// If we can't deserialize it, we'll just use the string fallback | ||
} | ||
} | ||
} | ||
|
||
// We create a new instance of this component for each new ExecuteResult, | ||
// so there's no need for existing instances to re-render | ||
protected override bool ShouldRender() | ||
=> false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters