Commits

Tim Donohue authored and GitHub committed 0968fe8bbc5 Merge
Merge pull request #2271 from kshepherd/item_status_page_config_fix

ItemStatus component should handle missing config gracefully
No tags
gidlmaster

src/app/item-page/edit-item-page/item-status/item-status.component.ts

Modified
1 1 import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
2 2 import { fadeIn, fadeInOut } from '../../../shared/animations/fade';
3 3 import { Item } from '../../../core/shared/item.model';
4 4 import { ActivatedRoute } from '@angular/router';
5 5 import { ItemOperation } from '../item-operation/itemOperation.model';
6 6 import { distinctUntilChanged, first, map, mergeMap, switchMap, toArray } from 'rxjs/operators';
7 7 import { BehaviorSubject, Observable, Subscription } from 'rxjs';
8 8 import { RemoteData } from '../../../core/data/remote-data';
9 9 import { getItemEditRoute, getItemPageRoute } from '../../item-page-routing-paths';
10 10 import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
11 11 import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
12 -import { hasValue } from '../../../shared/empty.util';
12 +import { hasValue, isNotEmpty } from '../../../shared/empty.util';
13 13 import {
14 - getAllSucceededRemoteDataPayload, getFirstSucceededRemoteData, getRemoteDataPayload,
14 + getAllSucceededRemoteDataPayload, getFirstCompletedRemoteData, getFirstSucceededRemoteData, getRemoteDataPayload,
15 15 } from '../../../core/shared/operators';
16 16 import { IdentifierDataService } from '../../../core/data/identifier-data.service';
17 17 import { Identifier } from '../../../shared/object-list/identifier-data/identifier.model';
18 18 import { ConfigurationProperty } from '../../../core/shared/configuration-property.model';
19 19 import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
20 20 import { IdentifierData } from '../../../shared/object-list/identifier-data/identifier-data.model';
21 21
22 22 @Component({
23 23 selector: 'ds-item-status',
24 24 templateUrl: './item-status.component.html',
98 98 if (identifierRD.statusCode !== 401 && hasValue(identifierRD.payload)) {
99 99 return identifierRD.payload.identifiers;
100 100 } else {
101 101 return null;
102 102 }
103 103 }),
104 104 );
105 105
106 106 // Observable for configuration determining whether the Register DOI feature is enabled
107 107 let registerConfigEnabled$: Observable<boolean> = this.configurationService.findByPropertyName('identifiers.item-status.register-doi').pipe(
108 - getFirstSucceededRemoteData(),
109 - getRemoteDataPayload(),
110 - map((enabled: ConfigurationProperty) => {
111 - if (enabled !== undefined && enabled.values) {
112 - return true;
108 + getFirstCompletedRemoteData(),
109 + map((rd: RemoteData<ConfigurationProperty>) => {
110 + // If the config property is exposed via rest and has a value set, return it
111 + if (rd.hasSucceeded && hasValue(rd.payload) && isNotEmpty(rd.payload.values)) {
112 + return rd.payload.values[0] === 'true';
113 113 }
114 + // Otherwise, return false
114 115 return false;
115 116 })
116 117 );
117 118
118 119 /*
119 120 Construct a base list of operations.
120 121 The key is used to build messages
121 122 i18n example: 'item.edit.tabs.status.buttons.<key>.label'
122 123 The value is supposed to be a href for the button
123 124 */

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut