From 6d034450bc43694755f951fcc5fe5c23fa09f98a Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Wed, 1 Sep 2021 09:38:59 +0300 Subject: [PATCH] remove snq package resolves #4294 --- .../change-password/change-password.component.ts | 9 +++------ .../src/lib/components/login/login.component.ts | 11 +++++------ .../lib/components/register/register.component.ts | 9 +++++---- npm/ng-packs/packages/core/ng-package.json | 1 - .../directives/replaceable-template.directive.ts | 3 +-- .../src/lib/directives/visibility.directive.ts | 15 +++++---------- .../core/src/lib/services/permission.service.ts | 7 +++---- .../packages/core/src/lib/states/config.state.ts | 11 +++++------ .../core/src/lib/utils/localization-utils.ts | 3 +-- .../src/lib/components/users/users.component.ts | 15 ++++++--------- .../components/nav-items/languages.component.ts | 10 ++-------- .../extensible-form-prop.component.ts | 3 +-- .../src/lib/directives/table-sort.directive.ts | 3 +-- .../src/lib/utils/date-parser-formatter.ts | 3 +-- 14 files changed, 39 insertions(+), 64 deletions(-) diff --git a/npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts b/npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts index 47b02e4b6e..0feb091f81 100644 --- a/npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts @@ -1,10 +1,9 @@ -import { Profile, ProfileService } from '@abp/ng.core'; +import { ProfileService } from '@abp/ng.core'; import { getPasswordValidators, ToasterService } from '@abp/ng.theme.shared'; -import { Component, Injector, Input, OnInit } from '@angular/core'; +import { Component, Injector, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { comparePasswords, Validation } from '@ngx-validate/core'; import { finalize } from 'rxjs/operators'; -import snq from 'snq'; import { Account } from '../../models/account'; import { ManageProfileStateService } from '../../services/manage-profile.state.service'; @@ -91,9 +90,7 @@ export class ChangePasswordComponent } }, error: err => { - this.toasterService.error( - snq(() => err.error.error.message, 'AbpAccount::DefaultErrorMessage'), - ); + this.toasterService.error(err.error?.error?.message || 'AbpAccount::DefaultErrorMessage'); }, }); } diff --git a/npm/ng-packs/packages/account/src/lib/components/login/login.component.ts b/npm/ng-packs/packages/account/src/lib/components/login/login.component.ts index 7ef04e31a9..dbef4e832e 100644 --- a/npm/ng-packs/packages/account/src/lib/components/login/login.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/login/login.component.ts @@ -1,11 +1,9 @@ -import { ConfigStateService, AuthService } from '@abp/ng.core'; +import { AuthService, ConfigStateService } from '@abp/ng.core'; import { ToasterService } from '@abp/ng.theme.shared'; import { Component, Injector, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; -import { Store } from '@ngxs/store'; import { throwError } from 'rxjs'; import { catchError, finalize } from 'rxjs/operators'; -import snq from 'snq'; import { eAccountComponents } from '../../enums/components'; import { getRedirectUrl } from '../../utils/auth-utils'; @@ -66,9 +64,10 @@ export class LoginComponent implements OnInit { .pipe( catchError(err => { this.toasterService.error( - snq(() => err.error.error_description) || - snq(() => err.error.error.message, 'AbpAccount::DefaultErrorMessage'), - 'Error', + err.error?.error_description || + err.error?.error.message || + 'AbpAccount::DefaultErrorMessage', + null, { life: 7000 }, ); return throwError(err); diff --git a/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts b/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts index 9be22d2203..0e45f36b0c 100644 --- a/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts @@ -4,7 +4,6 @@ import { Component, Injector, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { throwError } from 'rxjs'; import { catchError, finalize, switchMap } from 'rxjs/operators'; -import snq from 'snq'; import { eAccountComponents } from '../../enums/components'; import { AccountService } from '../../proxy/account/account.service'; import { RegisterDto } from '../../proxy/account/models'; @@ -88,11 +87,13 @@ export class RegisterComponent implements OnInit { ), catchError(err => { this.toasterService.error( - snq(() => err.error.error_description) || - snq(() => err.error.error.message, 'AbpAccount::DefaultErrorMessage'), - 'Error', + err.error?.error_description || + err.error?.error.message || + 'AbpAccount::DefaultErrorMessage', + null, { life: 7000 }, ); + return throwError(err); }), finalize(() => (this.inProgress = false)), diff --git a/npm/ng-packs/packages/core/ng-package.json b/npm/ng-packs/packages/core/ng-package.json index ff0fca7559..4639066002 100644 --- a/npm/ng-packs/packages/core/ng-package.json +++ b/npm/ng-packs/packages/core/ng-package.json @@ -10,7 +10,6 @@ "angular-oauth2-oidc", "just-compare", "just-clone", - "snq", "ts-toolbelt" ] } diff --git a/npm/ng-packs/packages/core/src/lib/directives/replaceable-template.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/replaceable-template.directive.ts index 0a5509aeec..f83af059f6 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/replaceable-template.directive.ts +++ b/npm/ng-packs/packages/core/src/lib/directives/replaceable-template.directive.ts @@ -13,7 +13,6 @@ import { import compare from 'just-compare'; import { Subscription } from 'rxjs'; import { filter } from 'rxjs/operators'; -import snq from 'snq'; import { ABP } from '../models/common'; import { ReplaceableComponents } from '../models/replaceable-components'; import { ReplaceableComponentsService } from '../services/replaceable-components.service'; @@ -99,7 +98,7 @@ export class ReplaceableTemplateDirective implements OnInit, OnChanges { } ngOnChanges(changes: SimpleChanges) { - if (snq(() => changes.data.currentValue.inputs) && this.defaultComponentRef) { + if (changes?.data?.currentValue?.inputs && this.defaultComponentRef) { this.setDefaultComponentInputs(); } } diff --git a/npm/ng-packs/packages/core/src/lib/directives/visibility.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/visibility.directive.ts index b85440d486..8e02ef5b87 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/visibility.directive.ts +++ b/npm/ng-packs/packages/core/src/lib/directives/visibility.directive.ts @@ -1,6 +1,5 @@ import { AfterViewInit, Directive, ElementRef, Input, Optional, Renderer2 } from '@angular/core'; import { Subject } from 'rxjs'; -import snq from 'snq'; /** * @@ -26,10 +25,8 @@ export class VisibilityDirective implements AfterViewInit { mutations.forEach(mutation => { if (!mutation.target) return; - const htmlNodes = snq( - () => Array.from(mutation.target.childNodes).filter(node => node instanceof HTMLElement), - [], - ); + const htmlNodes = + Array.from(mutation.target.childNodes).filter(node => node instanceof HTMLElement) || []; if (!htmlNodes.length) { this.removeFromDOM(); @@ -42,11 +39,9 @@ export class VisibilityDirective implements AfterViewInit { }); setTimeout(() => { - const htmlNodes = snq( - () => - Array.from(this.focusedElement.childNodes).filter(node => node instanceof HTMLElement), - [], - ); + const htmlNodes = + Array.from(this.focusedElement.childNodes).filter(node => node instanceof HTMLElement) || + []; if (!htmlNodes.length) this.removeFromDOM(); }, 0); diff --git a/npm/ng-packs/packages/core/src/lib/services/permission.service.ts b/npm/ng-packs/packages/core/src/lib/services/permission.service.ts index eb6b3fc75e..a1979bbe1e 100644 --- a/npm/ng-packs/packages/core/src/lib/services/permission.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/permission.service.ts @@ -1,9 +1,8 @@ import { Injectable } from '@angular/core'; import { map } from 'rxjs/operators'; -import snq from 'snq'; +import { ABP } from '../models/common'; import { ApplicationConfigurationDto } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models'; import { ConfigStateService } from './config-state.service'; -import { ABP } from '../models/common'; @Injectable({ providedIn: 'root' }) export class PermissionService { @@ -70,10 +69,10 @@ export class PermissionService { } protected mapToPolicies(applicationConfiguration: ApplicationConfigurationDto) { - return snq(() => applicationConfiguration.auth.grantedPolicies, {}); + return applicationConfiguration?.auth?.grantedPolicies || {}; } protected getPolicy(key: string, grantedPolicies: Record) { - return snq(() => grantedPolicies[key], false); + return grantedPolicies[key] || false; } } diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index 385bf6f634..7f771a3006 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -4,7 +4,6 @@ import { Action, createSelector, Selector, State, StateContext, Store } from '@n import compare from 'just-compare'; import { throwError } from 'rxjs'; import { catchError, distinctUntilChanged } from 'rxjs/operators'; -import snq from 'snq'; import { GetAppConfiguration, PatchConfigState, SetEnvironment } from '../actions/config.actions'; import { RestOccurError } from '../actions/rest.actions'; import { Config } from '../models/config'; @@ -76,7 +75,7 @@ export class ConfigState { static getFeature(key: string) { const selector = createSelector([ConfigState], (state: Config.State) => { - return snq(() => state.features.values[key]); + return state.features.values[key]; }); return selector; @@ -84,7 +83,7 @@ export class ConfigState { static getSetting(key: string) { const selector = createSelector([ConfigState], (state: Config.State) => { - return snq(() => state.setting.values[key]); + return state.setting.values[key]; }); return selector; @@ -92,7 +91,7 @@ export class ConfigState { static getSettings(keyword?: string) { const selector = createSelector([ConfigState], (state: Config.State) => { - const settings = snq(() => state.setting.values, {}); + const settings = state.setting.values || {}; if (!keyword) return settings; @@ -113,7 +112,7 @@ export class ConfigState { static getGrantedPolicy(key: string) { const selector = createSelector([ConfigState], (state: Config.State): boolean => { if (!key) return true; - const getPolicy = (k: string) => snq(() => state.auth.grantedPolicies[k], false); + const getPolicy = (k: string) => state.auth.grantedPolicies[k] || false; const orRegexp = /\|\|/g; const andRegexp = /&&/g; @@ -180,7 +179,7 @@ export class ConfigState { const sourceName = keys[0] || - snq(() => state.environment.localization.defaultResourceName) || + state.environment.localization?.defaultResourceName || state.localization.defaultResourceName; const sourceKey = keys[1]; diff --git a/npm/ng-packs/packages/core/src/lib/utils/localization-utils.ts b/npm/ng-packs/packages/core/src/lib/utils/localization-utils.ts index 0e22713449..02bbc3f338 100644 --- a/npm/ng-packs/packages/core/src/lib/utils/localization-utils.ts +++ b/npm/ng-packs/packages/core/src/lib/utils/localization-utils.ts @@ -1,4 +1,3 @@ -import snq from 'snq'; import { ApplicationLocalizationConfigurationDto } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models'; // This will not be necessary when only Angukar 9.1+ is supported @@ -14,7 +13,7 @@ export function createLocalizer(localization: ApplicationLocalizationConfigurati return (resourceName: string, key: string, defaultValue: string) => { if (resourceName === '_') return key; - const resource = snq(() => localization.values[resourceName]); + const resource = localization?.values?.[resourceName]; if (!resource) return defaultValue; diff --git a/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts b/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts index da533ba62a..5b13328f7b 100644 --- a/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts +++ b/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts @@ -18,7 +18,6 @@ import { AbstractControl, FormArray, FormBuilder, FormGroup } from '@angular/for import { Select, Store } from '@ngxs/store'; import { Observable } from 'rxjs'; import { finalize, pluck, switchMap, take } from 'rxjs/operators'; -import snq from 'snq'; import { CreateUser, DeleteUser, @@ -83,7 +82,7 @@ export class UsersComponent implements OnInit { }; get roleGroups(): FormGroup[] { - return snq(() => (this.form.get('roleNames') as FormArray).controls as FormGroup[], []); + return ((this.form.get('roleNames') as FormArray)?.controls as FormGroup[]) || []; } constructor( @@ -112,7 +111,7 @@ export class UsersComponent implements OnInit { this.fb.group({ [role.name]: [ this.selected.id - ? !!snq(() => this.selectedUserRoles.find(userRole => userRole.id === role.id)) + ? !!this.selectedUserRoles?.find(userRole => userRole.id === role.id) : role.isDefault, ], }), @@ -152,12 +151,10 @@ export class UsersComponent implements OnInit { if (!this.form.valid || this.modalBusy) return; this.modalBusy = true; - const { roleNames } = this.form.value; - const mappedRoleNames = snq( - () => - roleNames.filter(role => !!role[Object.keys(role)[0]]).map(role => Object.keys(role)[0]), - [], - ); + const { roleNames = [] } = this.form.value; + const mappedRoleNames = + roleNames.filter(role => !!role[Object.keys(role)[0]]).map(role => Object.keys(role)[0]) || + []; this.store .dispatch( diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/languages.component.ts b/npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/languages.component.ts index 293452979a..7ee1000007 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/languages.component.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/languages.component.ts @@ -2,7 +2,6 @@ import { ConfigStateService, LanguageInfo, SessionStateService } from '@abp/ng.c import { Component } from '@angular/core'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import snq from 'snq'; @Component({ selector: 'abp-languages', @@ -53,10 +52,7 @@ export class LanguagesComponent { return this.languages$.pipe( map( languages => - snq( - () => languages.find(lang => lang.cultureName === this.selectedLangCulture).displayName, - ), - '', + languages?.find(lang => lang.cultureName === this.selectedLangCulture).displayName || '', ), ); } @@ -64,9 +60,7 @@ export class LanguagesComponent { get dropdownLanguages$(): Observable { return this.languages$.pipe( map( - languages => - snq(() => languages.filter(lang => lang.cultureName !== this.selectedLangCulture)), - [], + languages => languages?.filter(lang => lang.cultureName !== this.selectedLangCulture) || [], ), ); } diff --git a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts index 0f792e8578..e52984db53 100644 --- a/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts +++ b/npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts @@ -22,7 +22,6 @@ import { import { NgbDateAdapter, NgbTimeAdapter } from '@ng-bootstrap/ng-bootstrap'; import { Observable, of } from 'rxjs'; import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; -import snq from 'snq'; import { DateAdapter } from '../../adapters/date.adapter'; import { TimeAdapter } from '../../adapters/time.adapter'; import { EXTRA_PROPERTIES_KEY } from '../../constants/extra-properties'; @@ -171,7 +170,7 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit { } ngOnChanges({ prop }: SimpleChanges) { - const currentProp = snq(() => prop.currentValue); + const currentProp = prop?.currentValue; const { options, readonly, disabled, validators } = currentProp || {}; if (options) this.options$ = options(this.data); diff --git a/npm/ng-packs/packages/theme-shared/src/lib/directives/table-sort.directive.ts b/npm/ng-packs/packages/theme-shared/src/lib/directives/table-sort.directive.ts index 011768be7b..90e8b5e6e1 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/directives/table-sort.directive.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/directives/table-sort.directive.ts @@ -10,7 +10,6 @@ import { SimpleChanges, } from '@angular/core'; import clone from 'just-clone'; -import snq from 'snq'; import { TableComponent } from '../components/table/table.component'; export interface TableSortOptions { @@ -35,7 +34,7 @@ export class TableSortDirective implements OnChanges { get table(): TableComponent | any { return ( - this.abpTable || snq(() => this.cdRef['_view'].component) || snq(() => this.cdRef['context']) // 'context' for ivy + this.abpTable || this.cdRef['_view'].component || this.cdRef['context'] // 'context' for ivy ); } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/utils/date-parser-formatter.ts b/npm/ng-packs/packages/theme-shared/src/lib/utils/date-parser-formatter.ts index b095ae821c..301a6cd26f 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/utils/date-parser-formatter.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/utils/date-parser-formatter.ts @@ -2,7 +2,6 @@ import { ApplicationLocalizationConfigurationDto, ConfigStateService } from '@ab import { formatDate } from '@angular/common'; import { Inject, Injectable, LOCALE_ID } from '@angular/core'; import { NgbDateParserFormatter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'; -import snq from 'snq'; function isNumber(value: any): boolean { return !isNaN(toInteger(value)); @@ -48,7 +47,7 @@ export class DateParserFormatter extends NgbDateParserFormatter { this.configState.getOne('localization'); const dateFormat = - snq(() => localization.currentCulture.dateTimeFormat.shortDatePattern) || 'yyyy-MM-dd'; + localization.currentCulture?.dateTimeFormat?.shortDatePattern || 'yyyy-MM-dd'; return formatDate(new Date(date.year, date.month - 1, date.day), dateFormat, this.locale); }