@grafana/ui
Version:
Grafana Components Library
57 lines (52 loc) • 2.38 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var jsxRuntime = require('react/jsx-runtime');
var css = require('@emotion/css');
var React = require('react');
var table = require('../../../utils/table.cjs');
var CellActions = require('../CellActions.cjs');
var DataLinksActionsTooltip = require('../DataLinksActionsTooltip.cjs');
var TableCellInspector = require('../TableCellInspector.cjs');
var cellUtils = require('../cellUtils.cjs');
;
function JSONViewCell(props) {
var _a;
const { cell, tableStyles, cellProps, field, row } = props;
const inspectEnabled = Boolean((_a = field.config.custom) == null ? void 0 : _a.inspect);
const txt = css.css({
cursor: "pointer",
fontFamily: "monospace"
});
let value = cell.value;
let displayValue = value;
if (typeof value === "string") {
try {
value = JSON.parse(value);
} catch (e) {
}
} else {
try {
displayValue = JSON.stringify(value, null, " ");
} catch (e) {
displayValue = void 0;
}
}
const links = table.getCellLinks(field, row) || [];
const [tooltipCoords, setTooltipCoords] = React.useState();
const { shouldShowLink, hasMultipleLinksOrActions } = cellUtils.getDataLinksActionsTooltipUtils(links);
const shouldShowTooltip = hasMultipleLinksOrActions && tooltipCoords !== void 0;
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...cellProps, className: inspectEnabled ? tableStyles.cellContainerNoOverflow : tableStyles.cellContainer, children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { className: css.cx(tableStyles.cellText, txt), onClick: cellUtils.tooltipOnClickHandler(setTooltipCoords), children: shouldShowLink ? DataLinksActionsTooltip.renderSingleLink(links[0], displayValue) : shouldShowTooltip ? /* @__PURE__ */ jsxRuntime.jsx(
DataLinksActionsTooltip.DataLinksActionsTooltip,
{
links,
value: displayValue,
coords: tooltipCoords,
onTooltipClose: () => setTooltipCoords(void 0)
}
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: tableStyles.cellText, children: displayValue }) }),
inspectEnabled && /* @__PURE__ */ jsxRuntime.jsx(CellActions.CellActions, { ...props, previewMode: TableCellInspector.TableCellInspectorMode.code })
] });
}
exports.JSONViewCell = JSONViewCell;
//# sourceMappingURL=JSONViewCell.cjs.map