mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Suggest correct table when converting to RefList
Summary: RecordSets now have new encoding and rendering analogous to Records: `['r', 'Table', [1, 2, 3]]` and `Table[[1, 2, 3]]`. Test Plan: Added to nbrowser/TypeChange.ts. Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2987
This commit is contained in:
@@ -50,6 +50,18 @@ export class Reference {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A ReferenceList represents a reference to a number of rows in a table. It is simply a pair of a string tableId
|
||||
* and a numeric array rowIds.
|
||||
*/
|
||||
export class ReferenceList {
|
||||
constructor(public tableId: string, public rowIds: number[]) {}
|
||||
|
||||
public toString(): string {
|
||||
return `${this.tableId}[[${this.rowIds}]]`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A RaisedException represents a formula error. It includes the exception name, message, and
|
||||
* optional details.
|
||||
@@ -140,6 +152,8 @@ export function encodeObject(value: unknown): CellValue {
|
||||
return null;
|
||||
} else if (value instanceof Reference) {
|
||||
return ['R', value.tableId, value.rowId];
|
||||
} else if (value instanceof ReferenceList) {
|
||||
return ['r', value.tableId, value.rowIds];
|
||||
} else if (value instanceof Date) {
|
||||
const timestamp = value.valueOf() / 1000;
|
||||
if ('timezone' in value) {
|
||||
@@ -185,6 +199,7 @@ export function decodeObject(value: CellValue): unknown {
|
||||
case 'L': return (args as CellValue[]).map(decodeObject);
|
||||
case 'O': return mapValues(args[0] as {[key: string]: CellValue}, decodeObject, {sort: true});
|
||||
case 'P': return new PendingValue();
|
||||
case 'r': return new ReferenceList(String(args[0]), args[1]);
|
||||
case 'R': return new Reference(String(args[0]), args[1]);
|
||||
case 'S': return new SkipValue();
|
||||
case 'C': return new CensoredValue();
|
||||
|
||||
Reference in New Issue
Block a user