diff --git a/packages/iris-grid/src/IrisGridTableModel.ts b/packages/iris-grid/src/IrisGridTableModel.ts index 900d9eecdb..1d99694591 100644 --- a/packages/iris-grid/src/IrisGridTableModel.ts +++ b/packages/iris-grid/src/IrisGridTableModel.ts @@ -271,18 +271,29 @@ class IrisGridTableModel extends IrisGridTableModelTemplate { 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(), ]); diff --git a/packages/iris-grid/src/IrisGridTableModelTemplate.ts b/packages/iris-grid/src/IrisGridTableModelTemplate.ts index b5796d9f66..26578c8e9f 100644 --- a/packages/iris-grid/src/IrisGridTableModelTemplate.ts +++ b/packages/iris-grid/src/IrisGridTableModelTemplate.ts @@ -2086,95 +2086,7 @@ class IrisGridTableModelTemplate< } async delete(ranges: GridRange[]): Promise { - 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 {