Skip to content

Commit

Permalink
cleanup useless properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika committed Oct 21, 2023
1 parent 0b85a96 commit 6f61a25
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('MetadataTabComponent', () => {
allowableOperations: ['update']
} as Node;
component.ngOnInit();
expect(component.canUpdateNode).toBe(true);
expect(component.readOnly).toBe(true);
});

it('should return false if node is locked', () => {
Expand All @@ -119,7 +119,7 @@ describe('MetadataTabComponent', () => {
allowableOperations: ['update']
} as Node;
component.ngOnInit();
expect(component.canUpdateNode).toBe(false);
expect(component.readOnly).toBe(false);
});

it('should return false if node has no update permission', () => {
Expand All @@ -128,7 +128,7 @@ describe('MetadataTabComponent', () => {
allowableOperations: ['other']
} as Node;
component.ngOnInit();
expect(component.canUpdateNode).toBe(false);
expect(component.readOnly).toBe(false);
});

it('should return false if node has read only property', () => {
Expand All @@ -140,7 +140,7 @@ describe('MetadataTabComponent', () => {
}
} as Node;
component.ngOnInit();
expect(component.canUpdateNode).toBe(false);
expect(component.readOnly).toBe(false);
});

describe('set by triggering EditOfflineAction', () => {
Expand All @@ -159,40 +159,40 @@ describe('MetadataTabComponent', () => {
id: component.node.id
} as Node
});
component.canUpdateNode = true;
component.readOnly = true;
});

it('should have set true if node is not locked and has update permission', () => {
component.canUpdateNode = false;
component.readOnly = false;
actions$.next(editOfflineAction);
expect(component.canUpdateNode).toBeTrue();
expect(component.readOnly).toBeTrue();
});

it('should not have set false if changed node has different id than original', () => {
editOfflineAction.payload.entry.id = 'some other id';
editOfflineAction.payload.entry.isLocked = true;
actions$.next(editOfflineAction);
expect(component.canUpdateNode).toBeTrue();
expect(component.readOnly).toBeTrue();
});

it('should have set false if node is locked', () => {
editOfflineAction.payload.entry.isLocked = true;
actions$.next(editOfflineAction);
expect(component.canUpdateNode).toBeFalse();
expect(component.readOnly).toBeFalse();
});

it('should have set false if node has no update permission', () => {
editOfflineAction.payload.entry.allowableOperations = ['other'];
actions$.next(editOfflineAction);
expect(component.canUpdateNode).toBeFalse();
expect(component.readOnly).toBeFalse();
});

it('should have set false if node has read only property', () => {
editOfflineAction.payload.entry.properties = {
'cm:lockType': 'WRITE_LOCK'
};
actions$.next(editOfflineAction);
expect(component.canUpdateNode).toBeFalse();
expect(component.readOnly).toBeFalse();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ import { Actions, ofType } from '@ngrx/effects';
selector: 'app-metadata-tab',
template: `
<adf-content-metadata
[readOnly]="!canUpdateNode"
[readOnly]="readOnly"
[preset]="'custom'"
[node]="node"
[displayAspect]="displayAspect$ | async"
[customPanels]="customPanels | async"
[editable]="editable"
[editableTags]="editableTags"
[editableCategories]="editableCategories"
[group]="group"
>
</adf-content-metadata>
Expand All @@ -61,11 +59,9 @@ export class MetadataTabComponent implements OnInit, OnDestroy {
node: Node;

displayAspect$: Observable<string>;
canUpdateNode = false;
readOnly = false;
editable = false;
customPanels: Observable<ContentMetadataCustomPanel[]>;
editableTags = false;
editableCategories = false;
group: any = {
editable: false
};
Expand Down Expand Up @@ -98,12 +94,6 @@ export class MetadataTabComponent implements OnInit, OnDestroy {
)
.subscribe((updatedNode) => {
this.checkIfNodeIsUpdatable(updatedNode?.payload.entry);
if (!this.canUpdateNode) {
this.editable = false;
this.editableTags = false;
this.editableCategories = false;
this.group.editable = false;
}
});
this.customPanels = this.extensions.getCustomMetadataPanels({ entry: this.node }).pipe(
map((panels) => {
Expand All @@ -121,6 +111,6 @@ export class MetadataTabComponent implements OnInit, OnDestroy {
}

private checkIfNodeIsUpdatable(node: Node) {
this.canUpdateNode = node && !isLocked({ entry: node }) ? this.permission.check(node, ['update']) : false;
this.readOnly = !(node && !isLocked({ entry: node }) ? this.permission.check(node, ['update']) : false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<mat-progress-bar mode="indeterminate" [attr.aria-label]="'APP.INFO_DRAWER.DATA_LOADING' | translate"></mat-progress-bar>
</div>
<ng-container *ngIf="!isLoading && !!displayNode">
<adf-info-drawer [nodeIcon]="getNodeIcon(node?.entry)" [title]="node?.entry?.name || 'APP.INFO_DRAWER.TITLE'" cdkTrapFocus cdkTrapFocusAutoCapture>
<adf-info-drawer [icon]="icon" [title]="node?.entry?.name || 'APP.INFO_DRAWER.TITLE'" cdkTrapFocus cdkTrapFocusAutoCapture>
<aca-toolbar [items]="actions" info-drawer-buttons></aca-toolbar>

<adf-info-drawer-tab *ngFor="let tab of tabs" [icon]="tab.icon" [label]="tab.title">
<adf-dynamic-tab [node]="$any(displayNode)" [id]="tab.component" [attr.data-automation-id]="tab.component"> </adf-dynamic-tab>
</adf-info-drawer-tab>
</adf-info-drawer>
</ng-container>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class InfoDrawerComponent implements OnChanges, OnInit, OnDestroy {
actions: Array<ContentActionRef> = [];
onDestroy$ = new Subject<boolean>();
preventFromClosing = false;
icon: string = null;

@HostListener('keydown.escape')
onEscapeKeyboardEvent(): void {
Expand Down Expand Up @@ -124,9 +125,6 @@ export class InfoDrawerComponent implements OnChanges, OnInit, OnDestroy {

private setDisplayNode(node: any) {
this.displayNode = node;
}

getNodeIcon(node: Node): string {
return this.contentApi.getNodeIcon(node);
this.icon = this.contentApi.getNodeIcon(node);
}
}

0 comments on commit 6f61a25

Please sign in to comment.