@deephaven/js-plugin-ag-grid
Version:
Deephaven AG Grid plugin
30 lines • 2.48 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback } from 'react';
import classNames from 'classnames';
import { TREE_NODE_KEY } from '../utils/AgGridTableUtils';
import DeephavenViewportDatasource from '../datasources/DeephavenViewportDatasource';
export function TreeCellRenderer(props) {
const { node, datasource, api } = props;
const { data } = node;
const treeNode = data === null || data === void 0 ? void 0 : data[TREE_NODE_KEY];
const { hasChildren = false, depth = 0, isExpanded = false } = treeNode !== null && treeNode !== void 0 ? treeNode : {};
const handleClick = useCallback(() => {
if (treeNode != null && datasource instanceof DeephavenViewportDatasource) {
datasource.setExpanded(treeNode.index, !treeNode.isExpanded);
}
}, [datasource, treeNode]);
const rowGroupColumns = api.getRowGroupColumns();
// If we're on a leaf row, show the last row group column as the group name instead of an empty string.
const colDef = rowGroupColumns[hasChildren ? depth - 2 : rowGroupColumns.length - 1];
const colId = colDef === null || colDef === void 0 ? void 0 : colDef.getId();
const groupName = data === null || data === void 0 ? void 0 : data[colId];
// This mimics the structure of the default AG Grid group cell renderer... wish we could just provide the groups/depth information to AG Grid directly, but this seems to be the only way.
const indentLevel = Math.max(0, depth - 1);
return (_jsxs("span", { className: classNames('ag-cell-wrapper', { 'ag-cell-expandable': hasChildren }, hasChildren ? 'ag-row-group' : 'ag-row-group-leaf-indent'), style: { '--ag-indentation-level': indentLevel }, children: [hasChildren && (_jsxs(_Fragment, { children: [_jsx("span", { className: classNames('ag-group-expanded', {
'ag-hidden': !isExpanded,
}), children: _jsx("span", { className: "ag-icon ag-icon-tree-open", role: "presentation", onClick: handleClick }) }), _jsx("span", { className: classNames('ag-group-contracted', {
'ag-hidden': isExpanded,
}), children: _jsx("span", { className: "ag-icon ag-icon-tree-closed", role: "presentation", onClick: handleClick }) })] })), _jsx("span", { className: "ag-group-value", children: groupName })] }));
}
export default TreeCellRenderer;
//# sourceMappingURL=TreeCellRenderer.js.map