(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

@@ -7,7 +7,7 @@ import {withInfoTooltip} from 'app/client/ui/tooltips';
import {mediaXSmall, theme} from 'app/client/ui2018/cssVars';
import {icon} from 'app/client/ui2018/icons';
import {loadingDots, loadingSpinner} from 'app/client/ui2018/loaders';
import {APPROACHING_LIMIT_RATIO, DataLimitStatus} from 'app/common/DocUsage';
import {APPROACHING_LIMIT_RATIO, DataLimitInfo} from 'app/common/DocUsage';
import {Features, isFreePlan} from 'app/common/Features';
import {capitalizeFirstWord} from 'app/common/gutil';
import {canUpgradeOrg} from 'app/common/roles';
@@ -40,8 +40,8 @@ export class DocumentUsage extends Disposable {
// TODO: Update this whenever the rest of the UI is internationalized.
private readonly _rowCountFormatter = new Intl.NumberFormat('en-US');
private readonly _dataLimitStatus = Computed.create(this, this._currentDocUsage, (_use, usage) => {
return usage?.dataLimitStatus ?? null;
private readonly _dataLimitInfo = Computed.create(this, this._currentDocUsage, (_use, usage) => {
return usage?.dataLimitInfo;
});
private readonly _rowCount = Computed.create(this, this._currentDocUsage, (_use, usage) => {
@@ -158,11 +158,11 @@ export class DocumentUsage extends Disposable {
const org = use(this._currentOrg);
const product = use(this._currentProduct);
const features = use(this._currentFeatures);
const status = use(this._dataLimitStatus);
if (!org || !status) { return null; }
const usageInfo = use(this._dataLimitInfo);
if (!org || !usageInfo?.status) { return null; }
return buildMessage([
buildLimitStatusMessage(status, features, {
buildLimitStatusMessage(usageInfo, features, {
disableRawDataLink: true
}),
(product && isFreePlan(product.name)
@@ -196,13 +196,14 @@ export class DocumentUsage extends Disposable {
}
export function buildLimitStatusMessage(
status: NonNullable<DataLimitStatus>,
usageInfo: NonNullable<DataLimitInfo>,
features?: Features|null,
options: {
disableRawDataLink?: boolean;
} = {}
) {
const {disableRawDataLink = false} = options;
const {status, daysRemaining} = usageInfo;
switch (status) {
case 'approachingLimit': {
return [
@@ -224,7 +225,7 @@ export function buildLimitStatusMessage(
return [
'Document limits ',
disableRawDataLink ? 'exceeded' : buildRawDataPageLink('exceeded'),
`. In ${gracePeriodDays} days, this document will be read-only.`
`. In ${daysRemaining} days, this document will be read-only.`
];
}
case 'deleteOnly': {