Skip to content

Commit

Permalink
fix: Input Tables cannot paste more rows than number of visible rows (#…
Browse files Browse the repository at this point in the history
…2152)

Resolves #2089
  • Loading branch information
AkshatJawne committed Jul 29, 2024
1 parent a2d5d5f commit 1d51585
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
11 changes: 1 addition & 10 deletions packages/grid/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,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 @@ -1518,16 +1519,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
27 changes: 9 additions & 18 deletions packages/iris-grid/src/IrisGridTableModelTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ class IrisGridTableModelTemplate<
*/
pendingRow(y: ModelIndex): ModelIndex | null {
const pendingRow = y - this.floatingTopRowCount - this.table.size;
if (pendingRow >= 0 && pendingRow < this.pendingNewRowCount) {
if (pendingRow >= 0) {
return pendingRow;
}

Expand Down Expand Up @@ -1633,7 +1633,11 @@ class IrisGridTableModelTemplate<

isEditableRange(range: GridRange): boolean {
// Make sure we have an input table and a valid range
if (this.inputTable == null || !GridRange.isBounded(range)) {
if (
this.inputTable == null ||
range.startRow == null ||
range.endRow == null
) {
return false;
}

Expand All @@ -1645,12 +1649,10 @@ class IrisGridTableModelTemplate<
this.isPendingRow(range.startRow) && this.isPendingRow(range.endRow);

let isKeyColumnInRange = false;
assertNotNull(range.startColumn);
// Check if any of the columns in grid range are key columns
for (
let column = range.startColumn;
column <= range.endColumn;
column += 1
) {
const bound = range.endColumn ?? this.table.size;
for (let column = range.startColumn; column <= bound; column += 1) {
if (this.isKeyColumn(column)) {
isKeyColumnInRange = true;
break;
Expand All @@ -1663,17 +1665,6 @@ class IrisGridTableModelTemplate<
return false;
}

// Editing the aggregations/totals which are floating above/below is not allowed
if (
range.startRow < this.floatingTopRowCount ||
range.startRow >=
this.floatingTopRowCount + this.table.size + this.pendingRowCount ||
range.endRow >=
this.floatingTopRowCount + this.table.size + this.pendingRowCount
) {
return false;
}

return true;
}

Expand Down

0 comments on commit 1d51585

Please sign in to comment.