Skip to content

Commit

Permalink
SHIBUI-1382 Fixed issue with date display
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Aug 21, 2019
1 parent 098b129 commit 58b0c25
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h2 class="mb-4">
<translate-i18n key="label.restore-version" [params]="{ 'date': date }">
<h2 class="mb-4" *ngIf="date$ | async">
<translate-i18n key="label.restore-version" [params]="{ 'date': date$ | async }">
Restore Version ( date )
</translate-i18n>
</h2>
Expand All @@ -8,11 +8,11 @@ <h2 class="mb-4">
<div class="card-body">
<h3 class="card-title"
translate="message.create-new-version-from-version"
[translateParams]="{ 'date': date }">
[translateParams]="{ 'date': date$ | async }">
Create New Version from Version ( date ) Settings
</h3>
<p translate="message.restoring-this-version-will-copy"
[translateParams]="{ 'date': date }">
[translateParams]="{ 'date': date$ | async }">
Restoring this version will copy the Version ( date ) 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" translate="action.cancel">Cancel</a>&nbsp;
Expand Down
31 changes: 21 additions & 10 deletions ui/src/app/metadata/configuration/container/restore.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component, ChangeDetectionStrategy, OnDestroy } from '@angular/core';
import { ActivatedRoute, } from '@angular/router';
import { Store } from '@ngrx/store';
import { Subject } from 'rxjs';
import { Subject, Observable } from 'rxjs';

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

Expand All @@ -20,25 +20,36 @@ export class RestoreComponent implements OnDestroy {
readonly subj = new Subject<any>();
restore$ = this.subj.asObservable();

date$ = this.store.select(fromConfiguration.getConfigurationVersionDate);
date: string;
date$: Observable<string>;
kind$: Observable<string> = this.store.select(fromConfiguration.getConfigurationModelKind);
id$: Observable<string> = this.store.select(fromConfiguration.getConfigurationModelId);

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

this.date$.pipe(takeUntil(this.subj)).subscribe(
(date) => this.date = this.datePipe.transform(date, CONFIG_DATE_FORMAT)
);
this.date$ = this.store
.select(fromConfiguration.getConfigurationVersionDate)
.pipe(
map((date) => this.datePipe.transform(date, CONFIG_DATE_FORMAT))
);

this.route.queryParams.pipe(
takeUntil(this.subj),
map(params => params.version),
withLatestFrom(this.id$, this.kind$),
map(([version, id, type]) => new SelectVersionRestoreRequest({ version, id, type }))
).subscribe(this.store);
}

restore() {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/configuration/effect/restore.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class RestoreVersionEffects {
ofType<SelectVersionRestoreRequest>(RestoreActionTypes.SELECT_VERSION_REQUEST),
map(action => action.payload),
switchMap(({ type, id, version }) => {
return this.historyService.getVersion(id, version, type).pipe(
return this.historyService.getVersion(id, type, version).pipe(
map(v => new SelectVersionRestoreSuccess(v)),
catchError(err => of(new SelectVersionRestoreError(err)))
);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/configuration/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +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);
export const getConfigurationVersionDate = createSelector(getRestoreModel, version => version && version.modifiedDate);

0 comments on commit 58b0c25

Please sign in to comment.