-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add data buffer support to components (form card). #441 #2085
Conversation
@geomodular could you please have a look at the Go code once you have a bit of time? I feel like the code is too verbose and a more idiomatic solution exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for the go
part. Just few notes.
card.go
Outdated
lastKey := keys[len(keys)-1] | ||
var x any = c.data | ||
// Get the object even if nested. | ||
for i := 0; i < len(keys)-1; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rewrite this as for ... range
for better readability:
for _, key := range keys {
x = get(x, key)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, the problem is I need to ignore the last entry. Do you think this would be more readable?
for _, key := range keys[:len(keys)-1] {
x = get(x, key)
}
card.go
Outdated
x = c.nameComponentMap[ks[0]] | ||
startIdx = 1 | ||
} | ||
for i := startIdx; i < len(ks)-1; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be rewritten as:
for _, k := range ks[startIdx:] {
x = get(x, k)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, exactly what I needed 👍
for _, k := range ks[startIdx : len(ks)-1] {
x = get(x, k)
}
card.go
Outdated
@@ -163,6 +175,12 @@ func get(ix any, k string) any { | |||
func (c *Card) dump() CardD { | |||
data := make(map[string]any) | |||
var bufs []BufD | |||
|
|||
// Look for nested buffers within form_card. | |||
if v, ok := c.data["view"]; ok && v.(string) == "form" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v.(string)
might not be a string and can cause some trouble here. I'd handle it inside the if
scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I need to write a nested if with type cast check, right? Or is there a way how to put it to the existing if statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, nested if
card.go
Outdated
|
||
// Look for nested buffers within form_card. | ||
if v, ok := c.data["view"]; ok && v.(string) == "form" { | ||
fillFormCardBufs(c.data, data, &bufs, make([]string, 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I was puzzled with make([]string, 0))
but now I see the function is recursive. Seems ok.
…tes are loaded due to Go arbitrary map iteration order. #441
This PR introduces support for non-packed data buffers within
ui.visualization
components - form cards.By-name access is supported as well, buffers behave in the same way for form components as they do in cards.
Closes #441