Skip to content

Commit

Permalink
NAS-131036 / 25.04 / Remove use of chain method from 'lodash-es' (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanY147 authored Sep 23, 2024
1 parent 8e5e6c9 commit b237815
Show file tree
Hide file tree
Showing 81 changed files with 298 additions and 290 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ module.exports = {
"importNames": ["CommonModule"],
"message": "Import individual constituents instead."
},
{
"name": "lodash-es",
"importNames": ["chain"],
"message": "Use standalone methods to get results instead of using 'chain' for chaining."
},
{
"name": "lodash",
"importNames": ["chain"],
"message": "Use standalone methods to get results instead of using 'chain' for chaining."
}
],
"patterns": [{
"group": [ "../**"],
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/testing/utils/mock-window.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValueProvider } from '@angular/core';
import * as _ from 'lodash-es';
import { merge } from 'lodash-es';
import { DeepPartial } from 'utility-types';
import { WINDOW } from 'app/helpers/window.helper';

Expand All @@ -14,6 +14,6 @@ export function mockWindow(overrides: DeepPartial<Window> = {}): ValueProvider {

return {
provide: WINDOW,
useValue: _.merge(baseWindow, overrides),
useValue: merge(baseWindow, overrides),
};
}
4 changes: 2 additions & 2 deletions src/app/helpers/operators/options.operators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash-es';
import { uniq } from 'lodash-es';
import { OperatorFunction } from 'rxjs';
import { map } from 'rxjs/operators';
import { Choices } from 'app/interfaces/choices.interface';
Expand Down Expand Up @@ -28,7 +28,7 @@ export function singleArrayToOptions(): OperatorFunction<(string | number)[], Op

export function redundantListToUniqueOptions(): OperatorFunction<string[], Option[]> {
return map((redundantArray) => {
return _.uniq(redundantArray).map((item: string) => ({ label: item, value: item }));
return uniq(redundantArray).map((item: string) => ({ label: item, value: item }));
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/entity/entity-job/entity-job.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@angular/core';
import { MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import * as _ from 'lodash-es';
import { replace } from 'lodash-es';
import { Subscription } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { JobState } from 'app/enums/job-state.enum';
Expand Down Expand Up @@ -91,8 +91,8 @@ export class EntityJobComponent implements OnInit, AfterViewChecked {
});

this.failure.pipe(untilDestroyed(this)).subscribe((job) => {
let error = _.replace(job.error, '<', '< ');
error = _.replace(error, '>', ' >');
let error = replace(job.error, '<', '< ');
error = replace(error, '>', ' >');

this.description = '<b>Error:</b> ' + error;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ChangeDetectionStrategy, Component, Input,
} from '@angular/core';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import * as _ from 'lodash-es';
import { sortBy, uniqBy } from 'lodash-es';
import {
BehaviorSubject, Observable, debounceTime, distinctUntilChanged, filter, pairwise, switchMap,
} from 'rxjs';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class SimilarIssuesComponent {
this.isLoading$.next(true);
return this.feedbackService.getSimilarIssues(query).pipe(
switchMap((newIssues) => {
const combinedUniqueIssues = _.sortBy(_.uniqBy([
const combinedUniqueIssues = sortBy(uniqBy([
...this.similarIssues$.value,
...newIssues,
], 'id'), { summaryText: query });
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/forms/ix-forms/validators/ip-validation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FormControl, ValidatorFn } from '@angular/forms';
import ipRegex from 'ip-regex';
import isCidr from 'is-cidr';
import * as _ from 'lodash-es';
import { indexOf } from 'lodash-es';

// Accepts ipv4 or ipv6 addresses with no CIDR (ie, /24)
export function ipv4or6Validator(): ValidatorFn {
Expand Down Expand Up @@ -154,7 +154,7 @@ export function ipValidator(type: string = 'ipv4' || 'ipv6' || 'all'): Validator
function checkIp(ipType = 'ipv4' || 'ipv6'): boolean {
const regex = ipType === 'ipv4' ? ipv4Regex : ipv6Regex;
const wildcard = ipType === 'ipv4' ? '0.0.0.0' : '::';
if (_.indexOf(thisControl.value, wildcard) !== -1) {
if (indexOf(thisControl.value, wildcard) !== -1) {
for (const ip of thisControl.value) {
if (ip !== wildcard && regex.test(ip)) {
error = [ipType === 'ipv4' ? 'IPv4' : 'IPv6', wildcard, ip];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FormGroup, UntypedFormControl, ValidatorFn } from '@angular/forms';
import * as _ from 'lodash-es';
import { isEmpty } from 'lodash-es';

export function matchOthersFgValidator(
controlName: string,
Expand Down Expand Up @@ -34,7 +34,7 @@ export function matchOthersFgValidator(
}
let prevErrors = { ...fg.get(controlName).errors };
delete prevErrors.matchOther;
if (_.isEmpty(prevErrors)) {
if (isEmpty(prevErrors)) {
prevErrors = null;
}
fg.get(controlName).setErrors(prevErrors);
Expand Down Expand Up @@ -75,7 +75,7 @@ export function doesNotEqualFgValidator(
}
let prevErrors = { ...fg.get(controlName).errors };
delete prevErrors.matchesOther;
if (_.isEmpty(prevErrors)) {
if (isEmpty(prevErrors)) {
prevErrors = null;
}
fg.get(controlName).setErrors(prevErrors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { FormControl } from '@angular/forms';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { Store } from '@ngrx/store';
import * as _ from 'lodash-es';
import { isEqual } from 'lodash-es';
import {
tap, debounceTime, filter, switchMap,
combineLatestWith,
Expand Down Expand Up @@ -183,7 +183,7 @@ export class GlobalSearchComponent implements OnInit, AfterViewInit, OnDestroy {
}),
combineLatestWith(this.searchDirectives.directiveAdded$.pipe(filter(Boolean))),
filter(([config]) => !!this.searchDirectives.get(config)),
distinctUntilChanged(([prevConfig], [nextConfig]) => _.isEqual(prevConfig, nextConfig)),
distinctUntilChanged(([prevConfig], [nextConfig]) => isEqual(prevConfig, nextConfig)),
untilDestroyed(this),
).subscribe(([config]) => {
this.resetInput();
Expand Down
9 changes: 4 additions & 5 deletions src/app/modules/ix-table/classes/base-data-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter } from '@angular/core';
import * as _ from 'lodash-es';
import { orderBy, sortBy } from 'lodash-es';
import {
BehaviorSubject, Observable, Subscription, map,
} from 'rxjs';
Expand Down Expand Up @@ -85,16 +85,15 @@ export function sort<T>(rows: T[], sorting: TableSort<T>): T[] {
const sorted = rows;
const direction = sorting.direction;
const propertyName = sorting.propertyName;
const sortBy = sorting.sortBy;

if (direction === null || propertyName === null) {
return sorted;
}
if (sortBy) {
return direction === SortDirection.Desc ? _.sortBy(sorted, sortBy).reverse() : _.sortBy(sorted, sortBy);
if (sorting.sortBy) {
return direction === SortDirection.Desc ? sortBy(sorted, sorting.sortBy).reverse() : sortBy(sorted, sorting.sortBy);
}

return _.orderBy(sorted, propertyName, direction);
return orderBy(sorted, propertyName, direction);
}

export function paginate<T>(rows: T[], pagination: TablePagination): T[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MatButton } from '@angular/material/button';
import { MatMenuTrigger, MatMenu, MatMenuItem } from '@angular/material/menu';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateModule } from '@ngx-translate/core';
import * as _ from 'lodash-es';
import { cloneDeep } from 'lodash-es';
import { IxSimpleChanges } from 'app/interfaces/simple-changes.interface';
import { IxIconModule } from 'app/modules/ix-icon/ix-icon.module';
import { Column, ColumnComponent } from 'app/modules/ix-table/interfaces/column-component.class';
Expand Down Expand Up @@ -87,7 +87,7 @@ export class IxTableColumnsSelectorComponent<T = unknown> implements OnChanges {
}

private setInitialState(): void {
this.columns = _.cloneDeep(this.defaultColumns);
this.columns = cloneDeep(this.defaultColumns);
this.hiddenColumns.select(...this.columns);

this.defaultColumns.forEach((column, index) => {
Expand Down
34 changes: 16 additions & 18 deletions src/app/modules/page-header/breadcrumb/breadcrumb.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { chain } from 'lodash-es';
import { uniqBy } from 'lodash-es';
import { filter } from 'rxjs/operators';
import { RoutePartsService, RoutePart } from 'app/services/route-parts/route-parts.service';

Expand Down Expand Up @@ -39,22 +39,20 @@ export class BreadcrumbComponent implements OnInit {
}

private getBreadcrumbs(): RoutePart[] {
return chain(this.routePartsService.routeParts)
.sort((a, b) => a.ngUrl.length - b.ngUrl.length)
.uniqBy('url')
.filter((routePart) => {
routePart.ngUrl = routePart.ngUrl.filter((item) => item !== '');
if (routePart.url === this.router.url) {
return false;
}
return Boolean(routePart.breadcrumb);
})
.map((routePart) => {
if (noLinksRoutes.some((url) => routePart.url === url)) {
return { ...routePart, url: null };
}
return routePart;
})
.value();
const sortedRoutes = this.routePartsService.routeParts.sort((a, b) => a.ngUrl.length - b.ngUrl.length);
const uniqRoutesList = uniqBy(sortedRoutes, 'url');
const validRoutesBeforeCurrent = uniqRoutesList.filter((routePart) => {
routePart.ngUrl = routePart.ngUrl.filter((item) => item !== '');
if (routePart.url === this.router.url) {
return false;
}
return Boolean(routePart.breadcrumb);
});
return validRoutesBeforeCurrent.map((routePart) => {
if (noLinksRoutes.some((url) => routePart.url === url)) {
return { ...routePart, url: null };
}
return routePart;
});
}
}
4 changes: 2 additions & 2 deletions src/app/modules/truecommand/truecommand-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import * as _ from 'lodash-es';
import { isObject } from 'lodash-es';
import { TrueCommandStatus } from 'app/enums/true-command-status.enum';
import { WINDOW } from 'app/helpers/window.helper';
import { helptextTopbar } from 'app/helptext/topbar';
Expand Down Expand Up @@ -93,7 +93,7 @@ export class TruecommandButtonComponent implements OnInit {
.afterClosed()
.pipe(untilDestroyed(this))
.subscribe((dialogResult: TruecommandSignupModalResult) => {
if (_.isObject(dialogResult) && dialogResult?.deregistered) {
if (isObject(dialogResult) && dialogResult?.deregistered) {
this.tcStatusDialogRef.close(true);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormBuilder, Validators } from '@angular/forms';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import * as _ from 'lodash-es';
import { remove } from 'lodash-es';
import {
Observable, combineLatest, of,
} from 'rxjs';
Expand Down Expand Up @@ -240,7 +240,7 @@ export class GroupFormComponent implements OnInit {
this.ws.call('group.query').pipe(untilDestroyed(this)).subscribe((groups) => {
let forbiddenNames = groups.map((group) => group.group);
if (currentName) {
forbiddenNames = _.remove(forbiddenNames, currentName);
forbiddenNames = remove(forbiddenNames, currentName);
}
this.form.controls.name.addValidators(forbiddenValues(forbiddenNames));
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/account/users/user-form/user-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FormBuilder } from '@ngneat/reactive-forms';
import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import * as _ from 'lodash-es';
import { remove } from 'lodash-es';
import {
from, Observable, of, Subscription,
} from 'rxjs';
Expand Down Expand Up @@ -457,7 +457,7 @@ export class UserFormComponent implements OnInit {
this.store$.select(selectUsers).pipe(untilDestroyed(this)).subscribe((users) => {
let forbiddenNames = users.map((user) => user.username);
if (currentName) {
forbiddenNames = _.remove(forbiddenNames, currentName);
forbiddenNames = remove(forbiddenNames, currentName);
}
this.form.controls.username.addValidators(forbiddenValues(forbiddenNames));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateService } from '@ngx-translate/core';
import * as _ from 'lodash-es';
import { isArray, isPlainObject, unset } from 'lodash-es';
import {
BehaviorSubject, Observable, of, Subject, Subscription, timer,
} from 'rxjs';
Expand Down Expand Up @@ -202,12 +202,12 @@ export class AppWizardComponent implements OnInit, OnDestroy {
}
});
}
if (_.isPlainObject(data)) {
if (isPlainObject(data)) {
Object.keys(data).forEach((key) => {
this.getFieldsHiddenOnForm((data as Record<string, unknown>)[key], deleteField$, path ? path + '.' + key : key);
});
}
if (_.isArray(data)) {
if (isArray(data)) {
for (let i = 0; i < data.length; i++) {
this.getFieldsHiddenOnForm(data[i], deleteField$, `${path}.${i}`);
}
Expand All @@ -220,7 +220,7 @@ export class AppWizardComponent implements OnInit, OnDestroy {
deleteField$.pipe(untilDestroyed(this)).subscribe({
next: (fieldToBeDeleted) => {
const keys = fieldToBeDeleted.split('.');
_.unset(data, keys);
unset(data, keys);
},
complete: () => this.saveData(data),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { ComponentHarness } from '@angular/cdk/testing';
import * as _ from 'lodash-es';
import { isString } from 'lodash-es';
import { IxFormControlHarness } from 'app/modules/forms/ix-forms/interfaces/ix-form-control-harness.interface';
import { getErrorText } from 'app/modules/forms/ix-forms/utils/harness.utils';
import { IxIconHarness } from 'app/modules/ix-icon/ix-icon.harness';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class IxFilterSelectListHarness extends ComponentHarness implements IxFor
}

async setValue(value: string[] | string): Promise<void> {
if (_.isString(value)) {
if (isString(value)) {
value = [value];
}
const items = await this.getItems();
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/apps/store/apps-filter-store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { ComponentStore } from '@ngrx/component-store';
import { TranslateService } from '@ngx-translate/core';
import * as _ from 'lodash-es';
import { deburr, some, toLower } from 'lodash-es';
import {
EMPTY, Observable, combineLatest, map,
} from 'rxjs';
Expand Down Expand Up @@ -191,10 +191,10 @@ export class AppsFilterStore extends ComponentStore<AppsFilterState> {
}

private doesAppContainString = (searchQuery: string, app: AvailableApp): boolean => {
const normalize = (str: string): string => _.toLower(_.deburr(str));
const normalize = (str: string): string => toLower(deburr(str));
const isStringsArray = (arr: unknown[]): boolean => arr.every((i) => typeof i === 'string');
const search = normalize(searchQuery);
return _.some(app, (value) => {
return some(app, (value) => {
if (typeof value === 'string') {
return normalize(value).includes(search);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/audit/utils/audit-api-data-provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash-es';
import { isEqual } from 'lodash-es';
import { Observable, of } from 'rxjs';
import { ApiCallParams } from 'app/interfaces/api/api-call-directory.interface';
import { AuditEntry, AuditQueryParams } from 'app/interfaces/audit/audit.interface';
Expand All @@ -14,7 +14,7 @@ export class AuditApiDataProvider extends ApiDataProvider<'audit.query'> {
}

get avoidCountRowsRequest(): boolean {
return this.totalRows && !this.isLastOffset && _.isEqual(this.lastParams, this.params[0]);
return this.totalRows && !this.isLastOffset && isEqual(this.lastParams, this.params[0]);
}

constructor(ws: WebSocketService) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FormGroup } from '@angular/forms';
import * as _ from 'lodash-es';
import { isNull, omitBy } from 'lodash-es';
import { BehaviorSubject, Observable, of } from 'rxjs';
import { helptextSystemCloudcredentials as helptext } from 'app/helptext/system/cloud-credentials';
import { CloudCredential } from 'app/interfaces/cloud-sync-task.interface';
Expand All @@ -23,7 +23,7 @@ export abstract class BaseProviderFormComponent<T = CloudCredential['attributes'
}

getSubmitAttributes(): T {
const nonNullAttributes = _.omitBy(this.form.value, _.isNull);
const nonNullAttributes = omitBy(this.form.value, isNull);
return nonNullAttributes as T;
}

Expand Down
Loading

0 comments on commit b237815

Please sign in to comment.