From a74120ef8fc074b80d0bf317cb7840d43f0f763e Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Fri, 11 Oct 2024 11:17:37 +0530 Subject: [PATCH] fix: improvement suggested by CodeRabbit --- .../date-range-picker-builder.service.ts | 2 +- .../selectors/organization/organization.component.ts | 11 ++++++++--- .../src/lib/selectors/team/team/team.component.ts | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/ui-core/core/src/lib/services/selector-builder/date-range-picker-builder.service.ts b/packages/ui-core/core/src/lib/services/selector-builder/date-range-picker-builder.service.ts index 6d44ac6b22f..25f7521f583 100644 --- a/packages/ui-core/core/src/lib/services/selector-builder/date-range-picker-builder.service.ts +++ b/packages/ui-core/core/src/lib/services/selector-builder/date-range-picker-builder.service.ts @@ -36,7 +36,7 @@ export class DateRangePickerBuilderService { * @param range - The new date range to set. */ set selectedDateRange(range: IDateRangePicker) { - if (range) { + if (isNotEmpty(range)) { this._selectedDateRange$.next(range); this.dates$.next(range); } diff --git a/packages/ui-core/shared/src/lib/selectors/organization/organization.component.ts b/packages/ui-core/shared/src/lib/selectors/organization/organization.component.ts index 47a991fa9c4..aec75ba3bbb 100644 --- a/packages/ui-core/shared/src/lib/selectors/organization/organization.component.ts +++ b/packages/ui-core/shared/src/lib/selectors/organization/organization.component.ts @@ -1,9 +1,9 @@ import { Component, OnInit, OnDestroy, AfterViewInit, Input } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { catchError, distinctUntilChanged, filter, map, tap } from 'rxjs/operators'; +import { catchError, distinctUntilChanged, filter, map, tap } from 'rxjs'; import { Observable } from 'rxjs/internal/Observable'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; -import { uniq as uniqBy } from 'underscore'; +import { uniq } from 'underscore'; import { IOrganization, CrudActionEnum, PermissionsEnum, ID } from '@gauzy/contracts'; import { isNotEmpty } from '@gauzy/ui-core/common'; import { @@ -139,7 +139,7 @@ export class OrganizationSelectorComponent implements AfterViewInit, OnInit, OnD const fetchedOrganizations: IOrganization[] = items.map(({ organization }) => organization); // Remove duplicate organizations based on their ID - this.organizations = uniqBy(fetchedOrganizations, 'id'); + this.organizations = uniq(fetchedOrganizations, 'id'); // Select and set the active organization this.selectAndSetOrganization(); @@ -265,6 +265,7 @@ export class OrganizationSelectorComponent implements AfterViewInit, OnInit, OnD // Assign the filtered and updated organizations list this.organizations = updatedOrganizations.filter(isNotEmpty); } catch (error) { + console.error('Error updating organization:', error); this._toastrService.error('Failed to update organization.', error); } } @@ -391,6 +392,10 @@ export class OrganizationSelectorComponent implements AfterViewInit, OnInit, OnD * @returns A randomly selected organization. */ private getRandomOrganization(organizations: IOrganization[]): IOrganization { + if (organizations.length === 0) { + return null; + } + const randomIndex = Math.floor(Math.random() * organizations.length); return organizations[randomIndex]; } diff --git a/packages/ui-core/shared/src/lib/selectors/team/team/team.component.ts b/packages/ui-core/shared/src/lib/selectors/team/team/team.component.ts index 4c2429952bf..9dd640486d8 100644 --- a/packages/ui-core/shared/src/lib/selectors/team/team/team.component.ts +++ b/packages/ui-core/shared/src/lib/selectors/team/team/team.component.ts @@ -84,7 +84,7 @@ export class TeamSelectorComponent implements OnInit, OnDestroy { * The placeholder text to be displayed in the team selector. * Provides guidance to the user on what action to take or what information to provide. * -\ */ + */ @Input() placeholder: string | null = null; /**