2022-04-22 08:33:13 -05:00
|
|
|
import { groupBy } from 'lodash';
|
2021-11-30 03:53:31 -06:00
|
|
|
import React, { useMemo } from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-11-30 03:53:31 -06:00
|
|
|
import { MetadataInspectorProps } from '@grafana/data';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-11-30 03:53:31 -06:00
|
|
|
import { CloudWatchDatasource } from '../datasource';
|
|
|
|
import { CloudWatchQuery, CloudWatchJsonData } from '../types';
|
|
|
|
|
|
|
|
export type Props = MetadataInspectorProps<CloudWatchDatasource, CloudWatchQuery, CloudWatchJsonData>;
|
|
|
|
|
|
|
|
export function MetaInspector({ data = [] }: Props) {
|
|
|
|
const rows = useMemo(() => groupBy(data, 'refId'), [data]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<table className="filter-table form-inline">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>RefId</th>
|
|
|
|
<th>Metric Data Query ID</th>
|
|
|
|
<th>Metric Data Query Expression</th>
|
|
|
|
<th>Period</th>
|
|
|
|
<th />
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
{Object.entries(rows).map(([refId, frames], idx) => {
|
|
|
|
if (!frames.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const frame = frames[0];
|
|
|
|
const custom = frame.meta?.custom;
|
|
|
|
if (!custom) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tbody key={idx}>
|
|
|
|
<tr>
|
|
|
|
<td>{refId}</td>
|
|
|
|
<td>{custom.id}</td>
|
|
|
|
<td>{frame.meta?.executedQueryString}</td>
|
|
|
|
<td>{custom.period}</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</table>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|