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: Input Tables cannot paste more rows than number of visible rows (DH-18184) #2369

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 1 addition & 10 deletions packages/grid/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,7 @@ class Grid extends PureComponent<GridProps, GridState> {
const { columnCount, rowCount } = model;
let ranges = selectedRanges;
// If each cell is a single selection, we need to update the selection to map to the newly pasted data
// Check for
if (
ranges.every(
range =>
Expand All @@ -1347,16 +1348,6 @@ class Grid extends PureComponent<GridProps, GridState> {
this.setSelectedRanges(ranges);
}

if (
!ranges.every(
range =>
GridRange.rowCount([range]) === tableHeight &&
GridRange.columnCount([range]) === tableWidth
)
) {
throw new PasteError('Copy and paste area are not same size.');
}

const edits: EditOperation[] = [];
ranges.forEach(range => {
for (let x = 0; x < tableWidth; x += 1) {
Expand Down
59 changes: 39 additions & 20 deletions packages/iris-grid/src/IrisGridTableModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ class IrisGridTableModel extends IrisGridModel {
this.handleTableUpdate = this.handleTableUpdate.bind(this);
this.handleTotalsUpdate = this.handleTotalsUpdate.bind(this);
this.handleRequestFailed = this.handleRequestFailed.bind(this);
this.handleCustomColumnsChanged = this.handleCustomColumnsChanged.bind(
this
);
this.handleCustomColumnsChanged =
this.handleCustomColumnsChanged.bind(this);
this.setViewport = throttle(
this.setViewport.bind(this),
SET_VIEWPORT_THROTTLE
Expand Down Expand Up @@ -654,7 +653,7 @@ class IrisGridTableModel extends IrisGridModel {
*/
pendingRow(y) {
const pendingRow = y - this.floatingTopRowCount - this.table.size;
if (pendingRow >= 0 && pendingRow < this.pendingNewRowCount) {
if (pendingRow >= 0) {
return pendingRow;
}

Expand Down Expand Up @@ -726,10 +725,8 @@ class IrisGridTableModel extends IrisGridModel {
const operationMap = this.totals?.operationMap;
for (let c = 0; c < columns.length; c += 1) {
const column = columns[c];
const [
name,
operation = operationMap?.[name]?.[0] ?? defaultOperation,
] = column.name.split('__');
const [name, operation = operationMap?.[name]?.[0] ?? defaultOperation] =
column.name.split('__');
if (!dataMap.has(operation)) {
dataMap.set(operation, { data: new Map() });
}
Expand Down Expand Up @@ -1260,18 +1257,40 @@ class IrisGridTableModel extends IrisGridModel {
}

isEditableRange(range) {
return (
this.inputTable != null &&
GridRange.isBounded(range) &&
((this.isPendingRow(range.startRow) && this.isPendingRow(range.endRow)) ||
(range.startColumn >= this.inputTable.keyColumns.length &&
range.endColumn >= this.inputTable.keyColumns.length)) &&
range.startRow >= this.floatingTopRowCount &&
range.startRow <
this.floatingTopRowCount + this.table.size + this.pendingRowCount &&
range.endRow <
this.floatingTopRowCount + this.table.size + this.pendingRowCount
);
// Make sure we have an input table and a valid range
if (
this.inputTable == null ||
range.startRow == null ||
range.endRow == null
) {
return false;
}

// Check that the edit is in the editable range
// If an input table has keyed columns, the non-key columns are always editable
// If an input table does not have key columns, it is append only and existing rows cannot be editable
// Pending rows are always editable
const isPendingRange =
this.isPendingRow(range.startRow) && this.isPendingRow(range.endRow);

let isKeyColumnInRange = false;

// Check if any of the columns in grid range are key columns
const bound = range.endColumn ?? this.table.size;
for (let column = range.startColumn; column <= bound; column += 1) {
if (this.isKeyColumn(column)) {
isKeyColumnInRange = true;
break;
}
}

if (
!(isPendingRange || (this.keyColumnSet.size !== 0 && !isKeyColumnInRange))
) {
return false;
}

return true;
}

isDeletableRange(range) {
Expand Down