Skip to content

Commit

Permalink
SHIBUI-1382 implementation for restore page
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Aug 9, 2019
1 parent b3b2b5f commit 3a2cee5
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 21 deletions.
31 changes: 30 additions & 1 deletion ui/src/app/metadata/configuration/action/restore.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,39 @@ export enum RestoreActionTypes {
SELECT_VERSION_SUCCESS = '[Restore Version] Select Version Success',
SELECT_VERSION_ERROR = '[Restore Version] Select Version Error',
SELECT_VERSION_REQUEST = '[Restore Version] Select Version Request',

RESTORE_VERSION_REQUEST = '[Restore Version] Restore Version Request',
RESTORE_VERSION_SUCCESS = '[Restore Version] Restore Version Request',
RESTORE_VERSION_ERROR = '[Restore Version] Restore Version Request',

CLEAR_VERSION = '[Restore Version] Clear Versions'
}

export interface VersionRequest {
type: string;
id: string;
version: string;
}

export class RestoreVersionRequest implements Action {
readonly type = RestoreActionTypes.RESTORE_VERSION_REQUEST;
constructor(public payload: VersionRequest) { }
}

export class RestoreVersionSuccess implements Action {
readonly type = RestoreActionTypes.RESTORE_VERSION_SUCCESS;
constructor(public payload: Metadata) { }
}

export class RestoreVersionError implements Action {
readonly type = RestoreActionTypes.RESTORE_VERSION_ERROR;
constructor(public payload: any) { }
}

export class SelectVersionRestoreRequest implements Action {
readonly type = RestoreActionTypes.SELECT_VERSION_REQUEST;

constructor(public payload: { type: string, id: string, version: string }) { }
constructor(public payload: VersionRequest) { }
}

export class SelectVersionRestoreSuccess implements Action {
Expand All @@ -33,4 +59,7 @@ export type RestoreActionsUnion =
| SelectVersionRestoreRequest
| SelectVersionRestoreError
| SelectVersionRestoreSuccess
| RestoreVersionRequest
| RestoreVersionSuccess
| RestoreVersionError
| ClearVersionRestore;
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ConfigurationComponent implements OnDestroy {
type,
version
}))
).subscribe(store);
).subscribe(this.store);

this.routerState.params.pipe(
takeUntil(this.ngUnsubscribe),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class MetadataHistoryComponent {
this.router.navigate(
[ '../', 'restore' ],
{
queryParams: { version: version.id },
relativeTo: this.route
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<h2 class="mb-4">
Restore Version
Restore Version ({{ date$ | async | date:DATE_FORMAT }})
</h2>
<div class="d-flex justify-content-center align-items-center">
<div class="card m-4 w-50">
<div class="card-body">
<h3 class="card-title">Create new version from {{ date | date:DATE_FORMAT }} settings</h3>
<p>Restoring this version will copy the configuration from the selected version and create a new version from these settings. You can then edit the configuration before saving the new version.</p>
<a href="#" class="btn btn-light">Cancel</a>&nbsp;<a href="#" class="btn btn-primary">Restore</a>
<h3 class="card-title">Create New Version from Version ({{ date$ | async | date:DATE_FORMAT }}) Settings</h3>
<p>Restoring this version will copy the Version ({{ date$ | async | date:DATE_FORMAT }}) configuration and create a new Version from the
selected version settings. You can then edit the configuration before saving the new version.</p>
<a [routerLink]="['../', 'history']" class="btn btn-light">Cancel</a>&nbsp;
<button class="btn btn-primary" (click)="restore()">Restore</button>
</div>
</div>
</div>
33 changes: 24 additions & 9 deletions ui/src/app/metadata/configuration/container/restore.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Subject } from 'rxjs';

import * as fromConfiguration from '../reducer';
import { CONFIG_DATE_FORMAT } from '../configuration.values';
import { RestoreVersionRequest } from '../action/restore.action';
import { withLatestFrom, map, takeUntil } from 'rxjs/operators';

@Component({
selector: 'restore-component',
Expand All @@ -13,19 +15,32 @@ import { CONFIG_DATE_FORMAT } from '../configuration.values';
styleUrls: []
})
export class RestoreComponent implements OnDestroy {
private ngUnsubscribe: Subject<void> = new Subject<void>();

DATE_FORMAT = CONFIG_DATE_FORMAT;
private subj = new Subject<any>();
restore$ = this.subj.asObservable();

date$ = this.store.select(fromConfiguration.getConfigurationVersionDate);

date = new Date();
DATE_FORMAT = CONFIG_DATE_FORMAT;

constructor(
private store: Store<fromConfiguration.ConfigurationState>,
private routerState: ActivatedRoute
) {}
private store: Store<fromConfiguration.ConfigurationState>
) {
this.restore$.pipe(
withLatestFrom(
this.store.select(fromConfiguration.getSelectedVersionId),
this.store.select(fromConfiguration.getConfigurationModelType),
this.store.select(fromConfiguration.getConfigurationModelId)
),
map(([restore, version, type, id]) => new RestoreVersionRequest({ id, type, version }))
).subscribe(this.store);
}

restore() {
this.subj.next();
}

ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
ngOnDestroy(): void {
this.subj.complete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export class MetadataConfigurationEffects {
map(action => action.payload),
switchMap(payload =>
this.historyService.getVersion(payload.id, payload.type, payload.version).pipe(
map((response: Metadata) =>
(payload.type === 'resolver') ?
map((response: Metadata) => {
return (payload.type === 'resolver') ?
new SelectResolverSuccess(response as MetadataResolver) :
new SelectProviderSuccess(response as MetadataProvider)
)
new SelectProviderSuccess(response as MetadataProvider);
})
)
)
);
Expand Down
17 changes: 15 additions & 2 deletions ui/src/app/metadata/configuration/effect/restore.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
RestoreActionTypes,
SelectVersionRestoreRequest,
SelectVersionRestoreError,
SelectVersionRestoreSuccess
SelectVersionRestoreSuccess,
RestoreVersionRequest
} from '../action/restore.action';
import { MetadataHistoryService } from '../service/history.service';
import { of } from 'rxjs';
Expand All @@ -16,7 +17,7 @@ import { of } from 'rxjs';
export class RestoreVersionEffects {

@Effect()
restoreVersionFromId$ = this.actions$.pipe(
selectVersionFromId$ = this.actions$.pipe(
ofType<SelectVersionRestoreRequest>(RestoreActionTypes.SELECT_VERSION_REQUEST),
map(action => action.payload),
switchMap(({ type, id, version }) => {
Expand All @@ -27,6 +28,18 @@ export class RestoreVersionEffects {
})
);

@Effect()
restoreVersion$ = this.actions$.pipe(
ofType<RestoreVersionRequest>(RestoreActionTypes.RESTORE_VERSION_REQUEST),
map(action => action.payload),
switchMap(({ id, type, version }) => {
return this.historyService.getVersion(id, version, type).pipe(
map(v => new SelectVersionRestoreSuccess(v)),
catchError(err => of(new SelectVersionRestoreError(err)))
);
})
);

constructor(
private historyService: MetadataHistoryService,
private actions$: Actions
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/metadata/configuration/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,4 @@ export const getConfigurationModelType = createSelector(getConfigurationModel, g

export const getConfigurationHasXml = createSelector(getConfigurationXml, xml => !!xml);
export const getConfigurationFilters = createSelector(getConfigurationModel, model => model.metadataFilters);
export const getConfigurationVersionDate = createSelector(getConfigurationModel, version => version.modifiedDate);

0 comments on commit 3a2cee5

Please sign in to comment.