(core) hide long sequences of unchanged rows in diffs

Summary:
It can be hard to find changes, even when highlighted, in a table with many rows.  This diff replaces long sequences of unchanged rows with a row containing "..."s.

With daff, I found that it is important to do this for sequences of unchanged columns also, but not tackling that yet.

Test Plan: added test

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2666
This commit is contained in:
Paul Fitzpatrick
2020-11-18 10:54:23 -05:00
parent bc3a472324
commit c387fc4bce
10 changed files with 185 additions and 29 deletions

View File

@@ -7,10 +7,12 @@ import { CellValue } from 'app/plugin/GristData';
export { CellValue, RowRecord } from 'app/plugin/GristData';
// Part of a special CellValue used for comparisons, embedding several versions of a CellValue.
export type CellVersions =
{ parent: CellValue, remote: CellValue } |
{ parent: CellValue, local: CellValue } |
{ parent: CellValue, local: CellValue, remote: CellValue };
export interface AllCellVersions {
parent: CellValue;
remote: CellValue;
local: CellValue;
}
export type CellVersions = Partial<AllCellVersions>;
import map = require('lodash/map');

View File

@@ -17,6 +17,16 @@ interface ColData {
values: CellValue[];
}
/**
* An interface for a table with rows that may be skipped.
*/
export interface SkippableRows {
// If there may be skippable rows, return a function to test rowIds for keeping.
getKeepFunc(): undefined | ((rowId: number|"new") => boolean);
// Get a special row id which represents a skipped sequence of rows.
getSkipRowId(): number;
}
/**
* TableData class to maintain a single table's data.
*
@@ -24,7 +34,7 @@ interface ColData {
* represent it as column-wise arrays. (An early hope was to allow use of TypedArrays, but since
* types can be mixed, those are not used.)
*/
export class TableData extends ActionDispatcher {
export class TableData extends ActionDispatcher implements SkippableRows {
private _tableId: string;
private _isLoaded: boolean = false;
private _fetchPromise?: Promise<void>;
@@ -156,6 +166,16 @@ export class TableData extends ActionDispatcher {
return function(rowId: number|"new") { return rowId === "new" ? "new" : values[rowMap.get(rowId)!]; };
}
// By default, no rows are skippable, all are kept.
public getKeepFunc(): undefined | ((rowId: number|"new") => boolean) {
return undefined;
}
// By default, no special row id for skip rows is needed.
public getSkipRowId(): number {
throw new Error('no skip row id defined');
}
/**
* Returns the list of all rowIds in this table, in unspecified and unstable order. Equivalent
* to getColValues('id').
@@ -171,6 +191,13 @@ export class TableData extends ActionDispatcher {
return this._rowIdCol.slice(0).sort((a, b) => a - b);
}
/**
* Returns true if cells may contain multiple versions (e.g. in diffs).
*/
public mayHaveVersions() {
return false;
}
/**
* Returns the list of colIds in this table, including 'id'.
*/

View File

@@ -18,6 +18,7 @@ export const enum GristObjCode {
Dict = 'O',
DateTime = 'D',
Date = 'd',
Skip = 'S',
Reference = 'R',
Exception = 'E',
Pending = 'P',
@@ -119,6 +120,10 @@ export function isVersions(value: CellValue): value is [GristObjCode.Versions, C
return getObjCode(value) === GristObjCode.Versions;
}
export function isSkip(value: CellValue): value is [GristObjCode.Skip] {
return getObjCode(value) === GristObjCode.Skip;
}
/**
* Returns whether a value (as received in a DocAction) represents a list or is null,
* which is a valid value for list types in grist.
@@ -139,7 +144,7 @@ function isNumberOrNull(v: CellValue) { return isNumber(v) || v === null; }
function isBoolean(v: CellValue) { return typeof v === 'boolean' || v === 1 || v === 0; }
// These values are not regular cell values, even in a column of type Any.
const abnormalValueTypes: string[] = [GristObjCode.Exception, GristObjCode.Pending,
const abnormalValueTypes: string[] = [GristObjCode.Exception, GristObjCode.Pending, GristObjCode.Skip,
GristObjCode.Unmarshallable, GristObjCode.Versions];
function isNormalValue(value: CellValue) {