Skip to content

Commit

Permalink
SHIBUI-1549 Fixed issue with saving/editing sources
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Nov 5, 2019
1 parent 97f8386 commit 3b04015
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
};

parser(changes: Partial<MetadataResolver>, schema?: any): any {
if (!changes.organization) {
if (!schema || !schema.properties) {
return changes;
}
if (schema.properties.hasOwnProperty('organization') && !changes.organization) {
changes.organization = {};
}
return changes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,23 @@ export class ResolverEditStepComponent implements OnDestroy {
this.valueChangeEmitted$.pipe(
takeUntil(this.ngUnsubscribe),
map(changes => changes.value),
withLatestFrom(this.definition$, this.store.select(fromResolver.getSelectedResolver), this.changes$),
withLatestFrom(
this.definition$,
this.store.select(fromResolver.getSelectedResolver),
this.changes$,
this.schema$
),
filter(([valueChange, definition, resolver]) => definition && resolver),
map(([valueChange, definition, resolver, changes]) => definition.parser({ ...resolver, ...changes, ...valueChange }))
map(([
valueChange,
definition,
resolver,
changes,
schema
]) => {
const parsed = definition.parser({ ...valueChange }, schema);
return { ...resolver, ...changes, ...parsed };
})
)
.subscribe(changes => {
this.store.dispatch(new UpdateChangesRequest(changes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ export class ResolverWizardStepComponent implements OnDestroy {
);

this.valueChangeEmitted$.pipe(
withLatestFrom(this.definition$),
withLatestFrom(
this.definition$,
this.schema$,
this.store.select(fromResolver.getSelectedDraft)
),
filter(([ changes, definition ]) => (!!definition && !!changes)),
map(([ changes, definition ]) => definition.parser(changes.value))
map(([ changes, definition, schema, original ]) => {
const parsed = definition.parser(changes.value, schema);
return { ...original, ...parsed };
})
)
.subscribe(changes => {
this.store.dispatch(new UpdateChangesRequest(changes));
Expand Down
12 changes: 3 additions & 9 deletions ui/src/app/metadata/resolver/effect/entity.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@ export class EntityEffects {
ofType<UpdateChangesRequest>(ResolverEntityActionTypes.UPDATE_CHANGES_REQUEST),
map(action => action.payload),
withLatestFrom(
this.store.select(fromResolver.getEntityChanges),
this.store.select(fromWizard.getSchema)
this.store.select(fromResolver.getEntityChanges)
),
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 };
map(([changes, storedChanges]) => {
const update = { ...storedChanges, ...changes };
return new UpdateChangesSuccess(update);
})
);
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/metadata/resolver/reducer/collection.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export function reducer(state = initialState, action: ResolverCollectionActionsU
}

case ResolverCollectionActionTypes.UPDATE_RESOLVER_SUCCESS: {
return adapter.updateOne(action.payload, state);
const removed = adapter.removeOne(action.payload.id as string, state);
const addBack = adapter.upsertOne(action.payload.changes as MetadataResolver, removed);
return addBack;
}

case ResolverCollectionActionTypes.SELECT_SUCCESS: {
Expand Down

0 comments on commit 3b04015

Please sign in to comment.