Change /suggestions response format to include params
Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Brandon Farmer <bthesorceror@gmail.com>pull/3033/head
parent
c9e9b0bc90
commit
6e35370751
|
@ -10,11 +10,12 @@ import (
|
||||||
|
|
||||||
// SuggestionsResponse provides a list of available IFQL functions
|
// SuggestionsResponse provides a list of available IFQL functions
|
||||||
type SuggestionsResponse struct {
|
type SuggestionsResponse struct {
|
||||||
Functions []string `json:"funcs"`
|
Functions []SuggestionResponse `json:"funcs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SuggestionResponse provides the parameters available for a given IFQL function
|
// SuggestionResponse provides the parameters available for a given IFQL function
|
||||||
type SuggestionResponse struct {
|
type SuggestionResponse struct {
|
||||||
|
Name string `json:"name"`
|
||||||
Params map[string]string `json:"params"`
|
Params map[string]string `json:"params"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +45,20 @@ func (s *Service) IFQL(w http.ResponseWriter, r *http.Request) {
|
||||||
func (s *Service) IFQLSuggestions(w http.ResponseWriter, r *http.Request) {
|
func (s *Service) IFQLSuggestions(w http.ResponseWriter, r *http.Request) {
|
||||||
completer := ifql.DefaultCompleter()
|
completer := ifql.DefaultCompleter()
|
||||||
names := completer.FunctionNames()
|
names := completer.FunctionNames()
|
||||||
res := SuggestionsResponse{Functions: names}
|
var functions []SuggestionResponse
|
||||||
|
for _, name := range names {
|
||||||
|
suggestion, err := completer.FunctionSuggestion(name)
|
||||||
|
if err != nil {
|
||||||
|
Error(w, http.StatusNotFound, err.Error(), s.Logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
functions = append(functions, SuggestionResponse{
|
||||||
|
Name: name,
|
||||||
|
Params: suggestion.Params,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
res := SuggestionsResponse{Functions: functions}
|
||||||
|
|
||||||
encodeJSON(w, http.StatusOK, res, s.Logger)
|
encodeJSON(w, http.StatusOK, res, s.Logger)
|
||||||
}
|
}
|
||||||
|
@ -55,10 +69,10 @@ func (s *Service) IFQLSuggestion(w http.ResponseWriter, r *http.Request) {
|
||||||
name := httprouter.GetParamFromContext(ctx, "name")
|
name := httprouter.GetParamFromContext(ctx, "name")
|
||||||
completer := ifql.DefaultCompleter()
|
completer := ifql.DefaultCompleter()
|
||||||
|
|
||||||
res, err := completer.FunctionSuggestion(name)
|
suggestion, err := completer.FunctionSuggestion(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error(w, http.StatusNotFound, err.Error(), s.Logger)
|
Error(w, http.StatusNotFound, err.Error(), s.Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
encodeJSON(w, http.StatusOK, SuggestionResponse(res), s.Logger)
|
encodeJSON(w, http.StatusOK, SuggestionResponse{Name: name, Params: suggestion.Params}, s.Logger)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,8 @@ export class IFQLPage extends PureComponent<Props, State> {
|
||||||
const {suggestions} = this.props.links
|
const {suggestions} = this.props.links
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const funcs = await getSuggestions(suggestions)
|
const results = await getSuggestions(suggestions)
|
||||||
|
const funcs = results.map(s => s.name)
|
||||||
this.setState({funcs})
|
this.setState({funcs})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Could not get function suggestions: ', error)
|
console.error('Could not get function suggestions: ', error)
|
||||||
|
|
Loading…
Reference in New Issue