Skip to content

Commit

Permalink
[ACS-7597] Convert Core pipes to Standalone # (#9560)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika authored Apr 16, 2024
1 parent 7854cde commit eaad09b
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 118 deletions.
5 changes: 4 additions & 1 deletion lib/core/src/lib/pipes/date-time.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import { Pipe, PipeTransform } from '@angular/core';
import { addMinutes, fromUnixTime, parse } from 'date-fns';

@Pipe({ name: 'adfDateTime' })
@Pipe({
name: 'adfDateTime',
standalone: true
})
export class DateTimePipe implements PipeTransform {
transform(value: string | Date | number, dateFormat: string): Date {
let parsedValue: Date;
Expand Down
3 changes: 2 additions & 1 deletion lib/core/src/lib/pipes/decimal-number.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { takeUntil } from 'rxjs/operators';

@Pipe({
name: 'adfDecimalNumber',
pure: false
pure: false,
standalone: true
})
export class DecimalNumberPipe implements PipeTransform, OnDestroy {
static DEFAULT_LOCALE = 'en-US';
Expand Down
8 changes: 3 additions & 5 deletions lib/core/src/lib/pipes/file-size.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import { TranslationService } from '../translation/translation.service';

@Pipe({
name: 'adfFileSize',
pure: false
pure: false,
standalone: true
})
export class FileSizePipe implements PipeTransform {

constructor(private translation: TranslationService) {
}
constructor(private translation: TranslationService) {}

transform(paramByte: any, decimals: number = 2): string {
if (paramByte == null) {
Expand All @@ -49,5 +48,4 @@ export class FileSizePipe implements PipeTransform {

return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + i18nSize;
}

}
8 changes: 3 additions & 5 deletions lib/core/src/lib/pipes/file-type.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ import { PipeTransform, Pipe } from '@angular/core';

@Pipe({
name: 'fileType',
pure: true
pure: true,
standalone: true
})
export class FileTypePipe implements PipeTransform {

transform(value: string) {

if ( value == null ) {
if (value == null) {
return '';
} else {
const fileInfo = value.substring(value.lastIndexOf('/') + 1).replace(/\.[a-z]+/, '');
return fileInfo.split('_').pop();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'filterOutEvery' })
@Pipe({
name: 'filterOutEvery',
standalone: true
})
export class FilterOutArrayObjectsByPropPipe<T> implements PipeTransform {
transform(values: T[], filterKey: string, filterValue: any): T[] {
return (values ?? []).filter(value => value[filterKey] !== filterValue);
return (values ?? []).filter((value) => value[filterKey] !== filterValue);
}
}
10 changes: 5 additions & 5 deletions lib/core/src/lib/pipes/filter-string.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'filterString' })
@Pipe({
name: 'filterString',
standalone: true
})
export class FilterStringPipe implements PipeTransform {

transform(value: string = '', filterBy: string = ''): string {
const testResult = filterBy ?
value.toLowerCase().indexOf(filterBy.toLowerCase()) > -1 :
true;
const testResult = filterBy ? value.toLowerCase().indexOf(filterBy.toLowerCase()) > -1 : true;

return testResult ? value : '';
}
Expand Down
10 changes: 5 additions & 5 deletions lib/core/src/lib/pipes/format-space.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'formatSpace'
name: 'formatSpace',
standalone: true
})
export class FormatSpacePipe implements PipeTransform {

transform(inputValue: string, replaceChar: string = '_', lowerCase: boolean = true): string {
let transformedString = '';
if (inputValue) {
transformedString = lowerCase ? inputValue.trim().split(' ').join(replaceChar).toLocaleLowerCase() :
inputValue.trim().split(' ').join(replaceChar);
transformedString = lowerCase
? inputValue.trim().split(' ').join(replaceChar).toLocaleLowerCase()
: inputValue.trim().split(' ').join(replaceChar);
}
return transformedString;
}

}
8 changes: 5 additions & 3 deletions lib/core/src/lib/pipes/full-name.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import { Pipe, PipeTransform } from '@angular/core';
import { UserLike } from './user-like.interface';

@Pipe({ name: 'fullName' })
@Pipe({
name: 'fullName',
standalone: true
})
export class FullNamePipe implements PipeTransform {

transform(user: UserLike): string {
return this.buildFullName(user) ? this.buildFullName(user) : this.buildFromUsernameOrEmail(user);
}
Expand All @@ -35,6 +37,6 @@ export class FullNamePipe implements PipeTransform {
}

buildFromUsernameOrEmail(user: UserLike): string {
return (user?.username || user?.email) ?? '' ;
return (user?.username || user?.email) ?? '';
}
}
6 changes: 3 additions & 3 deletions lib/core/src/lib/pipes/localized-role.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { Pipe, PipeTransform } from '@angular/core';
import { TranslationService } from '../translation/translation.service';

@Pipe({
name: 'adfLocalizedRole'
name: 'adfLocalizedRole',
standalone: true
})
export class LocalizedRolePipe implements PipeTransform {
constructor(private translationService: TranslationService) {
}
constructor(private translationService: TranslationService) {}

transform(value: string): any {
if (value) {
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/lib/pipes/mime-type-icon.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { Pipe, PipeTransform } from '@angular/core';
import { ThumbnailService } from '../common/services/thumbnail.service';

@Pipe({
name: 'adfMimeTypeIcon'
name: 'adfMimeTypeIcon',
standalone: true
})
export class MimeTypeIconPipe implements PipeTransform {

constructor(private thumbnailService: ThumbnailService) { }
constructor(private thumbnailService: ThumbnailService) {}

transform(text: string): string {
return this.thumbnailService.getMimeTypeIcon(text);
Expand Down
5 changes: 4 additions & 1 deletion lib/core/src/lib/pipes/moment-date.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ declare let moment: any;
/**
* @deprecated this pipe is deprecated and should no longer be used
*/
@Pipe({ name: 'adfMomentDate' })
@Pipe({
name: 'adfMomentDate',
standalone: true
})
export class MomentDatePipe implements PipeTransform {
transform(value: any, dateFormat: string): any {
return moment(value, dateFormat);
Expand Down
5 changes: 4 additions & 1 deletion lib/core/src/lib/pipes/moment-datetime.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ declare let moment: any;
/**
* @deprecated this pipe is deprecated and should no longer be used
*/
@Pipe({ name: 'adfMomentDateTime' })
@Pipe({
name: 'adfMomentDateTime',
standalone: true
})
export class MomentDateTimePipe implements PipeTransform {
transform(value: any, dateFormat: string): any {
return moment(value, dateFormat).add(moment(value, dateFormat).utcOffset(), 'minutes');
Expand Down
11 changes: 3 additions & 8 deletions lib/core/src/lib/pipes/multi-value.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,16 @@
import { MultiValuePipe } from './multi-value.pipe';
import { TestBed } from '@angular/core/testing';
import { CoreTestingModule } from '../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';

describe('FullNamePipe', () => {

describe('MultiValuePipe', () => {
let pipe: MultiValuePipe;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CoreTestingModule
]
imports: [CoreTestingModule, MultiValuePipe]
});
pipe = TestBed.inject(MultiValuePipe);
});
});

it('should add the separator when a string list is provided', () => {
const values = ['cat', 'house', 'dog'];
Expand Down
7 changes: 4 additions & 3 deletions lib/core/src/lib/pipes/multi-value.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'multiValue' })
@Pipe({
name: 'multiValue',
standalone: true
})
export class MultiValuePipe implements PipeTransform {

static DEFAULT_SEPARATOR = ', ';

transform(values: any | any[], valueSeparator: string = MultiValuePipe.DEFAULT_SEPARATOR): string {

if (values && values instanceof Array) {
return values.join(valueSeparator);
}
Expand Down
91 changes: 28 additions & 63 deletions lib/core/src/lib/pipes/pipe.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { FileSizePipe } from './file-size.pipe';
Expand All @@ -30,73 +29,39 @@ import { MultiValuePipe } from './multi-value.pipe';
import { LocalizedDatePipe } from './localized-date.pipe';
import { DecimalNumberPipe } from './decimal-number.pipe';
import { LocalizedRolePipe } from './localized-role.pipe';
import { TranslateModule } from '@ngx-translate/core';
import { MomentDatePipe } from './moment-date.pipe';
import { MomentDateTimePipe } from './moment-datetime.pipe';
import { FilterStringPipe } from './filter-string.pipe';
import { FilterOutArrayObjectsByPropPipe } from './filter-out-every-object-by-prop.pipe';
import { DateTimePipe } from './date-time.pipe';

export const CORE_PIPES = [
LocalizedDatePipe,
TimeAgoPipe,
FileSizePipe,
HighlightPipe,
MimeTypeIconPipe,
FullNamePipe,
FormatSpacePipe,
FileTypePipe,
MultiValuePipe,
DecimalNumberPipe,
LocalizedRolePipe,
MomentDatePipe,
MomentDateTimePipe,
DateTimePipe,
FilterStringPipe,
FilterOutArrayObjectsByPropPipe,
InitialUsernamePipe
] as const;

/**
* @deprecated this Module is deprecated and should no longer be used.
* Consider importing CORE_PIPES or individual pipes directly.
*/
@NgModule({
imports: [
CommonModule,
TranslateModule,
LocalizedDatePipe,
TimeAgoPipe
],
declarations: [
FileSizePipe,
HighlightPipe,
MimeTypeIconPipe,
InitialUsernamePipe,
FullNamePipe,
FormatSpacePipe,
FileTypePipe,
MultiValuePipe,
DecimalNumberPipe,
LocalizedRolePipe,
MomentDatePipe,
MomentDateTimePipe,
DateTimePipe,
FilterStringPipe,
FilterOutArrayObjectsByPropPipe
],
providers: [
FileSizePipe,
HighlightPipe,
TimeAgoPipe,
MimeTypeIconPipe,
InitialUsernamePipe,
FormatSpacePipe,
FileTypePipe,
MultiValuePipe,
DecimalNumberPipe,
LocalizedRolePipe,
MomentDatePipe,
MomentDateTimePipe,
DateTimePipe,
FilterStringPipe,
FilterOutArrayObjectsByPropPipe,
LocalizedDatePipe
],
exports: [
FileSizePipe,
HighlightPipe,
TimeAgoPipe,
MimeTypeIconPipe,
InitialUsernamePipe,
FullNamePipe,
FormatSpacePipe,
FileTypePipe,
MultiValuePipe,
DecimalNumberPipe,
LocalizedRolePipe,
MomentDatePipe,
MomentDateTimePipe,
DateTimePipe,
FilterStringPipe,
FilterOutArrayObjectsByPropPipe
]
imports: [...CORE_PIPES],
providers: [...CORE_PIPES],
exports: [...CORE_PIPES]
})
export class PipeModule {
}
export class PipeModule {}
6 changes: 3 additions & 3 deletions lib/core/src/lib/pipes/text-highlight.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { Pipe, PipeTransform } from '@angular/core';
import { HighlightTransformService, HighlightTransformResult } from '../common/services/highlight-transform.service';

@Pipe({
name: 'highlight'
name: 'highlight',
standalone: true
})
export class HighlightPipe implements PipeTransform {

constructor(private highlightTransformService: HighlightTransformService) { }
constructor(private highlightTransformService: HighlightTransformService) {}

transform(text: string, search: string): string {
const highlightTransformResult: HighlightTransformResult = this.highlightTransformService.highlight(text, search);
Expand Down
11 changes: 5 additions & 6 deletions lib/core/src/lib/pipes/user-initial.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { UserLike } from './user-like.interface';

@Pipe({
name: 'usernameInitials'
name: 'usernameInitials',
standalone: true
})
export class InitialUsernamePipe implements PipeTransform {

constructor(private sanitized: DomSanitizer) {
}
constructor(private sanitized: DomSanitizer) {}

transform(user: UserLike & { displayName?: string }, className: string = '', delimiter: string = ''): SafeHtml {
let safeHtml: SafeHtml = '';
Expand All @@ -42,8 +41,8 @@ export class InitialUsernamePipe implements PipeTransform {
}

getInitialUserName(firstName: string, lastName: string, delimiter: string): string {
firstName = (firstName ? firstName[0] : '');
lastName = (lastName ? lastName[0] : '');
firstName = firstName ? firstName[0] : '';
lastName = lastName ? lastName[0] : '';
return firstName + delimiter + lastName;
}
}

0 comments on commit eaad09b

Please sign in to comment.