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

fix: raw value of read-only date field in data browser cannot be copied #2326

Merged
merged 7 commits into from
Oct 15, 2022
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
97 changes: 32 additions & 65 deletions src/components/BrowserCell/BrowserCell.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Pill from 'components/Pill/Pill.react';
import React, { Component } from 'react';
import styles from 'components/BrowserCell/BrowserCell.scss';
import baseStyles from 'stylesheets/base.scss';
import Tooltip from '../Tooltip/PopperTooltip.react';
import * as ColumnPreferences from 'lib/ColumnPreferences';

export default class BrowserCell extends Component {
Expand Down Expand Up @@ -388,8 +387,7 @@ export default class BrowserCell extends Component {
//#endregion

render() {
let { type, value, hidden, width, current, onSelect, onEditChange, setCopyableValue, onPointerCmdClick, row, col, field, onEditSelectedRow, readonly, isRequired, markRequiredFieldRow } = this.props;
let isNewRow = row < 0;
let { type, value, hidden, width, current, onSelect, onEditChange, setCopyableValue, onPointerCmdClick, row, col, field, onEditSelectedRow, isRequired, markRequiredFieldRow } = this.props;

let classes = [...this.state.classes];

Expand All @@ -400,68 +398,37 @@ export default class BrowserCell extends Component {
classes.push(styles.required);
}

return readonly ? (
<Tooltip placement='bottom' tooltip='Read only (CTRL+C to copy)' visible={this.state.showTooltip}>
<span
ref={this.cellRef}
className={classes.join(' ')}
style={{ width }}
onClick={(e) => {
if (e.metaKey === true && type === 'Pointer') {
onPointerCmdClick(value);
} else {
onSelect({ row, col });
setCopyableValue(hidden ? undefined : this.copyableValue);
}
}}
onDoubleClick={() => {
if (field === 'objectId' && onEditSelectedRow) {
onEditSelectedRow(true, value);
} else {
this.setState({ showTooltip: true });
setTimeout(() => {
this.setState({ showTooltip: false });
}, 2000);
}
}}
onContextMenu={this.onContextMenu}
>
{row < 0 || isNewRow ? '(auto)' : this.state.content}
</span>
</Tooltip>
) : (
<span
ref={this.cellRef}
className={classes.join(' ')}
style={{ width }}
onClick={(e) => {
if (e.metaKey === true && type === 'Pointer') {
onPointerCmdClick(value);
}
else {
onSelect({ row, col });
setCopyableValue(hidden ? undefined : this.copyableValue);
}
}}
onDoubleClick={() => {
// Since objectId can't be edited, double click event opens edit row dialog
if (field === 'objectId' && onEditSelectedRow) {
onEditSelectedRow(true, value);
} else if (type !== 'Relation') {
onEditChange(true)
return <span
ref={this.cellRef}
className={classes.join(' ')}
style={{ width }}
onClick={(e) => {
if (e.metaKey === true && type === 'Pointer') {
onPointerCmdClick(value);
}
else {
onSelect({ row, col });
setCopyableValue(hidden ? undefined : this.copyableValue);
}
}}
onDoubleClick={() => {
// Since objectId can't be edited, double click event opens edit row dialog
if (field === 'objectId' && onEditSelectedRow) {
onEditSelectedRow(true, value);
} else if (type !== 'Relation') {
onEditChange(true)
}
}}
onTouchEnd={e => {
if (current && type !== 'Relation') {
// The touch event may trigger an unwanted change in the column value
if (['ACL', 'Boolean', 'File'].includes(type)) {
e.preventDefault();
}
}}
onTouchEnd={e => {
if (current && type !== 'Relation') {
// The touch event may trigger an unwanted change in the column value
if (['ACL', 'Boolean', 'File'].includes(type)) {
e.preventDefault();
}
}}}
onContextMenu={this.onContextMenu.bind(this)}
>
{this.state.content}
</span>
);
}}}
onContextMenu={this.onContextMenu.bind(this)}
>
{this.state.content}
</span>
}
}
4 changes: 4 additions & 0 deletions src/components/BrowserCell/BrowserCell.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@
bottom: 0;
}
}

.readonly {
color: #04263bd1;
}
10 changes: 8 additions & 2 deletions src/components/StringEditor/StringEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ export default class StringEditor extends React.Component {
}

render() {
let classes = [styles.editor];
let onChange = this.props.readonly ? () => {} : (e) => this.setState({ value: e.target.value });
if (this.props.readonly) {
classes.push(styles.readonly)
}

if (this.props.multiline) {
var style = { minWidth: this.props.minWidth };
if (this.props.resizable) {
Expand All @@ -66,11 +71,12 @@ export default class StringEditor extends React.Component {
);
}
return (
<div style={{ width: this.props.width }} className={styles.editor}>
<div style={{ width: this.props.width }} className={classes.join(' ')}>
<input
ref={this.inputRef}
value={this.state.value}
onChange={onChange} />
onChange={onChange}
disabled={this.props.readonly} />
</div>
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/components/StringEditor/StringEditor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
font-size: 12px;
}

&.readonly {
box-shadow: 0px 0px 2px 1px rgb(0 0 0 / 20%);
}

input:disabled {
background-color: #f2f2f2;
color: #666;
}

textarea {
@include MonospaceFont;
width: 200px;
Expand Down