Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New optional Mesa inline table behaviour using tooltips #1115

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default function TreeTable<RowType>(props: TreeTableProps<RowType>) {
...props.tableProps.options,
deriveRowClassName: (_) => rowStyleClassName,
inline: true,
inlineUseTooltips: true,
inlineMaxHeight: `${rowHeight}px`,
inlineMaxWidth: `${maxColumnWidth}px`,
},
Expand Down
26 changes: 25 additions & 1 deletion packages/libs/coreui/src/components/Mesa/Ui/DataCell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
import Templates from '../Templates';
import { makeClassifier } from '../Utils/Utils';

import { Tooltip } from '../../../components/info/Tooltip';

const dataCellClass = makeClassifier('DataCell');

class DataCell extends React.PureComponent {
Expand Down Expand Up @@ -64,7 +66,29 @@ class DataCell extends React.PureComponent {
width = width ? { width, maxWidth: width, minWidth: width } : {};
style = Object.assign({}, style, width, whiteSpace);
className = dataCellClass() + (className ? ' ' + className : '');
const children = this.renderContent();

const content = this.renderContent();
const columnName = column.name ?? column.key;

// Ideally the tooltip would also be conditional on there
// being actual content, but this is not trivial without
// copy-pasting the getValue logic from this.renderContent().
// Verdict: not worth it
const children = options.inlineUseTooltips ? (
<Tooltip
title={
<>
{columnName && <span>{columnName}:</span>}
{content}
</>
}
>
{content}
</Tooltip>
) : (
content
);

const props = {
style,
children,
Expand Down
10 changes: 5 additions & 5 deletions packages/libs/coreui/src/components/Mesa/Ui/DataRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ class DataRow extends React.PureComponent {

expandRow() {
const { options } = this.props;
if (!options.inline) return;
if (!options.inline || options.inlineUseTooltips) return;
this.setState({ expanded: true });
}

collapseRow() {
const { options } = this.props;
if (!options.inline) return;
if (!options.inline || options.inlineUseTooltips) return;
this.setState({ expanded: false });
}

handleRowClick() {
const { row, rowIndex, options } = this.props;
const { inline, onRowClick } = options;
const { inline, onRowClick, inlineUseTooltips } = options;
if (!inline && !onRowClick) return;

if (inline) this.setState({ expanded: !this.state.expanded });
if (inline && !inlineUseTooltips)
this.setState({ expanded: !this.state.expanded });
if (typeof onRowClick === 'function') onRowClick(row, rowIndex);
}

Expand Down
1 change: 1 addition & 0 deletions packages/libs/coreui/src/components/Mesa/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface MesaStateProps<
inline?: boolean;
inlineMaxWidth?: string;
inlineMaxHeight?: string;
inlineUseTooltips?: boolean; // don't use onClick to show the full contents, use an onMouseOver tooltip instead
className?: string;
errOnOverflow?: boolean;
editableColumns?: boolean;
Expand Down
Loading