Skip to content

Commit

Permalink
DH-11843: Ability to copy column header from ui (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmmcken authored Nov 11, 2021
1 parent 6ff69f8 commit 6a2eb64
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
37 changes: 32 additions & 5 deletions packages/iris-grid/src/ColumnStatistics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { LoadingSpinner } from '@deephaven/components';
import { dhFreeze, dhRefresh, vsLock } from '@deephaven/icons';
import {
Button,
ContextActionUtils,
LoadingSpinner,
} from '@deephaven/components';
import {
dhFreeze,
dhRefresh,
vsCopy,
vsLock,
vsPassFilled,
} from '@deephaven/icons';
import { PropTypes as APIPropTypes } from '@deephaven/jsapi-shim';
import Log from '@deephaven/log';
import { PromiseUtils } from '@deephaven/utils';
Expand Down Expand Up @@ -35,6 +45,7 @@ class ColumnStatistics extends Component {
this.handleError = this.handleError.bind(this);
this.handleGenerateStatistics = this.handleGenerateStatistics.bind(this);
this.handleStatistics = this.handleStatistics.bind(this);
this.handleCopyHeader = this.handleCopyHeader.bind(this);

this.cancelablePromise = null;

Expand All @@ -43,6 +54,7 @@ class ColumnStatistics extends Component {
loading: false,
statistics: null,
numRows: 0,
copied: false,
};
}

Expand All @@ -56,6 +68,10 @@ class ColumnStatistics extends Component {
}
}

handleCopyHeader() {
this.setState({ copied: true });
}

maybeGenerateStatistics() {
const { model } = this.props;

Expand Down Expand Up @@ -128,7 +144,7 @@ class ColumnStatistics extends Component {

render() {
const { column, model } = this.props;
const { error, loading, statistics, numRows } = this.state;
const { error, loading, statistics, numRows, copied } = this.state;
const showGenerateStatistics =
!loading &&
error == null &&
Expand Down Expand Up @@ -164,8 +180,19 @@ class ColumnStatistics extends Component {
return (
<div className="column-statistics">
<div className="column-statistics-title">
{column.name}&nbsp;
<span className="column-statistics-type">({columnType})</span>
{column.name}
<span className="column-statistics-type">&nbsp;({columnType})</span>
<Button
kind="ghost"
className="column-statistics-copy"
icon={copied ? vsPassFilled : vsCopy}
onClick={() => {
ContextActionUtils.copyToClipboard(column.name)
.then(this.handleCopyHeader)
.catch(e => log.error('Unable to column name', e));
}}
tooltip={copied ? 'Copied text' : 'Copy column name'}
/>
</div>
{description && (
<div className="column-statistics-description">{description}</div>
Expand Down
5 changes: 5 additions & 0 deletions packages/iris-grid/src/ColumnStatistics.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
}

.column-statistics-title {
padding-top: $spacer-1;
font-weight: 500;
.column-statistics-copy {
margin-left: 2px;
margin-top: -2px;
}
}

.column-statistics-type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ class IrisGridColumnTooltipMouseHandler extends GridMouseHandler {
const theme = this.irisGrid.getTheme();
let newTooltip = null;
if (column !== null && row === null) {
if (y >= 0 && y <= theme.columnHeaderHeight - 2) {
// -2 account for borders
/**
* one would expect at y == theme.columnHeaderHeight, row == null
* however, gridY also == theme.columnHeaderHeight, so row still has a value
* so this tooltip won't actually show until row is null at columnHeaderHeight - 1
*/
if (y >= 0 && y <= theme.columnHeaderHeight) {
newTooltip = column;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ class IrisGridContextMenuHandler extends GridMouseHandler {
}
},
});
actions.push({
title: 'Copy Column Name',
group: IrisGridContextMenuHandler.GROUP_COPY,
action: () => {
ContextActionUtils.copyToClipboard(
model.textForColumnHeader(modelColumn)
).catch(e => log.error('Unable to copy header', e));
},
});

if (TableUtils.isDateType(column.type)) {
actions.push({
Expand Down

0 comments on commit 6a2eb64

Please sign in to comment.