[ACS-5703] Comment List code and styles cleanup (#8787)

* remove useless locale

* remove useless id values, update tests

* code cleanup

* fix formatting

* css cleanup

* code cleanup

* style cleanup

* fix css scope

* cleanup styles

* remove sanitise and don't bind to innerHTML

* reduce ng-container

* move model specific logic to Comment Model

* update tests, remove sanitise tests

* drop carma coverage to 72 as code removed

* drop selection animation as selection operations are not supported by the component itself

* cleanup css

* fix tests and lint

* update stories and tests

* fix line breaks

* move e2e to unit test

* disable search tests

* disable search tests

* disable search tests
This commit is contained in:
Denys Vuika
2023-07-31 19:23:46 +01:00
committed by GitHub
parent 312562889c
commit 3f3e83057d
21 changed files with 237 additions and 401 deletions

View File

@@ -19,15 +19,13 @@ import { CommentModel } from '../models/comment.model';
import {
Component,
EventEmitter,
Inject,
inject,
Input,
OnChanges,
Output,
SimpleChanges,
ViewEncapsulation
} from '@angular/core';
import { Observable, Observer } from 'rxjs';
import { share } from 'rxjs/operators';
import { ADF_COMMENTS_SERVICE } from './interfaces/comments.token';
import { CommentsService } from './interfaces/comments-service.interface';
@@ -49,27 +47,13 @@ export class CommentsComponent implements OnChanges {
/** Emitted when an error occurs while displaying/adding a comment. */
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
error = new EventEmitter<any>();
comments: CommentModel[] = [];
message: string;
beingAdded: boolean = false;
private commentObserver: Observer<CommentModel>;
comment$: Observable<CommentModel>;
constructor(@Inject(ADF_COMMENTS_SERVICE) private commentsService: CommentsService) {
this.comment$ = new Observable<CommentModel>((observer) => this.commentObserver = observer)
.pipe(
share()
);
this.comment$.subscribe((comment: CommentModel) => {
this.comments.push(comment);
});
}
private commentsService = inject<CommentsService>(ADF_COMMENTS_SERVICE);
ngOnChanges(changes: SimpleChanges): void {
this.id = null;
@@ -97,8 +81,7 @@ export class CommentsComponent implements OnChanges {
}
comments = this.sortedComments(comments);
this.addCommentsToObserver(comments);
this.comments.push(...comments);
},
(err) => {
this.error.emit(err);
@@ -111,11 +94,9 @@ export class CommentsComponent implements OnChanges {
return;
}
const comment: string = this.sanitize(this.message);
this.beingAdded = true;
this.commentsService.add(this.id, comment)
this.commentsService.add(this.id, this.message)
.subscribe(
(res: CommentModel) => {
this.addToComments(res);
@@ -164,20 +145,7 @@ export class CommentsComponent implements OnChanges {
});
}
private addCommentsToObserver(comments: CommentModel[]): void {
comments.forEach((currentComment: CommentModel) => {
this.commentObserver.next(currentComment);
});
}
private resetComments(): void {
this.comments = [];
}
private sanitize(input: string): string {
return input.replace(/^\s+|\s+$|\s+(?=\s)/g, '')
.replace(/&/g, '&amp;').replace(/</g, '&lt;')
.replace(/>/g, '&gt;').replace(/"/g, '&quot;')
.replace(/'/g, '&#039;').replace(/\r?\n/g, '<br/>');
}
}