(core) Add attachment and data size usage

Summary:
Adds attachment and data size to the usage section of
the raw data page. Also makes in-document usage banners
update as user actions are applied, causing them to be
hidden/shown or updated based on the current state of
the document.

Test Plan: Browser tests.

Reviewers: jarek

Reviewed By: jarek

Subscribers: alexmojaki

Differential Revision: https://phab.getgrist.com/D3395
This commit is contained in:
George Gevoian
2022-05-02 22:20:31 -07:00
parent f194d6861b
commit 1e42871cc9
18 changed files with 381 additions and 155 deletions

View File

@@ -25,5 +25,4 @@ export interface ActionGroup extends MinimalActionGroup {
user: string;
primaryAction: string; // The name of the first user action in the ActionGroup.
internal: boolean; // True if it is inappropriate to log/undo the action.
rowCount?: number;
}

View File

@@ -1,8 +1,8 @@
import {MinimalActionGroup} from 'app/common/ActionGroup';
import {TableDataAction} from 'app/common/DocActions';
import {DocUsage} from 'app/common/DocUsage';
import {Role} from 'app/common/roles';
import {StringUnion} from 'app/common/StringUnion';
import {DataLimitStatus, RowCount} from 'app/common/Usage';
import {FullUser} from 'app/common/UserAPI';
// Possible flavors of items in a list of documents.
@@ -43,10 +43,9 @@ export interface OpenLocalDocResult {
clientId: string; // the docFD is meaningful only in the context of this session
doc: {[tableId: string]: TableDataAction};
log: MinimalActionGroup[];
rowCount: RowCount;
recoveryMode?: boolean;
userOverride?: UserOverride;
dataLimitStatus?: DataLimitStatus;
docUsage?: DocUsage;
}
export interface UserOverride {

29
app/common/DocUsage.ts Normal file
View File

@@ -0,0 +1,29 @@
import {ApiError} from 'app/common/ApiError';
export interface DocUsage {
dataLimitStatus: DataLimitStatus;
rowCount: RowCount;
dataSizeBytes: DataSize;
attachmentsSizeBytes: AttachmentsSize;
}
type NumberOrStatus = number | 'hidden' | 'pending';
export type RowCount = NumberOrStatus;
export type DataSize = NumberOrStatus;
export type AttachmentsSize = NumberOrStatus;
export type DataLimitStatus = 'approachingLimit' | 'gracePeriod' | 'deleteOnly' | null;
export type NonHidden<T> = Exclude<T, 'hidden'>;
// Ratio of usage at which we start telling users that they're approaching limits.
export const APPROACHING_LIMIT_RATIO = 0.9;
export class LimitExceededError extends ApiError {
constructor(message: string) {
super(message, 413);
}
}

View File

@@ -1,6 +0,0 @@
export type RowCount = number | 'hidden' | 'pending';
export type DataLimitStatus = null | 'approachingLimit' | 'gracePeriod' | 'deleteOnly';
// Ratio of the row/data size limit where we tell users that they're approaching the limit.
export const APPROACHING_LIMIT_RATIO = 0.9;

View File

@@ -935,3 +935,16 @@ export function assertIsDefined<T>(name: string, value: T): asserts value is Non
throw new Error(`Expected '${name}' to be defined, but received ${value}`);
}
}
/**
* Calls function `fn`, passes any thrown errors to function `recover`, and finally calls `fn`
* once more if `recover` doesn't throw.
*/
export async function retryOnce<T>(fn: () => Promise<T>, recover: (e: unknown) => Promise<void>): Promise<T> {
try {
return await fn();
} catch (e) {
await recover(e);
return await fn();
}
}