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: Unable to delete selected rows in some input tables #1678

Merged
merged 1 commit into from
Dec 8, 2023
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
29 changes: 20 additions & 9 deletions packages/iris-grid/src/IrisGridTableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,29 @@ class IrisGridTableModel extends IrisGridTableModelTemplate<Table, UIRow> {
if (tableRanges.length <= 0) {
return;
}

const [data, deleteTable] = await Promise.all([
// Need to get the key values of each row
this.snapshot(
tableRanges.map(range => {
assertNotNull(range);
return new GridRange(
0,
range.startRow,
keyColumns.length - 1,
range.endRow
);
})
tableRanges
.map(range => {
assertNotNull(range);
// Need to map each key column to it's range so we can pass that into the snapshot function
return keyColumns.map(keyColumn => {
const keyIndex = this.getColumnIndexByName(keyColumn.name);
if (keyIndex == null) {
throw new Error(`Key column ${keyColumn.name} not found`);
}

return new GridRange(
keyIndex,
range.startRow,
keyIndex,
range.endRow
);
});
})
.flat()
),
this.table.copy(),
]);
Expand Down
90 changes: 1 addition & 89 deletions packages/iris-grid/src/IrisGridTableModelTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2086,95 +2086,7 @@ class IrisGridTableModelTemplate<
}

async delete(ranges: GridRange[]): Promise<void> {
if (!this.isDeletableRanges(ranges)) {
throw new Error(`Undeletable ranges ${ranges}`);
}

assertNotNull(this.inputTable);
const { keyColumns } = this.inputTable;
if (keyColumns.length === 0) {
throw new Error('No key columns to allow deletion');
}

const pendingAreaRange = this.getPendingAreaRange();
const pendingRanges = ranges
.map(range => GridRange.intersection(pendingAreaRange, range))
.filter(range => range != null)
.map(range => {
assertNotNull(range);

return GridRange.offset(
range,
0,
-(this.floatingTopRowCount + this.table.size)
);
});

if (pendingRanges.length > 0) {
const newDataMap = new Map(this.pendingNewDataMap);
for (let i = 0; i < pendingRanges.length; i += 1) {
const pendingRange = pendingRanges[i];
assertNotNull(pendingRange.startRow);
assertNotNull(pendingRange.endRow);
for (let r = pendingRange.startRow; r <= pendingRange.endRow; r += 1) {
newDataMap.delete(r);
}
}
this.pendingNewDataMap = newDataMap;

this.formattedStringData = [];

this.dispatchEvent(
new EventShimCustomEvent(IrisGridModel.EVENT.PENDING_DATA_UPDATED)
);

this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
}

const tableAreaRange = this.getTableAreaRange();
const tableRanges = ranges
.map(range => GridRange.intersection(tableAreaRange, range))
.filter(range => range != null);
if (tableRanges.length <= 0) {
return;
}
const [data, deleteTable] = await Promise.all([
// Need to get the key values of each row
this.snapshot(
tableRanges.map(range => {
assertNotNull(range);
return new GridRange(
0,
range.startRow,
keyColumns.length - 1,
range.endRow
);
})
),
this.table.copy(),
]);

// Now copy the existing table and filter it on the values in the snapshot for the key columns in the input table
const filters = data.map(row => {
const columnFilters = [];
for (let c = 0; c < keyColumns.length; c += 1) {
const column = keyColumns[c];
const value = row[c];
const filterValue = this.tableUtils.makeFilterRawValue(
column.type,
value
);
const filter = column.filter().eq(filterValue);
columnFilters.push(filter);
}
return columnFilters.reduce((agg, curr) => agg?.and(curr) ?? curr);
});

const filter = filters.reduce((agg, curr) => agg?.or(curr) ?? curr);
deleteTable.applyFilter([filter]);

// await this.inputTable?.deleteTable(deleteTable);
deleteTable.close();
throw new Error('Delete not implemented');
}

isValidForCell(x: ModelIndex, y: ModelIndex, value: string): boolean {
Expand Down
Loading