Skip to content

Commit

Permalink
Updated to enable deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Apr 9, 2021
1 parent 8f6d323 commit b1d23f3
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 43 deletions.
4 changes: 2 additions & 2 deletions ui/src/app/admin/action/metadata-collection.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export class UpdateMetadataConflict implements Action {
export class RemoveMetadataRequest implements Action {
readonly type = MetadataCollectionActionTypes.REMOVE_METADATA;

constructor(public payload: MetadataResolver) { }
constructor(public payload: string) { }
}

export class RemoveMetadataSuccess implements Action {
readonly type = MetadataCollectionActionTypes.REMOVE_METADATA_SUCCESS;

constructor(public payload: MetadataResolver) { }
constructor(public payload: string) { }
}

export class RemoveMetadataFail implements Action {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/admin/component/enable-metadata.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class EnableMetadataComponent {
.result
.then(
success => {
this.store.dispatch(new RemoveMetadataRequest(entity));
this.store.dispatch(new RemoveMetadataRequest(entity.id));
},
err => {
console.log('Cancelled');
Expand Down
3 changes: 3 additions & 0 deletions ui/src/app/admin/effect/metadata-collection.effect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { Metadata } from '../../metadata/domain/domain.type';
import { MetadataResolver } from '../../metadata/domain/model';
import * as fromI18n from '../../i18n/reducer';
import { I18nService } from '../../i18n/service/i18n.service';
import { Router } from '@angular/router';
import { RouterStub } from '../../../testing/router.stub';

describe('Metadata Collection Effects', () => {
let effects: MetadataCollectionEffects;
Expand Down Expand Up @@ -55,6 +57,7 @@ describe('Metadata Collection Effects', () => {
},
MetadataCollectionEffects,
provideMockActions(() => actions),
{ provide: Router, useClass: RouterStub }
],
});

Expand Down
13 changes: 12 additions & 1 deletion ui/src/app/admin/effect/metadata-collection.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Notification, NotificationType } from '../../notification/model/notific
import { I18nService } from '../../i18n/service/i18n.service';
import * as fromRoot from '../../app.reducer';
import * as fromI18n from '../../i18n/reducer';
import { Router } from '@angular/router';


/* istanbul ignore next */
Expand Down Expand Up @@ -123,10 +124,20 @@ export class MetadataCollectionEffects {
)
);

@Effect({dispatch: false})
redirectOnRemove$ = this.actions$.pipe(
ofType<RemoveMetadataSuccess>(MetadataCollectionActionTypes.REMOVE_METADATA_SUCCESS),
map(action => action.payload),
switchMap(entity =>
this.router.navigate(['/'])
)
);

constructor(
private descriptorService: ResolverService,
private actions$: Actions,
private store: Store<fromRoot.State>,
private i18nService: I18nService
private i18nService: I18nService,
private router: Router
) { }
} /* istanbul ignore next */
2 changes: 1 addition & 1 deletion ui/src/app/admin/reducer/metadata-collection.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function reducer(state = initialState, action: MetadataCollectionActionsU
}

case MetadataCollectionActionTypes.REMOVE_METADATA_SUCCESS: {
return adapter.removeOne(action.payload.id, {
return adapter.removeOne(action.payload, {
...state
});
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/core/service/can-deactivate.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate>
currentState: RouterStateSnapshot,
nextState: RouterStateSnapshot
) {
return component.canDeactivate ? component.canDeactivate(currentRoute, currentState, nextState) : true;
return component && component.canDeactivate ? component.canDeactivate(currentRoute, currentState, nextState) : true;
}
} /* istanbul ignore next */
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<div class="card enabled-status" *ngIf="version">
<div class="card-body">
<h5 class="card-title version-title">
<translate-i18n key="label.saved">Saved</translate-i18n>:&nbsp;
<span class="save-date">{{ (version.modifiedDate) | date:DATE_FORMAT }}</span>
<br />
<translate-i18n key="label.by">By</translate-i18n>:&nbsp;
<span class="author">{{ version.createdBy }}</span>
</h5>
<div class="d-flex justify-content-between">
<h5 class="card-title version-title">
<translate-i18n key="label.saved">Saved</translate-i18n>:&nbsp;
<span class="save-date">{{ (version.modifiedDate) | date:DATE_FORMAT }}</span>
<br />
<translate-i18n key="label.by">By</translate-i18n>:&nbsp;
<span class="author">{{ version.createdBy }}</span>
</h5>
<ng-content></ng-content>
</div>

<p class="card-text">
<span class="badge badge-primary" *ngIf="isEnabled"><translate-i18n key="value.enabled">Enabled</translate-i18n></span>
<span class="badge badge-danger" *ngIf="!isEnabled"><translate-i18n key="value.disabled">Disabled</translate-i18n></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ <h2 class="mb-4" [ngSwitch]="type$ | async">
<metadata-header
[isEnabled]="isEnabled$ | async"
[version]="model$ | async"
[isCurrent]="true"
></metadata-header>
[isCurrent]="true">
<button class="btn btn-outline btn-sm btn-danger align-self-start" (click)="deleteResolver(id)">
<translate-i18n key="action.delete">Delete</translate-i18n>
<i class="fa fa-trash ml-2"></i>
</button>
</metadata-header>
<div class="px-3 my-3 d-flex justify-content-between" id="navigation">
<div>
<a class="btn btn-link" routerLink="../history">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
getConfigurationModelType
} from '../reducer';
import { MetadataConfiguration } from '../model/metadata-configuration';
import { MetadataFilter } from '../../domain/model';
import { MetadataEntity, MetadataFilter, MetadataResolver } from '../../domain/model';
import { getAdditionalFilters } from '../../filter/reducer';
import {
ClearFilters,
Expand All @@ -29,6 +29,10 @@ import {
import { Metadata } from '../../domain/domain.type';
import { DeleteFilterComponent } from '../../provider/component/delete-filter.component';
import { ClearHistory } from '../action/history.action';
import { DeleteDialogComponent } from '../../manager/component/delete-dialog.component';
import { RemoveDraftRequest } from '../../resolver/action/draft.action';
import { RemoveResolverRequest } from '../../resolver/action/collection.action';
import { RemoveMetadataRequest } from '../../../admin/action/metadata-collection.action';

@Component({
selector: 'metadata-options-page',
Expand Down Expand Up @@ -114,6 +118,20 @@ export class MetadataOptionsComponent implements OnDestroy {
);
}

deleteResolver(id: string): void {
this.modalService
.open(DeleteDialogComponent)
.result
.then(
success => {
this.store.dispatch(new RemoveMetadataRequest(id));
},
err => {
console.log('Cancelled');
}
);
}

ngOnDestroy(): void {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
Expand Down
5 changes: 2 additions & 3 deletions ui/src/app/metadata/domain/service/draft.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe(`EntityDraftService`, () => {
it(`should return a 404 error if not found`, (done: DoneFn) => {
let id = null;
service.find(id).subscribe(null, err => {
expect(err).toEqual(404);
expect(err).toEqual(`404 - null not found in cache.`);
done();
});
});
Expand Down Expand Up @@ -96,10 +96,9 @@ describe(`EntityDraftService`, () => {

it('should return a 404 if not found', () => {
const resolver = { id: 'bar' } as MetadataResolver;
const updates = { id: 'foo', serviceProviderName: 'bar' };
spyOn(service.storage, 'findByAttr').and.returnValue(null);
service.update(resolver).subscribe(null, (err) => {
expect(err).toBe(404);
expect(err).toBe(`404 - ${resolver.id} not found in cache.`);
expect(service.storage.findByAttr).toHaveBeenCalled();
});
});
Expand Down
8 changes: 5 additions & 3 deletions ui/src/app/metadata/domain/service/draft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class EntityDraftService {

find(id: string, attr: string = 'id'): Observable<MetadataResolver> {
if (!id) {
return throwError(404);
return throwError(`404 - ${id} not found in cache.`);
}
return this.query().pipe(
switchMap(
Expand All @@ -39,7 +39,9 @@ export class EntityDraftService {
}

remove(provider: MetadataResolver): Observable<MetadataResolver> {
this.storage.removeByAttr(provider.id, 'id');
if (!!provider) {
this.storage.removeByAttr(provider.id, 'id');
}
return of(provider);
}

Expand All @@ -51,7 +53,7 @@ export class EntityDraftService {
this.storage.add(stored);
return of(stored);
} else {
return throwError(404);
return throwError(`404 - ${provider.id} not found in cache.`);
}
}
} /* istanbul ignore next */
6 changes: 2 additions & 4 deletions ui/src/app/metadata/domain/service/resolver.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,11 @@ describe(`Resolver Service`, () => {
});

describe('remove', () => {
let id = 'foo',
serviceProviderName = 'Test Provider',
createdBy = 'admin';
let id = 'foo';

it(`should send an expected PUT request`, waitForAsync(inject([ResolverService, HttpTestingController],
(service: ResolverService, backend: HttpTestingController) => {
service.remove({ id, serviceProviderName, createdBy }).subscribe();
service.remove(id).subscribe();

backend.expectOne((req: HttpRequest<any>) => {
return req.url === `api/EntityDescriptor/${id}`
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/metadata/domain/service/resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class ResolverService {
return this.http.post<MetadataResolver>(`${this.base}${this.endpoint}`, p);
}

remove(provider: MetadataResolver): Observable<MetadataResolver> {
return this.http.delete<MetadataResolver>(`${this.base}${this.endpoint}/${provider.id}`);
remove(id: string): Observable<MetadataResolver> {
return this.http.delete<MetadataResolver>(`${this.base}${this.endpoint}/${id}`);
}

upload(name: string, xml: string): Observable<MetadataResolver> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<th class="w-40"><translate-i18n key="label.entity-id">Entity ID</translate-i18n></th>
<th class="w-15"><translate-i18n key="label.author">Author</translate-i18n></th>
<th class="w-15"><translate-i18n key="label.creation-date">Created Date</translate-i18n></th>
<th class="text-right w-15"><translate-i18n key="label.enabled">Enabled</translate-i18n></th>
<th class="text-center w-15"><translate-i18n key="label.enabled">Enabled</translate-i18n></th>
<th class=""></th>
</thead>
<tbody infiniteScroll [infiniteScrollDistance]="2" [infiniteScrollThrottle]="50" (scrolled)="scroll.emit()">
<tr *ngFor="let resolver of entities; index as i">
Expand All @@ -21,13 +22,8 @@
<td [attr.aria-label]="resolver.getCreationDate() ? (resolver.getCreationDate() | customDate) : 'unknown'">
{{ resolver.getCreationDate() ? (resolver.getCreationDate() | customDate) : '&mdash;' }}
</td>
<td class="text-right">
<td class="text-center">
<span *ngIf="resolver.isDraft()">
<button class="btn btn-outline btn-sm btn-danger" (click)="delete.emit(resolver)">
<span class="sr-only">Delete</span>
<i class="fa fa-trash"></i>
</button>
&nbsp;
<span class="badge badge-warning" tabindex="0" aria-label="Warning Badge: Incomplete Form">
<translate-i18n key="message.incomplete-form">
Incomplete Form
Expand Down Expand Up @@ -55,6 +51,15 @@
</span>
</ng-container>
</td>
<td class="text-right">
<button class="btn btn-outline btn-sm btn-danger" (click)="delete.emit({
entity: resolver,
draft: resolver.isDraft()
})">
<span class="sr-only">Delete</span>
<i class="fa fa-trash"></i>
</button>
</td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Dashboard Resolvers List Page', () => {
result: Promise.resolve(true)
} as NgbModalRef;
});
instance.deleteResolver(resolver);
instance.deleteResolver({ entity: resolver, draft: false });
expect(modal.open).toHaveBeenCalled();
});
it('should log an error to the console on failure', () => {
Expand All @@ -137,7 +137,7 @@ describe('Dashboard Resolvers List Page', () => {
result: Promise.reject(false)
} as NgbModalRef;
});
instance.deleteResolver(resolver);
instance.deleteResolver({ entity: resolver, draft: false });
expect(modal.open).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DeleteDialogComponent } from '../component/delete-dialog.component';
import { RemoveDraftRequest } from '../../resolver/action/draft.action';
import { getAllResolvers } from '../../resolver/reducer';
import { FileBackedHttpMetadataResolver } from '../../domain/entity';
import { RemoveResolverRequest } from '../../resolver/action/collection.action';

@Component({
selector: 'dashboard-resolvers-list',
Expand Down Expand Up @@ -86,13 +87,17 @@ export class DashboardResolversListComponent implements OnInit {
this.router.navigate(['metadata', 'resolver', entity.getId(), 'versions']);
}

deleteResolver(entity: MetadataResolver): void {
deleteResolver({ entity, draft }: { entity: MetadataResolver, draft: boolean }): void {
this.modalService
.open(DeleteDialogComponent)
.result
.then(
success => {
this.store.dispatch(new RemoveDraftRequest(entity));
if (draft) {
this.store.dispatch(new RemoveDraftRequest(entity));
} else {
this.store.dispatch(new RemoveResolverRequest(entity.id));
}
},
err => {
console.log('Cancelled');
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/metadata/resolver/action/collection.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ export class AddResolverFail implements Action {
export class RemoveResolverRequest implements Action {
readonly type = ResolverCollectionActionTypes.REMOVE_RESOLVER;

constructor(public payload: MetadataResolver) { }
constructor(public payload: string) { }
}

export class RemoveResolverSuccess implements Action {
readonly type = ResolverCollectionActionTypes.REMOVE_RESOLVER_SUCCESS;

constructor(public payload: MetadataResolver) { }
constructor(public payload: string) { }
}

export class RemoveResolverFail implements Action {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/resolver/effect/collection.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class ResolverCollectionEffects {
this.descriptorService
.remove(entity)
.pipe(
map(p => new RemoveResolverSuccess(p)),
map(p => new RemoveResolverSuccess(entity)),
catchError(err => of(new RemoveResolverFail(err)))
)
)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/resolver/reducer/collection.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function reducer(state = initialState, action: ResolverCollectionActionsU
}

case ResolverCollectionActionTypes.REMOVE_RESOLVER_SUCCESS: {
return adapter.removeOne(action.payload.id, {
return adapter.removeOne(action.payload, {
...state
});
}
Expand Down

0 comments on commit b1d23f3

Please sign in to comment.