gristlabs_grist-core/app/common/DocListAPI.ts
Alex Hall 02e69fb685 (core) Crudely show row count and limit in UI
Summary:
Add rowCount returned from sandbox when applying user actions to ActionGroup which is broadcast to clients.

Add rowCount to ActiveDoc and update it after applying user actions.

Add rowCount to OpenLocalDocResult using ActiveDoc value, to show when a client opens a doc before any user actions happen.

Add rowCount observable to DocPageModel which is set when the doc is opened and when action groups are received.

Add crude UI (commented out) in Tool.ts showing the row count and the limit in AppModel.currentFeatures. The actual UI doesn't have a place to go yet.

Followup tasks:

- Real, pretty UI
- Counts per table
- Keep count(s) secret from users with limited access?
- Data size indicator?
- Banner when close to or above limit
- Measure row counts outside of sandbox to avoid spoofing with formula
- Handle changes to the limit when the plan is changed or extra rows are purchased

Test Plan: Tested UI manually, including with free team site, opening a fresh doc, opening an initialised doc, adding rows, undoing, and changes from another tab. Automated tests seem like they should wait for a proper UI.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3318
2022-03-14 21:49:32 +02:00

94 lines
2.8 KiB
TypeScript

import {MinimalActionGroup} from 'app/common/ActionGroup';
import {TableDataAction} from 'app/common/DocActions';
import {Role} from 'app/common/roles';
import {StringUnion} from 'app/common/StringUnion';
import {FullUser} from 'app/common/UserAPI';
// Possible flavors of items in a list of documents.
export type DocEntryTag = ''|'sample'|'invite'|'shared';
export const OpenDocMode = StringUnion(
'default', // open doc with user's maximal access level
'view', // open doc limited to view access (if user has at least that level of access)
'fork', // as for 'view', but suggest a fork on any attempt to edit - the client will
// enable the editing UI experience and trigger a fork on any edit.
);
export type OpenDocMode = typeof OpenDocMode.type;
/**
* Represents an entry in the DocList.
*/
export interface DocEntry {
docId?: string; // Set for shared docs and invites
name: string;
mtime?: Date;
size?: number;
tag: DocEntryTag;
senderName?: string;
senderEmail?: string;
}
export interface DocCreationInfo {
id: string;
title: string;
}
/**
* This documents the members of the structure returned when a local
* grist document is opened.
*/
export interface OpenLocalDocResult {
docFD: number;
clientId: string; // the docFD is meaningful only in the context of this session
doc: {[tableId: string]: TableDataAction};
log: MinimalActionGroup[];
recoveryMode?: boolean;
userOverride?: UserOverride;
rowCount?: number;
}
export interface UserOverride {
user: FullUser|null;
access: Role|null;
}
export interface DocListAPI {
/**
* Returns a all known Grist documents and document invites to show in the doc list.
*/
getDocList(): Promise<{docs: DocEntry[], docInvites: DocEntry[]}>;
/**
* Creates a new document, fetches it, and adds a table to it. Returns its name.
*/
createNewDoc(): Promise<string>;
/**
* Makes a copy of the given sample doc. Returns the name of the new document.
*/
importSampleDoc(sampleDocName: string): Promise<string>;
/**
* Processes an upload, containing possibly multiple files, to create a single new document, and
* returns the new document's name.
*/
importDoc(uploadId: number): Promise<string>;
/**
* Deletes a Grist document. Returns the name of the deleted document. If `deletePermanently` is
* true, the doc is deleted permanently rather than just moved to the trash.
*/
deleteDoc(docName: string, deletePermanently: boolean): Promise<string>;
/**
* Renames a document.
*/
renameDoc(oldName: string, newName: string): Promise<void>;
/**
* Opens a document, loads it, subscribes to its userAction events, and returns its metadata.
*/
openDoc(userDocName: string, openMode?: OpenDocMode,
linkParameters?: Record<string, string>): Promise<OpenLocalDocResult>;
}