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
…2313)

Cherry-picked from #2152
Fixes DH-18184

Co-authored-by: Akshat Jawne <69530774+AkshatJawne@users.noreply.github.com>
  • Loading branch information
mofojed and AkshatJawne authored Dec 13, 2024
1 parent c44deae commit bb424d1
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 @@ -1040,7 +1040,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 @@ -1635,7 +1635,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 @@ -1647,12 +1651,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 @@ -1665,17 +1667,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 bb424d1

Please sign in to comment.