mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACS-5088] Replaced function calls in templates with variable references (#3227)
* [ACS-5088] Replaced method calls in templates with variables * [ACS-5088] Replaced method calls in templates with variables * [ACS-5088] Replaced method calls for *ngIf and *ngFor with variables - Batch 1 (WIP) * [ACS-5088] Replaced method calls for *ngIf and *ngFor with variables - Batch 2 (WIP) * [ACS-5088] Replaced instances of $any with cast pipe. Replaced other instances of method calls in templates with variables * [ACS-5088] Resolved test cases * [ACS-5088] Resolved test cases in aca-content library * [ACS-5088] Resolved test cases in aca-shared library * [ACS-5088] Resolved test cases in aca-folder-rules library * [ACS-5088] Reverted usage of cast pipe to $any() * [ACS-5088] Fixed incorrect revert * [ACS-5088] Resolved code review findings - shortened expressions and made onDestroy subjects use void instead of boolean * [ACS-5088] Resolved code review findings - changed parameter name in sort function * [ACS-5088] Resolved code review findings - added 'void' type to onDestroy subjects * [ACS-5088] Upgraded eslint version to 8.41.0. Added "@angular-eslint/template/no-call-expression" rule to prevent function calls in templates unless needed (reports warnings) * [ACS-5088] Resolved typo in ToggleFavoriteComponent
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<ng-container *ngIf="selection$ | async as selection">
|
||||
<ng-container *ngIf="selectionState">
|
||||
<ng-container *ngIf="!data.iconButton">
|
||||
<button mat-menu-item data-automation-id="share-action-button" (click)="editSharedNode(selection, '.adf-context-menu-source')">
|
||||
<button mat-menu-item data-automation-id="share-action-button" (click)="editSharedNode(selectionState, '.adf-context-menu-source')">
|
||||
<mat-icon>link</mat-icon>
|
||||
<ng-container *ngIf="isShared(selection); else not_shared">
|
||||
<ng-container *ngIf="isShared; else not_shared">
|
||||
<span>{{ 'APP.ACTIONS.SHARE_EDIT' | translate }}</span>
|
||||
</ng-container>
|
||||
</button>
|
||||
@@ -12,9 +12,9 @@
|
||||
<button
|
||||
mat-icon-button
|
||||
data-automation-id="share-action-button"
|
||||
(click)="editSharedNode(selection, '#share-action-button')"
|
||||
[attr.aria-label]="getLabel(selection) | translate"
|
||||
[attr.title]="getLabel(selection) | translate"
|
||||
(click)="editSharedNode(selectionState, '#share-action-button')"
|
||||
[attr.aria-label]="selectionLabel | translate"
|
||||
[attr.title]="selectionLabel | translate"
|
||||
id="share-action-button"
|
||||
>
|
||||
<mat-icon>link</mat-icon>
|
||||
|
@@ -56,14 +56,14 @@ describe('ToggleSharedComponent', () => {
|
||||
it('should return false when entry is not shared', () => {
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.isShared({ first: { entry } })).toBe(false);
|
||||
expect(component.isShared).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when entry is shared', () => {
|
||||
entry.properties['qshare:sharedId'] = 'some-id';
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.isShared({ first: { entry } })).toBe(true);
|
||||
expect(component.isShared).toBe(true);
|
||||
});
|
||||
|
||||
it('should dispatch `SHARE_NODE` action on share', () => {
|
||||
@@ -74,7 +74,7 @@ describe('ToggleSharedComponent', () => {
|
||||
|
||||
it('should get action label for unshared file', () => {
|
||||
component.ngOnInit();
|
||||
const label = component.getLabel({ first: { entry } });
|
||||
const label = component.selectionLabel;
|
||||
|
||||
expect(label).toBe('APP.ACTIONS.SHARE');
|
||||
});
|
||||
@@ -82,7 +82,7 @@ describe('ToggleSharedComponent', () => {
|
||||
it('should get action label for shared file', () => {
|
||||
entry.properties['qshare:sharedId'] = 'some-id';
|
||||
component.ngOnInit();
|
||||
const label = component.getLabel({ first: { entry } });
|
||||
const label = component.selectionLabel;
|
||||
|
||||
expect(label).toBe('APP.ACTIONS.SHARE_EDIT');
|
||||
});
|
||||
|
@@ -22,8 +22,8 @@
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, OnInit, Input } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Component, OnInit, Input, OnDestroy } from '@angular/core';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { SelectionState } from '@alfresco/adf-extensions';
|
||||
import { AppStore, ShareNodeAction, getAppSelection } from '@alfresco/aca-shared/store';
|
||||
@@ -32,6 +32,7 @@ import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
@@ -39,29 +40,38 @@ import { MatButtonModule } from '@angular/material/button';
|
||||
selector: 'app-toggle-shared',
|
||||
templateUrl: './toggle-shared.component.html'
|
||||
})
|
||||
export class ToggleSharedComponent implements OnInit {
|
||||
export class ToggleSharedComponent implements OnInit, OnDestroy {
|
||||
@Input()
|
||||
data: {
|
||||
iconButton?: string;
|
||||
};
|
||||
|
||||
selection$: Observable<SelectionState>;
|
||||
selectionState: SelectionState;
|
||||
selectionLabel = '';
|
||||
isShared = false;
|
||||
|
||||
onDestroy$ = new Subject<void>();
|
||||
|
||||
constructor(private store: Store<AppStore>) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.selection$ = this.store.select(getAppSelection);
|
||||
this.selection$.pipe(takeUntil(this.onDestroy$)).subscribe((selectionState) => {
|
||||
this.selectionState = selectionState;
|
||||
|
||||
this.isShared =
|
||||
(this.selectionState.first && this.selectionState.first.entry && (this.selectionState.first.entry as any).sharedByUser) ||
|
||||
!!this.selectionState?.first?.entry?.properties?.['qshare:sharedId'];
|
||||
|
||||
this.selectionLabel = this.isShared ? 'APP.ACTIONS.SHARE_EDIT' : 'APP.ACTIONS.SHARE';
|
||||
});
|
||||
}
|
||||
|
||||
isShared(selection: SelectionState) {
|
||||
// workaround for shared files
|
||||
if (selection.first && selection.first.entry && (selection.first.entry as any).sharedByUser) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return selection.first && selection.first.entry && selection.first.entry.properties && !!selection.first.entry.properties['qshare:sharedId'];
|
||||
ngOnDestroy(): void {
|
||||
this.onDestroy$.next();
|
||||
this.onDestroy$.complete();
|
||||
}
|
||||
|
||||
editSharedNode(selection: SelectionState, focusedElementOnCloseSelector: string) {
|
||||
this.store.dispatch(
|
||||
new ShareNodeAction(selection.first, {
|
||||
@@ -69,8 +79,4 @@ export class ToggleSharedComponent implements OnInit {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getLabel(selection: SelectionState): string {
|
||||
return this.isShared(selection) ? 'APP.ACTIONS.SHARE_EDIT' : 'APP.ACTIONS.SHARE';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user