mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3190] Fix rerendering issue with content-meta-data (#3494)
* Fix rerendering issue with content-meta-data * Fix indentation
This commit is contained in:
committed by
Eugenio Romano
parent
ae73839e56
commit
737becd51f
@@ -23,20 +23,12 @@ import { By } from '@angular/platform-browser';
|
||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
import { ContentMetadataComponent } from './content-metadata.component';
|
||||
import { ContentMetadataService } from '../../services/content-metadata.service';
|
||||
import {
|
||||
CardViewBaseItemModel,
|
||||
CardViewComponent,
|
||||
CardViewUpdateService,
|
||||
NodesApiService,
|
||||
LogService,
|
||||
setupTestBed
|
||||
} from '@alfresco/adf-core';
|
||||
import { CardViewBaseItemModel, CardViewComponent, CardViewUpdateService, NodesApiService, LogService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
|
||||
describe('ContentMetadataComponent', () => {
|
||||
|
||||
let component: ContentMetadataComponent;
|
||||
let fixture: ComponentFixture<ContentMetadataComponent>;
|
||||
let node: MinimalNodeEntryEntity;
|
||||
@@ -45,9 +37,7 @@ describe('ContentMetadataComponent', () => {
|
||||
|
||||
setupTestBed({
|
||||
imports: [ContentTestingModule],
|
||||
providers: [
|
||||
{ provide: LogService, useValue: { error: jasmine.createSpy('error') } }
|
||||
]
|
||||
providers: [{ provide: LogService, useValue: { error: jasmine.createSpy('error') } }]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -81,7 +71,6 @@ describe('ContentMetadataComponent', () => {
|
||||
});
|
||||
|
||||
describe('Default input param values', () => {
|
||||
|
||||
it('should have editable input param as false by default', () => {
|
||||
expect(component.editable).toBe(false);
|
||||
});
|
||||
@@ -96,7 +85,6 @@ describe('ContentMetadataComponent', () => {
|
||||
});
|
||||
|
||||
describe('Folder', () => {
|
||||
|
||||
it('should show the folder node', () => {
|
||||
component.expanded = false;
|
||||
fixture.detectChanges();
|
||||
@@ -112,7 +100,6 @@ describe('ContentMetadataComponent', () => {
|
||||
});
|
||||
|
||||
describe('Saving', () => {
|
||||
|
||||
it('should save the node on itemUpdate', () => {
|
||||
const property = <CardViewBaseItemModel> { key: 'property-key', value: 'original-value' },
|
||||
updateService: CardViewUpdateService = fixture.debugElement.injector.get(CardViewUpdateService),
|
||||
@@ -139,7 +126,7 @@ describe('ContentMetadataComponent', () => {
|
||||
updateService.update(property, 'updated-value');
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.node).toBe(expectedNode);
|
||||
expect(component.node).toEqual(expectedNode);
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -160,9 +147,7 @@ describe('ContentMetadataComponent', () => {
|
||||
});
|
||||
|
||||
describe('Properties loading', () => {
|
||||
|
||||
let expectedNode,
|
||||
contentMetadataService: ContentMetadataService;
|
||||
let expectedNode, contentMetadataService: ContentMetadataService;
|
||||
|
||||
beforeEach(() => {
|
||||
expectedNode = Object.assign({}, node, { name: 'some-modified-value' });
|
||||
@@ -248,22 +233,5 @@ describe('ContentMetadataComponent', () => {
|
||||
expect(basicPropertiesComponent.displayEmpty).toBe(false);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be performed again if property updating occured, since the originally passed node has changed, so the previously calculated properties', () => {
|
||||
const property = <CardViewBaseItemModel> { key: 'property-key', value: 'original-value' },
|
||||
updateService = fixture.debugElement.injector.get(CardViewUpdateService),
|
||||
nodesApiService = TestBed.get(NodesApiService);
|
||||
|
||||
spyOn(nodesApiService, 'updateNode').and.callFake(() => Observable.of(node));
|
||||
spyOn(contentMetadataService, 'getBasicProperties');
|
||||
component.ngOnChanges({ node: new SimpleChange(null, node, true) });
|
||||
updateService.update(property, 'updated-value');
|
||||
|
||||
component.ngOnChanges({ expanded: new SimpleChange(false, true, false) });
|
||||
component.ngOnChanges({ expanded: new SimpleChange(true, false, false) });
|
||||
component.ngOnChanges({ expanded: new SimpleChange(false, true, false) });
|
||||
|
||||
expect(contentMetadataService.getBasicProperties).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, Input, OnChanges, OnInit, SimpleChanges, SimpleChange, ViewEncapsulation } from '@angular/core';
|
||||
import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core';
|
||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { CardViewItem, NodesApiService, LogService, CardViewUpdateService, AlfrescoApiService } from '@alfresco/adf-core';
|
||||
@@ -30,7 +30,6 @@ import { CardViewGroup } from '../../interfaces/content-metadata.interfaces';
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class ContentMetadataComponent implements OnChanges, OnInit {
|
||||
|
||||
/** (required) The node entity to fetch metadata about */
|
||||
@Input()
|
||||
node: MinimalNodeEntryEntity;
|
||||
@@ -57,35 +56,35 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
|
||||
@Input()
|
||||
preset: string;
|
||||
|
||||
nodeHasBeenUpdated: boolean = false;
|
||||
componentInited: boolean = false;
|
||||
basicProperties$: Observable<CardViewItem[]>;
|
||||
groupedProperties$: Observable<CardViewGroup[]>;
|
||||
|
||||
constructor(private contentMetadataService: ContentMetadataService,
|
||||
private cardViewUpdateService: CardViewUpdateService,
|
||||
private nodesApiService: NodesApiService,
|
||||
private logService: LogService,
|
||||
private alfrescoApiService: AlfrescoApiService) {}
|
||||
constructor(
|
||||
private contentMetadataService: ContentMetadataService,
|
||||
private cardViewUpdateService: CardViewUpdateService,
|
||||
private nodesApiService: NodesApiService,
|
||||
private logService: LogService,
|
||||
private alfrescoApiService: AlfrescoApiService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.cardViewUpdateService.itemUpdated$
|
||||
.switchMap(this.saveNode.bind(this))
|
||||
.subscribe(
|
||||
(node) => {
|
||||
this.nodeHasBeenUpdated = true;
|
||||
this.node = node;
|
||||
this.alfrescoApiService.nodeUpdated.next(node);
|
||||
},
|
||||
error => this.logService.error(error)
|
||||
);
|
||||
this.cardViewUpdateService.itemUpdated$.switchMap(this.saveNode.bind(this)).subscribe(
|
||||
updatedNode => {
|
||||
Object.assign(this.node, updatedNode);
|
||||
this.alfrescoApiService.nodeUpdated.next(this.node);
|
||||
},
|
||||
error => this.logService.error(error)
|
||||
);
|
||||
|
||||
this.componentInited = true;
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
const nodeChange: SimpleChange = changes['node'];
|
||||
if (nodeChange || this.nodeHasBeenUpdated) {
|
||||
const node = nodeChange && nodeChange.currentValue || this.node;
|
||||
this.nodeHasBeenUpdated = false;
|
||||
const changedNode: MinimalNodeEntryEntity = changes['node'] && changes['node'].currentValue;
|
||||
|
||||
if (!this.componentInited || (changedNode && changedNode !== this.node)) {
|
||||
const node = changedNode || this.node;
|
||||
this.basicProperties$ = this.contentMetadataService.getBasicProperties(node);
|
||||
this.groupedProperties$ = this.contentMetadataService.getGroupedProperties(node, this.preset);
|
||||
}
|
||||
|
Reference in New Issue
Block a user