Skip to content

Commit 57a0c9d

Browse files
committed
add warnings about plan preset mismatches
1 parent cc23218 commit 57a0c9d

File tree

1 file changed

+58
-11
lines changed

1 file changed

+58
-11
lines changed

frontend/src/features/admin/org-quota-editor.ts

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ export class OrgQuotaEditor extends BtrixElement {
147147
width: "1fr",
148148
renderCell: ({ item: { key, initialValue } }) =>
149149
html`<span class="text-xs text-neutral-600"
150-
>${this.format(initialValue, LABELS[key].type, true)}</span
150+
>${this.format(initialValue, LABELS[key].type, {
151+
asNumber: true,
152+
})}</span
151153
>`,
152154
},
153155
{
@@ -202,7 +204,9 @@ export class OrgQuotaEditor extends BtrixElement {
202204
width: "1fr",
203205
renderCell: ({ item: { key, currentValue: current } }) =>
204206
html`<span class="cursor-not-allowed"
205-
>${this.format(current, LABELS[key].type, true)}</span
207+
>${this.format(current, LABELS[key].type, {
208+
asNumber: true,
209+
})}</span
206210
>`,
207211
renderEditCell: ({ item, value: _value }) => {
208212
const key = item.key;
@@ -251,6 +255,11 @@ export class OrgQuotaEditor extends BtrixElement {
251255
maxPagesPerCrawl: org_quotas.maxPagesPerCrawl,
252256
storageQuota: org_quotas.storageQuota,
253257
};
258+
const mismatchesCurrentPlan =
259+
isCurrentSubscription &&
260+
(Object.entries(presets) as Entries<typeof presets>).some(
261+
([k, v]) => v !== quotas[k],
262+
);
254263
return html`<btrix-popover placement="top">
255264
<sl-button
256265
@click=${() => {
@@ -271,6 +280,13 @@ export class OrgQuotaEditor extends BtrixElement {
271280
slot="prefix"
272281
></sl-icon>`
273282
: null}
283+
${mismatchesCurrentPlan
284+
? html`<sl-icon
285+
name="exclamation-triangle"
286+
slot="suffix"
287+
class="text-warning-600"
288+
></sl-icon>`
289+
: null}
274290
</sl-button>
275291
<div slot="content">
276292
<header class="mb-2 font-medium">
@@ -289,18 +305,38 @@ export class OrgQuotaEditor extends BtrixElement {
289305
<tbody>
290306
${(
291307
Object.entries(presets) as Entries<typeof presets>
292-
).map(
293-
([key, value]) => html`
308+
).map(([key, value]) => {
309+
const currentValue = this.format(
310+
quotas[key],
311+
LABELS[key].type,
312+
{ plain: true },
313+
);
314+
return html`
294315
<tr>
295316
<td class="pr-2">${LABELS[key].label}</td>
296317
<td class="pr-2">
297318
${this.format(value, LABELS[key].type)}
319+
${mismatchesCurrentPlan &&
320+
value !== quotas[key]
321+
? html`<span class="text-warning-600"
322+
>(${msg(
323+
html`currently ${currentValue}`,
324+
)})</span
325+
>`
326+
: null}
298327
</td>
299328
</tr>
300-
`,
301-
)}
329+
`;
330+
})}
302331
</tbody>
303332
</table>
333+
${mismatchesCurrentPlan
334+
? html`<p class="mt-2 font-semibold text-warning-600">
335+
${msg(
336+
"Quotas for this org do not match its current plan.",
337+
)}
338+
</p>`
339+
: null}
304340
</div>
305341
</btrix-popover>`;
306342
}),
@@ -353,12 +389,23 @@ export class OrgQuotaEditor extends BtrixElement {
353389
</btrix-dialog>`;
354390
}
355391

356-
private format(v: number, type: "bytes" | "number", isInitialValue = true) {
357-
if (v <= 0)
358-
return isInitialValue
359-
? html`<span class="text-xs text-neutral-600">${msg("Unset")}</span>`
360-
: html`<span class="text-xs text-neutral-400">${msg("0")}</span>`;
392+
private format(
393+
v: number,
394+
type: "bytes" | "number",
395+
options: { plain?: boolean; asNumber?: boolean } = {},
396+
) {
397+
const { plain, asNumber } = options;
361398
const fn = type === "bytes" ? this.localize.bytes : this.localize.number;
399+
if (plain) {
400+
if (v <= 0) {
401+
return asNumber ? fn(0) : msg("Unset");
402+
}
403+
return fn(v);
404+
}
405+
if (v <= 0)
406+
return asNumber
407+
? html`<span class="text-xs text-neutral-400">${fn(0)}</span>`
408+
: html`<span class="text-xs text-neutral-600">${msg("Unset")}</span>`;
362409
return fn(v);
363410
}
364411

0 commit comments

Comments
 (0)