Skip to content

Commit 3e04acd

Browse files
committed
fix(plugins): address multiple minor issues and inconsistencies
This commit addresses several minor issues across different packages: - **RequestContext:** Corrected a typo in the `RequestContext.currentRequest()` call. - **Available Users Effects:** Implemented pagination for loading users by applying `slice` with `currentSkip` and `currentTake`. - **Plugin Subscription Plan Creator:** - Added a check for `normalizedPlanValue` to prevent errors when it's undefined. - Corrected the spread syntax for `normalizedPlanValue.id` to ensure it's only included if `id` exists. - **Plugin Settings Management:** Removed an unused `scope` variable. - **Plugin Subscription Hierarchy:** Added optional chaining (`?.`) to `subscription.plan.price` to safely access the price. - **Plugin Subscription Plan Selection:** - Updated `window.removeEventListener` and `window.addEventListener` to use a bound handler for `handleKeyboardShortcut` to ensure correct context. - Added optional chaining (`?.`) to `currentPlan?.id` for safe access. - **Plan Comparison Service:** Added a check for `currentPlan` to return early if it's null. - **Form Data Builder:** - Filtered out falsy values from `plans` before mapping in `appendSubscriptionPlans`. - Corrected the spread syntax for `plan.id` to ensure it's only included if `id` exists. - **List Plugin Subscription Plans Handler:** Removed an unused `relations` variable. - **Auto Tag Plugin Handler:** Removed an unused `overwriteExisting` option from `options`. - **Manage Plugin Tenant Users Handler:** Adjusted logging to correctly display the number of users, handling cases where `userIds` might be null. - **Update Plugin Command Handler:** Added optional chaining (`?.`) to all input properties being mapped to `pluginUpdate` for safer access. - **Plugin Billing Factory:** Removed unnecessary status assignment for `PluginBillingStatus.PENDING`. - **Plugin Subscription Access Service:** Removed the `SubscriptionValiditySpecification` as it was not being used. - **Plugin Subscription Plan DTO:** Removed the unused `transformToNumber` helper function.
1 parent 642e3a1 commit 3e04acd

File tree

15 files changed

+56
-72
lines changed

15 files changed

+56
-72
lines changed

packages/core/src/lib/core/context/request-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class RequestContext {
192192
const user: IUser | null = RequestContext.currentUser();
193193
return (
194194
user?.employee?.organizationId ||
195-
(RequestContext?.currentRequest()?.headers['organization-id'] as ID) ||
195+
(RequestContext.currentRequest()?.headers['organization-id'] as ID) ||
196196
null
197197
);
198198
}

packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/+state/effects/available-users.effects.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ export class AvailableUsersEffects {
7676
.filter((userOrg: IUserOrganization) => userOrg.isActive && userOrg.user)
7777
.map((userOrg: IUserOrganization) => userOrg.user);
7878

79+
// Apply pagination using currentSkip/currentTake
80+
const paginatedUsers = allUsers.slice(currentSkip, currentSkip + currentTake);
81+
7982
return AvailableUsersActions.loadUsersSuccess({
80-
users: allUsers,
83+
users: paginatedUsers,
8184
total: response.total
8285
});
8386
}),

packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-marketplace-upload/plugin-subscription-plan-creator/plugin-subscription-plan-creator.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,14 @@ export class PluginSubscriptionPlanCreatorComponent implements OnInit, OnDestroy
508508

509509
const planValue = plan.value as IPluginPlanCreateInput;
510510
const normalizedPlanValue = this.formBuilderService.normalizePlanValue(planValue);
511+
if (!normalizedPlanValue) {
512+
console.warn('Cannot update: Normalized plan value is undefined', { index, planId });
513+
return;
514+
}
511515

