Use backend IDs for great justice.

pull/1232/head
Hunter Trujillo 2017-04-10 12:02:09 -06:00
parent 607004b2e6
commit fd672f0f05
2 changed files with 7 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import (
)
type QueryRequest struct {
ID string `json:"id"`
Query string `json:"query"`
}
@ -17,6 +18,7 @@ type QueriesRequest struct {
}
type QueryResponse struct {
ID string `json:"id"`
Query string `json:"query"`
QueryConfig chronograf.QueryConfig `json:"queryConfig"`
QueryAST *queries.SelectStatement `json:"queryAST,omitempty"`
@ -52,12 +54,14 @@ func (s *Service) Queries(w http.ResponseWriter, r *http.Request) {
for i, q := range req.Queries {
qr := QueryResponse{
ID: q.ID,
Query: q.Query,
QueryConfig: ToQueryConfig(q.Query),
}
if stmt, err := queries.ParseSelect(q.Query); err == nil {
qr.QueryAST = stmt
}
qr.QueryConfig.ID = q.ID
res.Queries[i] = qr
}

View File

@ -150,9 +150,9 @@ export function editQueryStatus(queryID, status) {
// Async actions
export const editRawTextAsync = (url, id, text) => async (dispatch) => {
try {
const {data} = await getQueryConfig(url, [{query: text}])
const config = data.queries.find(q => q.query === text)
dispatch(updateQueryConfig({...config.queryConfig, id}))
const {data} = await getQueryConfig(url, [{query: text, id}])
const config = data.queries.find(q => q.id === id)
dispatch(updateQueryConfig(config.queryConfig))
} catch (error) {
console.error(error)
}