Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
convert a timestream query result to a mui-x datagrid compatible format
private normalizeQueryOutput = (output: QueryCommandOutput) => {
const columns =
output.ColumnInfo?.map((column) => {
const name = column.Name ?? "Unknown"
return {
field: name,
headerName: name,
flex: 1,
}
}) ?? []
const rows =
output.Rows?.map((row, rowOffset) => {
let object = { id: rowOffset }
columns.forEach((column, columnOffset) => {
if (row.Data) {
object = { ...object, [column.field]: row.Data[columnOffset].ScalarValue ?? 0 }
}
})
return object
}) ?? []
return { columns, rows }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment