mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
75d979abdb
Summary: In a selector table, when a selected row is filtered out of view, linked widgets should update based on the newly selected row. There were a few bugs that contributed to this wrong behavior: - Gridview wasn't subscribing to the current row id, and the row with id 'new' was being converted to the first row - Cursor was keeping track of the currently selected row id, it was hiding a problem behind the proper rowIndex - Undo/redo somehow leveraged the wrong rowId from the cursor during the position restore. The `No data` text was also changed to be more meaningful. Test Plan: Added and updated. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3937
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import type {ViewFieldRec} from 'app/client/models/entities/ViewFieldRec';
|
|
import type {CellValue} from 'app/common/DocActions';
|
|
import type {TableData, UIRowId} from 'app/common/TableData';
|
|
|
|
/**
|
|
* The CopySelection class is an abstraction for a subset of currently selected cells.
|
|
* @param {Array} rowIds - row ids of the rows selected
|
|
* @param {Array} fields - MetaRowModels of the selected view fields
|
|
* @param {Object} options.rowStyle - an object that maps rowId to an object containing
|
|
* style options. i.e. { 1: { height: 20px } }
|
|
* @param {Object} options.colStyle - an object that maps colId to an object containing
|
|
* style options.
|
|
*/
|
|
export class CopySelection {
|
|
public readonly colIds = this.fields.map(f => f.colId());
|
|
public readonly colRefs = this.fields.map(f => f.colRef());
|
|
public readonly displayColIds = this.fields.map(f => f.displayColModel().colId());
|
|
public readonly rowStyle: {[r: number]: object}|undefined;
|
|
public readonly colStyle: {[c: string]: object}|undefined;
|
|
|
|
public readonly columns: Array<{
|
|
colId: string,
|
|
fmtGetter: (rowId: UIRowId) => string,
|
|
rawGetter: (rowId: UIRowId) => CellValue|undefined,
|
|
}>;
|
|
|
|
constructor(tableData: TableData, public readonly rowIds: UIRowId[], public readonly fields: ViewFieldRec[],
|
|
options: {
|
|
rowStyle?: {[r: number]: object},
|
|
colStyle?: {[c: string]: object},
|
|
}
|
|
) {
|
|
this.rowStyle = options.rowStyle;
|
|
this.colStyle = options.colStyle;
|
|
this.columns = fields.map((f, i) => {
|
|
const formatter = f.formatter();
|
|
const _fmtGetter = tableData.getRowPropFunc(this.displayColIds[i])!;
|
|
const _rawGetter = tableData.getRowPropFunc(this.colIds[i])!;
|
|
|
|
return {
|
|
colId: this.colIds[i],
|
|
fmtGetter: rowId => formatter.formatAny(_fmtGetter(rowId)),
|
|
rawGetter: rowId => _rawGetter(rowId)
|
|
};
|
|
});
|
|
}
|
|
|
|
public isCellSelected(rowId: UIRowId, colId: string): boolean {
|
|
return this.rowIds.includes(rowId) && this.colIds.includes(colId);
|
|
}
|
|
|
|
public onlyAddRowSelected(): boolean {
|
|
return this.rowIds.length === 1 && this.rowIds[0] === "new";
|
|
}
|
|
}
|