(core) DocLimits: display days remaining instead of days of grace period

Summary:
Before this change we would always say there are 14 days remaining,
regardless of how many actually are remaining. Let's pass around a
different `dataLimitsInfo` object that also reports the number of days
remaining.

Test Plan: Ensure the test suite passes.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D4332
This commit is contained in:
Jordi Gutiérrez Hermoso
2024-08-27 21:27:59 -04:00
parent 8da89b0a3d
commit 80f8168cab
7 changed files with 40 additions and 30 deletions

View File

@@ -50,12 +50,12 @@ import {
UserAction
} from 'app/common/DocActions';
import {DocData} from 'app/common/DocData';
import {getDataLimitRatio, getDataLimitStatus, getSeverity, LimitExceededError} from 'app/common/DocLimits';
import {getDataLimitInfo, getDataLimitRatio, getSeverity, LimitExceededError} from 'app/common/DocLimits';
import {DocSnapshots} from 'app/common/DocSnapshot';
import {DocumentSettings} from 'app/common/DocumentSettings';
import {
APPROACHING_LIMIT_RATIO,
DataLimitStatus,
DataLimitInfo,
DocumentUsage,
DocUsageSummary,
FilteredDocUsageSummary,
@@ -421,8 +421,8 @@ export class ActiveDoc extends EventEmitter {
return getDataLimitRatio(this._docUsage, this._product?.features);
}
public get dataLimitStatus(): DataLimitStatus {
return getDataLimitStatus({
public get dataLimitInfo(): DataLimitInfo {
return getDataLimitInfo({
docUsage: this._docUsage,
productFeatures: this._product?.features,
gracePeriodStart: this._gracePeriodStart,
@@ -431,7 +431,7 @@ export class ActiveDoc extends EventEmitter {
public getDocUsageSummary(): DocUsageSummary {
return {
dataLimitStatus: this.dataLimitStatus,
dataLimitInfo: this.dataLimitInfo,
rowCount: this._docUsage?.rowCount ?? 'pending',
dataSizeBytes: this._docUsage?.dataSizeBytes ?? 'pending',
attachmentsSizeBytes: this._docUsage?.attachmentsSizeBytes ?? 'pending',
@@ -2176,7 +2176,7 @@ export class ActiveDoc extends EventEmitter {
await this.waitForInitialization();
if (
this.dataLimitStatus === "deleteOnly" &&
this.dataLimitInfo.status === "deleteOnly" &&
!actions.every(action => [
'RemoveTable', 'RemoveColumn', 'RemoveRecord', 'BulkRemoveRecord',
'RemoveViewSection', 'RemoveView', 'ApplyUndoActions', 'RespondToRequests',
@@ -2253,13 +2253,13 @@ export class ActiveDoc extends EventEmitter {
*/
private async _updateDocUsage(usage: Partial<DocumentUsage>, options: UpdateUsageOptions = {}) {
const {syncUsageToDatabase = true, broadcastUsageToClients = true} = options;
const oldStatus = this.dataLimitStatus;
const oldStatus = this.dataLimitInfo.status;
this._docUsage = {...(this._docUsage || {}), ...usage};
if (syncUsageToDatabase) {
/* If status decreased, we'll update usage in the database with minimal delay, so site usage
* banners show up-to-date statistics. If status increased or stayed the same, we'll schedule
* a delayed update, since it's less critical for banners to update immediately. */
const didStatusDecrease = getSeverity(this.dataLimitStatus) < getSeverity(oldStatus);
const didStatusDecrease = getSeverity(this.dataLimitInfo.status) < getSeverity(oldStatus);
this._syncDocUsageToDatabase(didStatusDecrease);
}
if (broadcastUsageToClients) {

View File

@@ -792,7 +792,7 @@ export class GranularAccess implements GranularAccessForBundle {
}
const role = options.role ?? await this.getNominalAccess(docSession);
const hasEditRole = canEdit(role);
if (!hasEditRole) { result.dataLimitStatus = null; }
if (!hasEditRole) { result.dataLimitInfo.status = null; }
const hasFullReadAccess = await this.canReadEverything(docSession);
if (!hasEditRole || !hasFullReadAccess) {
result.rowCount = 'hidden';