Skip to content
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

refactor(textual): Remove msg header screen #15208

Merged
merged 17 commits into from
Mar 9, 2023
Merged

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Feb 27, 2023

Description

@joeabbey 's PR with just some finishing touches

Closes: #14170


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Copy link
Contributor

@joeabbey joeabbey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@facundomedica facundomedica marked this pull request as ready for review February 28, 2023 14:04
@facundomedica facundomedica requested a review from a team as a code owner February 28, 2023 14:04
@@ -45,10 +47,15 @@ func (ar anyValueRenderer) Format(ctx context.Context, v protoreflect.Value) ([]
return nil, err
}

screens := make([]Screen, 1+len(subscreens))
// The Any value renderer suppresses emission of the object header
if subscreens[0].Content == fmt.Sprintf("%s object", internalMsg.ProtoReflect().Descriptor().Name()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting fmt.Sprintf("%s object", internalMsg.ProtoReflect().Descriptor().Name()) into a utility function taking a protoreflect.Message argument so that it can be used by both the formatter and the parser.

Actually, more than that, we need to check that vr is actually messageValueRenderer, whether or not the first screen matches the pattern. For instance, it would be reasonable to extend the SignModeHandler with a customer handler for StringValue messages that would work like the string renderer, and the enclosed string data might happen to say "StringValue object", but in this case it would be data, not a header.

For similar reasons, we'd need to check the type of the ValueRenderer in the parser, just for symmetry.

I'd still do the string comparison just to be sure. We want to be careful in omitting data from the sub-renderer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About extracting the fmt.Sprintf("%s object",...: there are 2 usages by 2 different types protoreflect.MessageType and protoreflect.ProtoMessage. Would it make sense to make it so we call msgType.New()?

Actually, more than that, we need to check that vr is actually messageValueRenderer, whether or not the first screen matches the pattern. For instance, it would be reasonable to extend the SignModeHandler with a customer handler for StringValue messages that would work like the string renderer, and the enclosed string data might happen to say "StringValue object", but in this case it would be data, not a header.

For similar reasons, we'd need to check the type of the ValueRenderer in the parser, just for symmetry.

I'd still do the string comparison just to be sure. We want to be careful in omitting data from the sub-renderer.

I think I understand what you mean, but I'm not sure I know how to implement that. Looks like GetMessageValueRenderer always return that type, even if the function returns an interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Sprintf, feel free to disregard my suggestion if it would lead to inefficiency or if the necessary adaptations make the code just as wordy as it was before.

GetMessageValueRenderer defaults to messageValueRenderer, but it can return specialized renderers for Coin, Timestamp, and Duration, and with SignModeHandler.DefineMessageRenderer() we can extend this list. None of the first three can have a rendering like "Foo object", but an extension could, and a specific renderer for StringValue (ref) would be quite reasonable.

It should be easy to modify the test to something like:

_, isMsgRender := vr.(*messageValueRenderer)
if isMsgRender && subscreens[0].Content == fmt.Sprintf(...) {
    omitHeader = 1
}

x/tx/textual/any.go Outdated Show resolved Hide resolved
x/tx/textual/any.go Outdated Show resolved Hide resolved
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @JimLarson said he'd take a look too, let's wait a bit before merging.

@amaury1093 amaury1093 enabled auto-merge (squash) March 9, 2023 08:43
@amaury1093 amaury1093 merged commit 138e0e1 into main Mar 9, 2023
@amaury1093 amaury1093 deleted the facu/rm-msg-header-screen branch March 9, 2023 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Textual Any Renderer: Remove msg header screen
4 participants