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 a0345fb commit 9edf0fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ActivatedRouteSnapshot, ResolveFn } from '@angular/router';
import { EMPTY, Observable, of } from 'rxjs';
import { Store } from '../services/store/store.service';
import { DEFAULT_SELECTOR_VISIBILITY } from '../services/selector-builder/selector-builder.service';
import { ErrorHandlingService } from '../services/notification/error-handling.service';

/**
* The `BookmarkQueryParamsResolver` is responsible for constructing a set of query parameters
Expand All @@ -17,12 +18,13 @@ import { DEFAULT_SELECTOR_VISIBILITY } from '../services/selector-builder/select
export const BookmarkQueryParamsResolver: ResolveFn<Observable<Record<string, string>>> = (
route: ActivatedRouteSnapshot
): Observable<Record<string, string>> => {
// Get injected services
const _store = inject(Store);
const _errorHandlingService = inject(ErrorHandlingService);

try {
// Get selectors visibility and selected entities
const selectors = Object.assign({}, DEFAULT_SELECTOR_VISIBILITY, route.data?.selectors);

// Get injected services
const _store = inject(Store);
const { selectedOrganization, selectedEmployee, selectedProject, selectedTeam } = _store;

// Map selectors to entity IDs
Expand All @@ -46,7 +48,7 @@ export const BookmarkQueryParamsResolver: ResolveFn<Observable<Record<string, st
} catch (error) {
// Handle any synchronous errors and redirect to "new integration" page
console.log(`Error resolving entity query params: ${error}`);
// Return an empty observable
return EMPTY;
_errorHandlingService.handleError(error);
return EMPTY; // Return an empty observable
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ export const DEFAULT_DATE_RANGE: IDateRangePicker = {

@Injectable({ providedIn: 'root' })
export class DateRangePickerBuilderService {
public dates$: BehaviorSubject<IDateRangePicker> = new BehaviorSubject(DEFAULT_DATE_RANGE);
private _datePickerConfig$: BehaviorSubject<IDatePickerConfig | null> = new BehaviorSubject(null);
public datePickerConfig$: Observable<IDatePickerConfig | null> = this._datePickerConfig$.asObservable();

private _selectedDateRange$: BehaviorSubject<IDateRangePicker | null> = new BehaviorSubject(null);
public selectedDateRange$: Observable<IDateRangePicker | null> = this._selectedDateRange$.asObservable();

public dates$: BehaviorSubject<IDateRangePicker> = new BehaviorSubject(DEFAULT_DATE_RANGE);

/**
* Gets the currently selected date range.
*/
get selectedDateRange(): IDateRangePicker {
return this.dates$.getValue();
}
/**
* Sets a new selected date range.
*
* @param range - The new date range to set.
*/
set selectedDateRange(range: IDateRangePicker) {
if (isNotEmpty(range)) {
if (range) {
this._selectedDateRange$.next(range);
this.dates$.next(range);
}
}

/**
* Gets the currently selected date range.
*/
get selectedDateRange(): IDateRangePicker {
return this.dates$.getValue();
}

/**
* Gets the current date picker configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ProjectSelectorComponent implements OnInit, OnDestroy, AfterViewIni
* The placeholder text to be displayed in the project selector.
* Provides guidance to the user on what action to take or what information to provide.
*
\ */
*/
@Input() placeholder: string | null = null;

/**
Expand Down Expand Up @@ -120,7 +120,7 @@ export class ProjectSelectorComponent implements OnInit, OnDestroy, AfterViewIni
public set projectId(value: ID | ID[]) {
this._projectId = value;
this.onChange(value);
this.onTouched(value);
this.onTouched();
}

/**
Expand Down Expand Up @@ -182,7 +182,7 @@ export class ProjectSelectorComponent implements OnInit, OnDestroy, AfterViewIni
/**
* Callback function to notify touch events in the form control.
*/
private onTouched: (value: ID | ID[]) => void = () => {};
private onTouched: () => void = () => {};

constructor(
private readonly _organizationProjects: OrganizationProjectsService,
Expand Down Expand Up @@ -352,7 +352,7 @@ export class ProjectSelectorComponent implements OnInit, OnDestroy, AfterViewIni
*
* @param fn - The callback function to register for the 'onChange' event.
*/
registerOnChange(fn: (value: any) => void): void {
registerOnChange(fn: (value: ID | ID[]) => void): void {
this.onChange = fn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class TeamSelectorComponent implements OnInit, OnDestroy {
public set teamId(value: ID | ID[]) {
this._teamId = value;
this.onChange(value);
this.onTouched(value);
this.onTouched();
}

/**
Expand Down Expand Up @@ -182,7 +182,7 @@ export class TeamSelectorComponent implements OnInit, OnDestroy {
/**
* Callback function to notify touch events in the form control.
*/
private onTouched: (value: ID | ID[]) => void = () => {};
private onTouched: () => void = () => {};

constructor(
private readonly _activatedRoute: ActivatedRoute,
Expand Down Expand Up @@ -339,7 +339,7 @@ export class TeamSelectorComponent implements OnInit, OnDestroy {
*
* @param fn - The callback function to register for the 'onChange' event.
*/
registerOnChange(fn: (value: any) => void): void {
registerOnChange(fn: (value: ID | ID[]) => void): void {
this.onChange = fn;
}

Expand Down

0 comments on commit 9edf0fd

Please sign in to comment.