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

Ability to copy column header from ui #285

Merged
merged 4 commits into from
Nov 11, 2021
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
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