Skip to content

The open alternative to Salesforce, designed for AI.

fix(billing): hide all operations option when a usage has a single operation (#26888)

Etienne9b9944ef6d3d
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitOperationTypes.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitOperationTypes.test.ts
index c12cebf864f..716510ffc86 100644
--- a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitOperationTypes.test.ts
+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitOperationTypes.test.ts
@@ -4,13 +4,16 @@ import {
UsageResourceType,
} from '~/generated-metadata/graphql';
-const buildDefinition = (allowedMeters: string[]) => ({
- __typename: 'UsageQuotaDefinition' as const,
- resourceType: UsageResourceType.AI,
- allowedOperationTypes: [
+const buildDefinition = (
+ allowedMeters: string[],
+ allowedOperationTypes: UsageOperationType[] = [
UsageOperationType.AI_CHAT_TOKEN,
UsageOperationType.WEB_SEARCH,
],
+) => ({
+ __typename: 'UsageQuotaDefinition' as const,
+ resourceType: UsageResourceType.AI,
+ allowedOperationTypes,
allowedSpenderTypes: ['workspace'],
allowedMeters,
});
@@ -34,4 +37,15 @@ describe('getUsageLimitOperationTypes', () => {
UsageOperationType.WEB_SEARCH,
]);
});
+
+ it('skips "all operations" when the resource has a single operation', () => {
+ expect(
+ getUsageLimitOperationTypes(
+ buildDefinition(
+ ['creditsUsedMicro', 'quantity'],
+ [UsageOperationType.WEB_SEARCH],
+ ),
+ ),
+ ).toEqual([UsageOperationType.WEB_SEARCH]);
+ });
});
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitOperationTypes.ts b/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitOperationTypes.ts
index 7198d5ccb18..8f4fbae37c7 100644
--- a/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitOperationTypes.ts
+++ b/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitOperationTypes.ts
@@ -9,6 +9,7 @@ type UsageLimitDefinition =
export const getUsageLimitOperationTypes = (
definition: UsageLimitDefinition,
): UsageOperationType[] =>
- definition.allowedMeters.includes('creditsUsedMicro')
+ definition.allowedMeters.includes('creditsUsedMicro') &&
+ definition.allowedOperationTypes.length > 1
? [UsageOperationType.ALL, ...definition.allowedOperationTypes]
: definition.allowedOperationTypes;