Skip to content

Commit

Permalink
Merged in feature/SHIBUI-1437 (pull request #381)
Browse files Browse the repository at this point in the history
SHIBUI-1437 Integrated config component to replace summary

Approved-by: Dmitriy Kopylenko <dkopylenko@unicon.net>
  • Loading branch information
rmathis committed Oct 1, 2019
2 parents 58da1ac + 40feb8a commit 6ca0950
Show file tree
Hide file tree
Showing 29 changed files with 424 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
</div>
<metadata-configuration
[numbered]="false"
[editable]="false"
[configuration]="configuration"
[entity]="filter"
[definition]="definition"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ <h2 class="title h4 m-0 flex-grow-1">
</span>
<span class="text ml-2">{{ section.label | translate }}</span>
</h2>
<div class="actions px-2"
*ngIf="editable && configuration.dates.length === 1">
<div class="actions px-2" *ngIf="editable">
<button class="btn btn-link edit-link change-view" (click)="edit(section.id)">
<i class="fa fa-edit"></i>&nbsp;
<span translate="action.edit">Edit</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ describe('Metadata Configuration Component', () => {
}));

describe('edit method', () => {
it('should call router.navigate', () => {
spyOn(router, 'navigate');
it('should call onEdit.emit', () => {
spyOn(app.onEdit, 'emit');
app.edit('foo');
expect(router.navigate).toHaveBeenCalled();
expect(app.onEdit.emit).toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter, OnChanges } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { Component, Input, Output, EventEmitter, OnChanges } from '@angular/core';
import { MetadataConfiguration } from '../model/metadata-configuration';
import { Metadata } from '../../domain/domain.type';
import { CONFIG_DATE_FORMAT } from '../configuration.values';
Expand All @@ -14,25 +13,26 @@ export class MetadataConfigurationComponent implements OnChanges {
@Input() definition: any;
@Input() entity: Metadata;
@Input() numbered = true;
@Input() editable = true;

@Output() preview: EventEmitter<any> = new EventEmitter();
@Output() onEdit: EventEmitter<string> = new EventEmitter();

zero = false;

DATE_FORMAT = CONFIG_DATE_FORMAT;

constructor(
private router: Router,
private activatedRoute: ActivatedRoute
) {}

ngOnChanges(): void {
this.zero = !this.configuration.sections.some(s => !!s.properties.length);
if (this.configuration) {
this.zero = !this.configuration.sections.some(s => !!s.properties.length);
}
}

get editable(): boolean {
return !!this.onEdit.observers.length;
}

edit(id: string): void {
this.router.navigate(['../', 'edit', id], { relativeTo: this.activatedRoute.parent });
this.onEdit.emit(id);
}

onPreview($event): void {
Expand Down
7 changes: 5 additions & 2 deletions ui/src/app/metadata/configuration/configuration.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ import { FilterCompareVersionEffects } from './effect/filter.effect';
WizardModule,
FormModule
],
exports: [],
exports: [
MetadataConfigurationComponent
],
providers: [
DatePipe,
IndexResolver
Expand Down Expand Up @@ -114,7 +116,8 @@ export class MetadataConfigurationModule {
RestoreEffects,
FilterCompareVersionEffects,
VersionEffects
])
]
)
],
providers: []
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ <h2 class="mb-4" [ngSwitch]="type$ | async">
</button>
</div>
<metadata-configuration
[configuration]="versions$ | async"
[editable]="false"></metadata-configuration>

[configuration]="versions$ | async"></metadata-configuration>
<div class="numbered-header d-flex justify-content-start bg-light align-items-center py-1">
<h2 class="title h4 m-0 flex-grow-1">
<span class="text ml-2" translate="label.metadata-filter">Metadata Filter</span>
Expand All @@ -41,8 +39,7 @@ <h2 class="title h4 m-0 flex-grow-1">
<ng-container *ngIf="(filterCompare$ | async)">
<br />
<metadata-configuration
[configuration]="filterCompare$ | async"
[editable]="false"></metadata-configuration>
[configuration]="filterCompare$ | async"></metadata-configuration>
<div class="d-flex justify-content-end my-2">
<button class="btn btn-success" (click)="resetCompareFilters()">
<i class="fa fa-arrow-left" aria-hidden="true"></i>&nbsp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ <h2 class="mb-4" [ngSwitch]="type$ | async">
</div>
</div>
<ng-container *ngIf="configuration$ | async">
<metadata-configuration [configuration]="configuration$ | async" id="configuration"></metadata-configuration>
<metadata-configuration
[configuration]="configuration$ | async"
(onEdit)="edit($event)"
id="configuration">
</metadata-configuration>
</ng-container>
<ng-container *ngIf="!(configuration$ | async)">
<div class="d-flex justify-content-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Store } from '@ngrx/store';
import { Component, ChangeDetectionStrategy, OnDestroy } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { Router } from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
import { ViewportScroller } from '@angular/common';
import { takeUntil, filter } from 'rxjs/operators';

Expand Down Expand Up @@ -53,7 +53,9 @@ export class MetadataOptionsComponent implements OnDestroy {
constructor(
protected store: Store<ConfigurationState>,
protected modalService: NgbModal,
protected scroller: ViewportScroller
protected scroller: ViewportScroller,
protected router: Router,
protected activatedRoute: ActivatedRoute
) {
this.model$
.pipe(
Expand All @@ -63,6 +65,10 @@ export class MetadataOptionsComponent implements OnDestroy {
.subscribe(p => this.setModel(p));
}

edit(id: string) {
this.router.navigate(['../', 'edit', id], { relativeTo: this.activatedRoute.parent });
}

setModel(data: Metadata): void {
this.id = 'resourceId' in data ? data.resourceId : data.id;
this.kind = '@type' in data ? 'provider' : 'resolver';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ <h2 class="mb-4" [ngSwitch]="type$ | async">
</div>
<metadata-configuration
[configuration]="configuration$ | async"
[editable]="false"
id="configuration">
</metadata-configuration>
<div *ngIf="kind === 'provider'" id="filters">
Expand Down
118 changes: 3 additions & 115 deletions ui/src/app/metadata/configuration/reducer/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,143 +1,31 @@
import {
getConfigurationSectionsFn,
getConfigurationModelNameFn,
getConfigurationModelEnabledFn,
assignValueToProperties,
getLimitedPropertiesFn,
getConfigurationModelTypeFn,
getSelectedVersionNumberFn,
getSelectedIsCurrentFn
} from './index';
import { SCHEMA as schema } from '../../../../testing/form-schema.stub';

import { Metadata } from '../../domain/domain.type';
import { MockMetadataWizard } from '../../../../testing/mockMetadataWizard';

describe('Configuration Reducer', () => {
const model = {
name: 'foo',
serviceEnabled: true,
foo: {
bar: 'bar',
baz: 'baz'
},
list: [
'super',
'cool'
]
};

const props = [
{
id: 'name',
items: null,
name: 'label.metadata-provider-name-dashboard-display-only',
properties: [],
type: 'string',
value: null,
widget: { id: 'string', help: 'message.must-be-unique' }
},
{
id: 'serviceEnabled',
items: null,
name: 'serviceEnabled',
properties: [],
type: 'string',
value: null,
widget: { id: 'select', disabled: true }
},
{
id: 'foo',
items: null,
name: 'foo',
type: 'object',
properties: [
{
id: 'bar',
name: 'bar',
type: 'string',
properties: []
},
{
id: 'baz',
name: 'baz',
type: 'string',
properties: []
}
]
},
{
id: 'list',
name: 'list',
type: 'array',
items: {
type: 'string'
},
widget: {
id: 'datalist',
data: [
{ key: 'super', label: 'super' },
{ key: 'cool', label: 'cool' },
{ key: 'notcool', label: 'notcool' }
]
}
}
];

const definition = MockMetadataWizard;

describe('getConfigurationSectionsFn', () => {
it('should parse the schema, definition, and model into a MetadataConfiguration', () => {
const config = getConfigurationSectionsFn([model], definition, schema);
expect(config.sections).toBeDefined();
});
});

describe('getConfigurationModelNameFn function', () => {
it('should return the name attribute', () => {
expect(getConfigurationModelNameFn({ serviceProviderName: 'foo' } as Metadata)).toBe('foo');
expect(getConfigurationModelNameFn({ name: 'bar' } as Metadata)).toBe('bar');
expect(getConfigurationModelNameFn(null)).toBe(false);
expect(getConfigurationModelNameFn(null)).toBe('');
});
});

describe('getConfigurationModelEnabledFn function', () => {
it('should return the name attribute', () => {
it('should return the enabled attribute', () => {
expect(getConfigurationModelEnabledFn({ serviceEnabled: true } as Metadata)).toBe(true);
expect(getConfigurationModelEnabledFn({ enabled: true } as Metadata)).toBe(true);
expect(getConfigurationModelEnabledFn(null)).toBe(false);
});
});

describe('assignValueToProperties function', () => {
it('should assign appropriate values to the given schema properties', () => {
const assigned = assignValueToProperties([model], props, definition);
expect(assigned[0].value).toEqual(['foo']);
expect(assigned[1].value).toEqual([true]);
});

it('should assign differences when passed multiple models', () => {
const assigned = assignValueToProperties([model, {
...model,
name: 'bar',
list: [
'super',
'notcool'
]
}], props, definition);
expect(assigned[0].differences).toBe(true);
});
});

describe('getLimitedPropertiesFn function', () => {
it('should filter properties without differences', () => {
const assigned = assignValueToProperties([model, {
...model,
name: 'bar'
}], props, definition);
expect(getLimitedPropertiesFn(assigned).length).toBe(1);
});
});

describe('getConfigurationModelTypeFn function ', () => {
it('should return provider type if the object has an @type property', () => {
const md = { '@type': 'FilebackedHttpMetadataResolver' } as Metadata;
Expand Down
Loading

0 comments on commit 6ca0950

Please sign in to comment.