Skip to content

Commit

Permalink
fix: improvement suggested by CodeRabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-rocket committed Oct 11, 2024
1 parent 415a99e commit a74120e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down

0 comments on commit a74120e

Please sign in to comment.