Skip to content

Commit

Permalink
fix(query-timeout-message): Fix query timeout message and add JSON re…
Browse files Browse the repository at this point in the history
…sult (#63)

Co-authored-by: Broknloop <broknloop@gmail.com>
  • Loading branch information
broknloop and joaomcclain authored Jan 10, 2024
1 parent 1758e46 commit 728d91b
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/main/js/components/query-result/query-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ function QueryResult({containerUrl, vispanaClient, query, showResults, schema, r
error: ""
});

const NoDataConst = props => {
if (data.json && data.json.root) {
const root = data.json.root
if (root.coverage && root.coverage.degraded && root.coverage.degraded.timeout) {
return <><span className="text-red-500 m-8">Vespa query timed out.</span></>
} else {
if (root.fields && root.fields.totalCount === 0) {
return <><span className="text-yellow-400 m-8">No fields returned.</span></>
} else {
return <><span className="text-yellow-400 m-8">Unexpected state, please check JSON and report an issue.</span></>
}
}
}

return <><span className="text-yellow-400 m-8">There are no records to display</span></>
}

async function postQuery(offset, perPage) {
try {
const queryObject = JSON.parse(query)
Expand Down Expand Up @@ -168,6 +185,7 @@ function QueryResult({containerUrl, vispanaClient, query, showResults, schema, r
paginationTotalRows={totalRows}
onChangeRowsPerPage={handlePerRowsChange}
onChangePage={handlePageChange}
noDataComponent={<NoDataConst/>}
/>
)

Expand All @@ -179,6 +197,12 @@ function QueryResult({containerUrl, vispanaClient, query, showResults, schema, r
{
"header": "Results",
"content": results
},
{
"header": "JSON response",
"content": (<SyntaxHighlighter language="json" style={androidstudio}>
{JSON.stringify(data.json, null, 2)}
</SyntaxHighlighter>)
}
]

Expand Down Expand Up @@ -217,10 +241,13 @@ function processResult(result) {
if (!result || !result.root.fields.totalCount) {
return {
columns: [],
content: []
content: [],
trace: [],
json: result
}
}
const children = result.root.children;

const children = result.root.children ? result.root.children : [];

const resultFields = children.flatMap(child => Object.keys(child.fields));
resultFields.push("relevance")
Expand Down Expand Up @@ -248,7 +275,8 @@ function processResult(result) {
return {
columns: columns,
content: data,
trace: trace
trace: trace,
json: result
}
}

Expand Down

0 comments on commit 728d91b

Please sign in to comment.