512516
// Build the update payload directly from form value
513517
const updates: Partial<IPluginPlanCreateInput> = {
514-
...(normalizedPlanValue?.id && { id: normalizedPlanValue.id }),
518+
...(normalizedPlanValue.id && { id: normalizedPlanValue.id }),
515519
type: normalizedPlanValue.type,
516520
name: normalizedPlanValue.name,
517521
description: normalizedPlanValue.description,

packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-settings-management/plugin-settings-management.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ export class PluginSettingsManagementComponent implements OnInit, OnDestroy, Aft
146146
}
147147

148148
private loadSettings(): void {
149-
const scope = this.data.scope || PluginSettingScope.GLOBAL;
150149
const query = {
151150
pluginTenantId: this.data.tenantId
152151
};

packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-subscription-hierarchy/plugin-subscription-hierarchy.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class PluginSubscriptionHierarchyComponent implements OnInit {
5757

5858
formatAmount(subscription: IPluginSubscription): string {
5959
// Handle both plan.price and subscription.amount
60-
const amount = subscription.plan.price || 0;
60+
const amount = subscription.plan?.price || 0;
6161
const currency = subscription.plan?.currency || CurrenciesEnum.USD;
6262
return `${currency} ${amount}`;
6363
}

packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-subscription-plan-selection/plugin-subscription-plan-selection.component.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import { ChangeDetectionStrategy, Component, inject, Input, OnDestroy, OnInit } from '@angular/core';
22
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
33
import {
4-
IPlugin,
5-
IPluginSubscription,
6-
IPluginSubscriptionCreateInput,
7-
IPluginSubscriptionPlan,
8-
PluginBillingPeriod,
9-
PluginScope,
10-
PluginSubscriptionType
4+
IPlugin,
5+
IPluginSubscription,
6+
IPluginSubscriptionCreateInput,
7+
IPluginSubscriptionPlan,
8+
PluginBillingPeriod,
9+
PluginScope,
10+
PluginSubscriptionType
1111
} from '@gauzy/contracts';
1212
import { NbDialogRef } from '@nebular/theme';
1313
import { Actions } from '@ngneat/effects-ng';
1414
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
1515
import {
16-
BehaviorSubject,
17-
combineLatest,
18-
filter,
19-
firstValueFrom,
20-
map,
21-
Observable,
22-
startWith,
23-
switchMap,
24-
take,
25-
tap
16+
BehaviorSubject,
17+
combineLatest,
18+
filter,
19+
firstValueFrom,
20+
map,
21+
Observable,
22+
startWith,
23+
switchMap,
24+
take,
25+
tap
2626
} from 'rxjs';
2727
import { PluginSubscriptionFacade } from '../+state';
2828
import { PluginSubscriptionActions } from '../+state/actions/plugin-subscription.action';
@@ -153,7 +153,7 @@ export class PluginSubscriptionPlanSelectionComponent implements OnInit, OnDestr
153153

154154
// Clean up keyboard event listener
155155
if (typeof window !== 'undefined') {
156-
window.removeEventListener('keydown', this.handleKeyboardShortcut.bind(this));
156+
window.removeEventListener('keydown', this.boundKeyboardHandler);
157157
}
158158
}
159159

@@ -297,8 +297,6 @@ export class PluginSubscriptionPlanSelectionComponent implements OnInit, OnDestr
297297
map(([planViewModel, formValues]) => {
298298
if (!planViewModel) return null;
299299

300-
const promoCode = (formValues as any).promoCode;
301-
// TODO: Calculate discount based on promo code validation
302300
const promoDiscount = 0;
303301

304302
return this.planFormatter.createPreviewViewModel(planViewModel.originalPlan, promoDiscount);
@@ -819,7 +817,7 @@ export class PluginSubscriptionPlanSelectionComponent implements OnInit, OnDestr
819817
}
820818

821819
const currentPlan = currentSubscription.plan;
822-
if (currentPlan.id === plan.id) {
820+
if (currentPlan?.id === plan.id) {
823821
return `${plan.name} plan - Your current active plan`;
824822
}
825823

@@ -837,10 +835,12 @@ export class PluginSubscriptionPlanSelectionComponent implements OnInit, OnDestr
837835
* Escape - Close dialog
838836
* Ctrl/Cmd + Enter - Submit form (if valid)
839837
*/
838+
private readonly boundKeyboardHandler = (event: KeyboardEvent) => this.handleKeyboardShortcut(event);
839+
840840
private setupKeyboardShortcuts(): void {
841841
// Using HostListener would be better, but adding via constructor for now
842842
if (typeof window !== 'undefined') {
843-
window.addEventListener('keydown', this.handleKeyboardShortcut.bind(this));
843+
window.addEventListener('keydown', this.boundKeyboardHandler);
844844
}
845845
}
846846

packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-subscription-plan-selection/services/plan-comparison.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ export class PlanComparisonService {
291291

292292
// Calculate daily rates
293293
// Use plan.price if available, otherwise fall back to subscription.amount
294-
const currentAmount = currentSubscription.plan?.price
295-
? this.parsePriceAsNumber(currentSubscription.plan.price)
296-
: currentSubscription.plan.price || 0;
297-
const currentBillingPeriod = currentSubscription.plan?.billingPeriod || currentSubscription.plan.billingPeriod;
294+
const currentPlan = currentSubscription.plan;
295+
if (!currentPlan) {
296+
return newPrice; // no plan info, fallback to full price
297+
}
298+
const currentAmount = currentPlan.price ? this.parsePriceAsNumber(currentPlan.price) : currentPlan.price || 0;
299+
const currentBillingPeriod = currentPlan.billingPeriod;
298300

299301
if (!currentBillingPeriod) {
300302
return newPrice; // Can't calculate proration without billing period

packages/desktop-ui-lib/src/lib/settings/plugins/services/builders/form-data.builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class PluginFormDataBuilder {
6969

7070
public appendSubscriptionPlans(plans: IPluginPlanCreateInput[]): this {
7171
if (plans && plans.length > 0) {
72-
const plansData = plans.map((plan) => this.buildSubscriptionPlanData(plan));
72+
const plansData = plans.filter(Boolean).map((plan) => this.buildSubscriptionPlanData(plan));
7373
this.appendFiltered(plansData, 'subscriptionPlans');
7474
}
7575
return this;
@@ -102,7 +102,7 @@ export class PluginFormDataBuilder {
102102

103103
private buildSubscriptionPlanData(plan: IPluginPlanCreateInput) {
104104
return {
105-
...(plan?.id && { id: plan?.id }),
105+
...(plan.id && { id: plan.id }),
106106
type: plan.type,
107107
name: plan.name,
108108
description: plan.description,

packages/plugins/registry/src/lib/application/plugin-subscription/queries/handlers/list-plugin-subscription-plans.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class ListPluginSubscriptionPlansQueryHandler implements IQueryHandler<Li
99
constructor(private readonly pluginSubscriptionPlanService: PluginSubscriptionPlanService) {}
1010

1111
async execute(query: ListPluginSubscriptionPlansQuery): Promise<IPluginSubscriptionPlan[]> {
12-
const { queryDto, relations } = query;
12+
const { queryDto } = query;
1313

1414
try {
1515
// Convert DTO to find input format

packages/plugins/registry/src/lib/application/plugin-tag/commands/handlers/auto-tag-plugin.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class AutoTagPluginHandler implements ICommandHandler<AutoTagPluginComman
2626
this.logger.log(`Auto-tagging plugin: ${command.pluginId}`);
2727

2828
const { pluginId, pluginData, options = {} } = command;
29-
const { createMissingTags = true, overwriteExisting = false, tenantId, organizationId } = options;
29+
const { createMissingTags = true, tenantId, organizationId } = options;
3030

3131
// Extract potential tag names from plugin data
3232
const extractedTags = this.extractTagsFromPluginData(pluginData);

0 commit comments

Comments
 (0)