Skip to content

Commit

Permalink
fix protofile loading bug (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzakhany authored Oct 9, 2024
1 parent cd670ab commit dc36a72
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 55 deletions.
2 changes: 0 additions & 2 deletions ui/pages/requests/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type Container interface {

type GrpcContainer interface {
Container
SetOnProtoFileSelect(func(id string))
SetProtoBodyFilePath(filePath string)
SetOnReload(func(id string))
SetServices(services []domain.GRPCService)
SetMethodsLoading(loading bool)
Expand Down
17 changes: 0 additions & 17 deletions ui/pages/requests/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func NewController(view *View, repo repository.Repository, model *state.Requests
view.SetOnSubmit(c.onSubmit)
view.SetOnCopyResponse(c.onCopyResponse)
view.SetOnBinaryFileSelect(c.onSelectBinaryFile)
view.SetOnProtoFileSelect(c.onProtoFileSelect)
view.SetOnPostRequestSetChanged(c.onPostRequestSetChanged)
view.SetOnFormDataFileSelect(c.onFormDataFileSelect)
view.SetOnServerInfoReload(c.onServerInfoReload)
Expand Down Expand Up @@ -185,22 +184,6 @@ func (c *Controller) onLoadRequestExample(id string) {
c.view.SetSetGrpcRequestBody(id, example)
}

func (c *Controller) onProtoFileSelect(id string) {
c.explorer.ChoseFile(func(result explorer.Result) {
if result.Error != nil {
c.view.ShowGRPCRequestError(id, "Error", result.Error.Error())
return
}
c.view.HideGRPCRequestError(id)

if result.FilePath == "" {
return
}
c.view.SetProtoFilePath(id, result.FilePath)

}, ".proto")
}

func (c *Controller) onPostRequestSetChanged(id string, statusCode int, item, from, fromKey string) {
req := c.model.GetRequest(id)
if req == nil {
Expand Down
13 changes: 0 additions & 13 deletions ui/pages/requests/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,6 @@ func (r *Grpc) SetOnSetOnTriggerRequestChanged(f func(id, collectionID, requestI
})
}

func (r *Grpc) SetOnProtoFileSelect(f func(id string)) {
r.Request.ServerInfo.FileSelector.SetOnSelectFile(func() {
f(r.Req.MetaData.ID)
})
}

func (r *Grpc) SetProtoBodyFilePath(filePath string) {
r.Request.ServerInfo.FileSelector.SetFileName(filePath)
if r.onDataChanged != nil {
r.onDataChanged(r.Req.MetaData.ID, r.Req)
}
}

func (r *Grpc) ShowRequestPrompt(title, content, modalType string, onSubmit func(selectedOption string, remember bool), options ...widgets.Option) {
r.Request.Prompt.Type = modalType
r.Request.Prompt.Title = title
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/requests/grpc/server_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewServerInfo(explorer *explorer.Explorer, info domain.ServerInfo) *ServerI

s := &ServerInfo{
definitionFrom: new(widget.Enum),
FileSelector: widgets.NewFileSelector(fileName, explorer),
FileSelector: widgets.NewFileSelector(fileName, explorer, ".proto"),
ReloadButton: new(widget.Clickable),
IsLoading: false,
}
Expand Down
19 changes: 0 additions & 19 deletions ui/pages/requests/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ type View struct {
onOnPostRequestSetChanged func(id string, statusCode int, item, from, fromKey string)
onOnSetOnTriggerRequestChanged func(id, collectionID, requestID string)
onBinaryFileSelect func(id string)
onProtoFileSelect func(id string)
onFromDataFileSelect func(requestID, fieldID string)
onServerInfoReload func(id string)
onGrpcInvoke func(id string)
Expand Down Expand Up @@ -256,10 +255,6 @@ func (v *View) SetOnBinaryFileSelect(f func(id string)) {
v.onBinaryFileSelect = f
}

func (v *View) SetOnProtoFileSelect(f func(id string)) {
v.onProtoFileSelect = f
}

func (v *View) SetOnServerInfoReload(f func(id string)) {
v.onServerInfoReload = f
}
Expand Down Expand Up @@ -288,14 +283,6 @@ func (v *View) SetBinaryBodyFilePath(id, filePath string) {
}
}

func (v *View) SetProtoFilePath(id, filePath string) {
if ct, ok := v.containers.Get(id); ok {
if ct, ok := ct.(GrpcContainer); ok {
ct.SetProtoBodyFilePath(filePath)
}
}
}

func (v *View) SetGRPCServices(id string, services []domain.GRPCService) {
if ct, ok := v.containers.Get(id); ok {
if ct, ok := ct.(GrpcContainer); ok {
Expand Down Expand Up @@ -512,12 +499,6 @@ func (v *View) createGrpcContainer(req *domain.Request) Container {
}
})

ct.SetOnProtoFileSelect(func(id string) {
if v.onProtoFileSelect != nil {
v.onProtoFileSelect(id)
}
})

ct.SetOnReload(func(id string) {
if v.onServerInfoReload != nil {
v.onServerInfoReload(id)
Expand Down
9 changes: 6 additions & 3 deletions ui/widgets/file_selector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package widgets

import (
"errors"
"fmt"

"gioui.org/layout"
Expand Down Expand Up @@ -50,7 +51,10 @@ func (b *FileSelector) handleExplorerSelect() {

b.explorer.ChoseFile(func(result explorer.Result) {
if result.Error != nil {
fmt.Println("failed to get file", result.Error)
if !errors.Is(result.Error, explorer.ErrUserDecline) {
fmt.Printf("failed to get file, %s\n", result.Error)
return
}
return
}
if result.FilePath == "" {
Expand All @@ -67,12 +71,11 @@ func (b *FileSelector) SetOnSelectFile(f func()) {
b.textField.SetOnIconClick(func() {
if b.FileName != "" {
b.RemoveFile()
b.changed = true
b.onChangeCallback()
return
} else {
// Select file
f()
b.onChangeCallback()
}
})
}
Expand Down

0 comments on commit dc36a72

Please sign in to comment.