Skip to content

Commit

Permalink
Merged in bugfix/SHIBUI-1224 (pull request #405)
Browse files Browse the repository at this point in the history
SHIBUI-1224 Fixed issue with org data
  • Loading branch information
rmathis committed Oct 30, 2019
2 parents c2160b5 + 1120bd6 commit 432c169
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 23 deletions.
16 changes: 12 additions & 4 deletions ui/src/app/metadata/resolver/action/entity.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { MetadataResolver } from '../../domain/model';
export enum ResolverEntityActionTypes {
UPDATE_STATUS = '[Resolver Entity] Update Status',
UPDATE_SAVING = '[Resolver Entity] Update Saving',
UPDATE_CHANGES = '[Resolver Entity] Update Changes',
UPDATE_CHANGES_REQUEST = '[Resolver Entity] Update Changes Request',
UPDATE_CHANGES_SUCCESS = '[Resolver Entity] Update Changes Success',
CLEAR = '[Resolver Entity] Clear',
CANCEL = '[Resolver Entity] Cancel'
}
Expand All @@ -15,8 +16,14 @@ export class UpdateStatus implements Action {
constructor(public payload: { [key: string]: string }) { }
}

export class UpdateChanges implements Action {
readonly type = ResolverEntityActionTypes.UPDATE_CHANGES;
export class UpdateChangesRequest implements Action {
readonly type = ResolverEntityActionTypes.UPDATE_CHANGES_REQUEST;

constructor(public payload: MetadataResolver) { }
}

export class UpdateChangesSuccess implements Action {
readonly type = ResolverEntityActionTypes.UPDATE_CHANGES_SUCCESS;

constructor(public payload: MetadataResolver) { }
}
Expand All @@ -41,6 +48,7 @@ export class Cancel implements Action {

export type ResolverEntityActionUnion =
| UpdateStatus
| UpdateChanges
| UpdateChangesRequest
| UpdateChangesSuccess
| UpdateSaving
| Clear;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LockEditor, UnlockEditor } from '../../../wizard/action/wizard.action';

import * as fromWizard from '../../../wizard/reducer';
import { withLatestFrom, map, distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
import { UpdateChanges } from '../action/entity.action';
import { UpdateChangesRequest } from '../action/entity.action';
import { FormControl } from '@angular/forms';

@Component({
Expand Down Expand Up @@ -103,7 +103,7 @@ export class ResolverEditStepComponent implements OnDestroy {
map(([valueChange, definition, resolver, changes]) => definition.parser({ ...resolver, ...changes, ...valueChange }))
)
.subscribe(changes => {
this.store.dispatch(new UpdateChanges(changes));
this.store.dispatch(new UpdateChangesRequest(changes));
});

this.statusChangeEmitted$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Store } from '@ngrx/store';
import * as fromResolver from '../reducer';
import * as fromWizard from '../../../wizard/reducer';

import { UpdateStatus, UpdateChanges } from '../action/entity.action';
import { UpdateStatus, UpdateChangesRequest } from '../action/entity.action';
import { Wizard } from '../../../wizard/model';
import { MetadataResolver } from '../../domain/model';

Expand Down Expand Up @@ -82,10 +82,14 @@ export class ResolverWizardStepComponent implements OnDestroy {
map(([ changes, definition ]) => definition.parser(changes.value))
)
.subscribe(changes => {
this.store.dispatch(new UpdateChanges(changes));
this.store.dispatch(new UpdateChangesRequest(changes));
});

this.statusChangeEmitted$.pipe(distinctUntilChanged()).subscribe(errors => this.updateStatus(errors));
this.statusChangeEmitted$
.pipe(distinctUntilChanged())
.subscribe(errors => {
this.updateStatus(errors);
});

this.store.select(fromWizard.getWizardIndex).subscribe(i => this.currentPage = i);
}
Expand Down
2 changes: 0 additions & 2 deletions ui/src/app/metadata/resolver/effect/collection.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ import {
CreateResolverFromUrlRequest
} from '../action/collection.action';
import * as draftActions from '../action/draft.action';
import { } from '../action/collection.action';
import { ResolverService } from '../../domain/service/resolver.service';
import { removeNulls } from '../../../shared/util';
import { AddNotification } from '../../../notification/action/notification.action';
import { Notification, NotificationType } from '../../../notification/model/notification';
import { I18nService } from '../../../i18n/service/i18n.service';
import * as fromRoot from '../../../app.reducer';
import * as fromI18n from '../../../i18n/reducer';
import { FileBackedHttpMetadataResolver } from '../../domain/entity';
import { UpdateSaving } from '../action/entity.action';


Expand Down
24 changes: 23 additions & 1 deletion ui/src/app/metadata/resolver/effect/entity.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { switchMap, map, withLatestFrom, tap } from 'rxjs/operators';

import * as fromResolver from '../reducer';
import * as fromRoot from '../../../app.reducer';
import * as fromWizard from '../../../wizard/reducer';

import {
ResolverEntityActionTypes,
Clear,
Cancel
Cancel,
UpdateChangesRequest,
UpdateChangesSuccess
} from '../action/entity.action';
import * as provider from '../action/collection.action';

Expand All @@ -24,6 +27,25 @@ import { ContentionService } from '../../../contention/service/contention.servic
@Injectable()
export class EntityEffects {

@Effect()
updateChanges$ = this.actions$.pipe(
ofType<UpdateChangesRequest>(ResolverEntityActionTypes.UPDATE_CHANGES_REQUEST),
map(action => action.payload),
withLatestFrom(
this.store.select(fromResolver.getEntityChanges),
this.store.select(fromWizard.getSchema)
),
map(([changes, stored, schema]) => {
const props = Object.keys(schema.properties);
const diffed = props.reduce((changeObj, prop) => {
changeObj[prop] = !changes.hasOwnProperty(prop) && stored.hasOwnProperty(prop) ? null : changes[prop];
return changeObj;
}, {});
const update = { ...stored, ...diffed };
return new UpdateChangesSuccess(update);
})
);

@Effect()
cancelChanges$ = this.actions$.pipe(
ofType<Cancel>(ResolverEntityActionTypes.CANCEL),
Expand Down
11 changes: 5 additions & 6 deletions ui/src/app/metadata/resolver/effect/wizard.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { map, filter, tap, withLatestFrom } from 'rxjs/operators';
import { Store } from '@ngrx/store';

import {
UpdateChanges,
Clear,
ResolverEntityActionTypes
ResolverEntityActionTypes,
UpdateChangesSuccess
} from '../action/entity.action';
import {
ResolverCollectionActionTypes,
Expand All @@ -17,18 +17,17 @@ import {
import * as fromResolver from '../reducer';

import { EntityDraftService } from '../../domain/service/draft.service';
import { UpdateDraftRequest, SelectDraftSuccess, DraftActionTypes } from '../action/draft.action';
import { UpdateDraftRequest } from '../action/draft.action';

@Injectable()
export class WizardEffects {

@Effect()
updateResolver$ = this.actions$.pipe(
ofType<UpdateChanges>(ResolverEntityActionTypes.UPDATE_CHANGES),
ofType<UpdateChangesSuccess>(ResolverEntityActionTypes.UPDATE_CHANGES_SUCCESS),
map(action => action.payload),
filter(provider => !provider.createdDate),
withLatestFrom(this.store.select(fromResolver.getSelectedDraft)),
map(([provider, draft]) => new UpdateDraftRequest({ ...draft, ...provider }))
map((provider) => new UpdateDraftRequest({ ...provider }))
);

@Effect()
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/metadata/resolver/reducer/entity.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { reducer } from './entity.reducer';
import * as fromEntity from './entity.reducer';
import {
UpdateChanges,
UpdateStatus,
Clear
Clear,
UpdateChangesSuccess
} from '../action/entity.action';
import { MetadataResolver } from '../../domain/model';

Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Entity Reducer', () => {

describe('Entity Update Changes', () => {
it('should add changes of the provided form', () => {
const action = new UpdateChanges(changes);
const action = new UpdateChangesSuccess(changes);
const result = reducer(initialState, action);
expect(result).toEqual(
{
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/metadata/resolver/reducer/entity.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const initialState: EntityState = {

export function reducer(state = initialState, action: ResolverEntityActionUnion): EntityState {
switch (action.type) {
case ResolverEntityActionTypes.UPDATE_CHANGES: {
case ResolverEntityActionTypes.UPDATE_CHANGES_SUCCESS: {
return {
...state,
changes: { ...state.changes, ...action.payload }
changes: { ...action.payload }
};
}
case ResolverEntityActionTypes.UPDATE_STATUS: {
Expand Down

0 comments on commit 432c169

Please sign in to comment.