Skip to content

Commit

Permalink
fix(database): incorrect row selection when changing row order (toeve…
Browse files Browse the repository at this point in the history
  • Loading branch information
zqran authored and Alkaidcc committed Jun 8, 2023
1 parent 29e4649 commit b5e73fa
Showing 1 changed file with 0 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import { styleMap } from 'lit/directives/style-map.js';
import type { DatabaseTableViewRowSelect } from '../../../../std.js';

type SelectionState = Pick<DatabaseTableViewRowSelect, 'databaseId' | 'rowIds'>;
type SelectionCache = {
left: number;
top: number;
height: number;
rowIds: string[];
};

@customElement('database-row-level-selection')
export class RowLevelSelection extends WithDisposable(LitElement) {
Expand All @@ -27,8 +21,6 @@ export class RowLevelSelection extends WithDisposable(LitElement) {
}
`;

private _selectionCache: SelectionCache | null = null;

@property()
container!: HTMLElement;

Expand Down Expand Up @@ -69,17 +61,6 @@ export class RowLevelSelection extends WithDisposable(LitElement) {

if (!startRow || !endRow) return hideStyles;

if (this._selectionCache) {
const { left, top, height, rowIds: cacheRowIds } = this._selectionCache;
if (isRowIdsSame(rowIds, cacheRowIds)) {
return styleMap({
left: `${left}px`,
top: `${top}px`,
height: `${height}px`,
});
}
}

const containerPos = this.container.getBoundingClientRect();
const { left, top } = startRow.getBoundingClientRect();

Expand All @@ -93,12 +74,6 @@ export class RowLevelSelection extends WithDisposable(LitElement) {
height: `${scaledHeight}px`,
});

this._selectionCache = {
left: scaledLeft,
top: scaledTop,
height: scaledHeight,
rowIds,
};
return styles;
};

Expand Down Expand Up @@ -146,8 +121,3 @@ function calcSelectionHeight(container: Element, rowIds: string[]) {
return acc + height;
}, 0);
}

function isRowIdsSame(rowIds: string[], rowIdsCache: string[]) {
// ids are in the same order, so a simplified comparison can be done
return rowIds.toString() === rowIdsCache.toString();
}

0 comments on commit b5e73fa

Please sign in to comment.