Skip to content

Commit

Permalink
Add google.protobuf.Struct support (#77)
Browse files Browse the repository at this point in the history
* Add google.protobuf.Struct support

* Add google.protobuf.Struct support

* Update package.yml

change from https://github.com/actions/virtual-environments

* mdf CHANGELOG.md

Co-authored-by: wangyufeng04 <wangyufeng04@baidu.com>
  • Loading branch information
tra4less and wangyufeng04 committed Dec 12, 2021
1 parent b107d60 commit fe95305
Show file tree
Hide file tree
Showing 11 changed files with 667 additions and 251 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/package.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
go-version: [1.16.x]
platform: [macos-10.15, ubuntu-16.04, windows-2019]
platform: [macos-10.15, ubuntu-18.04, windows-2019]
runs-on: ${{ matrix.platform }}
steps:
- name: Get version tag (unix)
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:

# linux
- name: Build for linux
if: matrix.platform == 'ubuntu-16.04'
if: matrix.platform == 'ubuntu-18.04'
run: |
sudo apt update && sudo apt install -y libgtk-3-dev libwebkit2gtk-4.0-dev
mkdir -p ~/.wails
Expand All @@ -69,7 +69,7 @@ jobs:
tar -C build -zcvf Wombat_${{ steps.version.outputs.tag }}_Linux_x86_64.tar.gz wombat
- name: Upload linux tar.gz
if: matrix.platform == 'ubuntu-16.04'
if: matrix.platform == 'ubuntu-18.04'
uses: actions/upload-artifact@v2
with:
name: Wombat_${{ steps.version.outputs.tag }}_Linux_x86_64.tar.gz
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.5.1] - 2021-11-22

### Added
- Support google.protobuf.Struct

## [v0.5.0] - 2021-04-26

### Added
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/controls/TextArea.svelte
@@ -1,11 +1,14 @@
<script>
import InputLabel from "./InputLabel.svelte";
import { createEventDispatcher } from "svelte";
export let label = undefined;
export let hint = "";
export let value = "";
export let width = "400px";
export let labelColor = undefined;
export let removeable = false;
const dispatch = createEventDispatcher();
const onDataChange = (event) => dispatch("change", event);
</script>

<style>
Expand Down Expand Up @@ -34,5 +37,5 @@
{#if label}
<InputLabel on:remove {removeable} {label} {hint} color={labelColor} />
{/if}
<textarea bind:value></textarea>
<textarea bind:value on:change={onDataChange} />
</div>
69 changes: 69 additions & 0 deletions frontend/src/views/FieldStruct.svelte
@@ -0,0 +1,69 @@
<script>
import InputLabel from "../controls/InputLabel.svelte";
import Checkbox from "../controls/Checkbox.svelte";
import TextArea from "../controls/TextArea.svelte";
export let field;
export let state;
export let key;
export let idx;
let val, labelColor, removeable, v;
$: {
val = key !== undefined ? key : idx >= 0 ? idx : field.name;
v === undefined ? (v = JSON.stringify(state[val])) : (v = v);
labelColor =
key !== undefined
? "var(--accent-color3)"
: idx >= 0
? "var(--accent-color2)"
: undefined;
removeable = idx >= 0;
}
const onEnabledChanged = ({ detail: checked }) => {
state[val] = checked ? {} : undefined;
};
const onDataChange = ({ detail: event }) => {
v = event.target.value;
try {
state[val] = JSON.parse(event.target.value);
} catch (e) {
state[val] = null;
wails.Events.Emit("wombat:error", {
msg: String(e),
title: "parse " + field.name + " error",
});
}
};
</script>

<div class="msg-label">
<InputLabel
on:remove
{removeable}
label={field.name}
color={labelColor}
hint={field.kind}
block
/>
<Checkbox
style="margin-bottom: 0"
checked={state[val] !== undefined}
on:check={onEnabledChanged}
/>
</div>

{#if state[val] !== undefined}
<TextArea on:remove {removeable} on:change={onDataChange} value={v} />
{/if}

<style>
.msg-label {
display: flex;
align-items: center;
min-width: 400px;
margin-bottom: var(--padding);
}
</style>
5 changes: 5 additions & 0 deletions frontend/src/views/FieldWellKnown.svelte
Expand Up @@ -3,6 +3,7 @@
import FieldBoolValue from "./FieldBoolValue.svelte";
import FieldNilText from "./FieldNilText.svelte";
import FieldTimestamp from "./FieldTimestamp.svelte";
import FieldStruct from "./FieldStruct.svelte";
export let name = "";
export let message = {};
Expand Down Expand Up @@ -44,6 +45,10 @@

<FieldTimestamp on:remove {field} {state} {key} {idx} />

{:else if field.kind === "google.protobuf.Struct"}

<FieldStruct on:remove {field} {state} {key} {idx} />

{:else}

<FieldText on:remove {field} {state} {key} {idx} {placeholder} />
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/MessageField.svelte
Expand Up @@ -28,6 +28,7 @@
case "google.protobuf.BoolValue":
case "google.protobuf.StringValue":
case "google.protobuf.BytesValue":
case "google.protobuf.Struct":
return true;
default:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -22,7 +22,7 @@ require (
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.0 // indirect
github.com/wailsapp/wails v1.16.3
github.com/wailsapp/wails v1.16.8
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d // indirect
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Expand Up @@ -86,7 +86,6 @@ github.com/jackmordaunt/icns v1.0.0 h1:RYSxplerf/l/DUd09AHtITwckkv/mqjVv4DjYdPmA
github.com/jackmordaunt/icns v1.0.0/go.mod h1:7TTQVEuGzVVfOPPlLNHJIkzA6CoV7aH1Dv9dW351oOo=
github.com/jhump/protoreflect v1.8.2 h1:k2xE7wcUomeqwY0LDCYA16y4WWfyTcMx5mKhk0d4ua0=
github.com/jhump/protoreflect v1.8.2/go.mod h1:7GcYQDdMU/O/BBrl/cX6PNHpXh6cenjd8pneu5yW7Tg=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
Expand Down Expand Up @@ -121,7 +120,6 @@ github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
Expand Down Expand Up @@ -261,7 +259,6 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12 h1:OwhZOOMuf7leLaSCuxtQ9FW7ui2L2L6UKOtKAUqovUQ=
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/AlecAivazis/survey.v1 v1.8.4 h1:10xXXN3wgIhPheb5NI58zFgZv32Ana7P3Tl4shW+0Qc=
gopkg.in/AlecAivazis/survey.v1 v1.8.4/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
15 changes: 15 additions & 0 deletions internal/app/api.go
Expand Up @@ -696,6 +696,21 @@ func fieldViewsFromDesc(fds protoreflect.FieldDescriptors, isOneof bool, cd *cyc

if fmd := fd.Message(); fmd != nil {
var err error
const structFullName = "google.protobuf.Struct"
if fmd.FullName() == structFullName {
fdesc.Kind = "message"
fdesc.Message = &messageDesc{
Name: string(fmd.Name()),
FullName: structFullName,
Fields: []fieldDesc{{
Name: "value",
FullName: "google.protobuf.Struct.value",
Kind: "string",
}},
}
goto appendField
}

fdesc.Message, err = messageViewFromDesc(fmd, cd)
if err != nil {
return nil, err
Expand Down

0 comments on commit fe95305

Please sign in to comment.