Skip to content

Commit a67c890

Browse files
committed
Merge branch 'main' into feature/CST-5729
2 parents ae4b68f + 37d9b5b commit a67c890

6 files changed

Lines changed: 81 additions & 38 deletions

File tree

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { RemoteData } from '../../../core/data/remote-data';
99
import { getItemEditRoute, getItemPageRoute } from '../../item-page-routing-paths';
1010
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
1111
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
12-
import { hasValue } from '../../../shared/empty.util';
12+
import { hasValue, isNotEmpty } from '../../../shared/empty.util';
1313
import {
14-
getAllSucceededRemoteDataPayload, getFirstSucceededRemoteData, getRemoteDataPayload,
14+
getAllSucceededRemoteDataPayload, getFirstCompletedRemoteData, getFirstSucceededRemoteData, getRemoteDataPayload,
1515
} from '../../../core/shared/operators';
1616
import { IdentifierDataService } from '../../../core/data/identifier-data.service';
1717
import { Identifier } from '../../../shared/object-list/identifier-data/identifier.model';
@@ -105,12 +105,13 @@ export class ItemStatusComponent implements OnInit {
105105

106106
// Observable for configuration determining whether the Register DOI feature is enabled
107107
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';
113113
}
114+
// Otherwise, return false
114115
return false;
115116
})
116117
);

src/app/shared/menu/menu.service.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,4 +567,41 @@ describe('MenuService', () => {
567567
});
568568
});
569569

570+
describe(`resolveSubstitutions`, () => {
571+
let linkPrefix;
572+
let link;
573+
let uuid;
574+
575+
beforeEach(() => {
576+
linkPrefix = 'statistics_collection_';
577+
link = `${linkPrefix}:id`;
578+
uuid = 'f7cc3ca4-3c2c-464d-8af8-add9f84f711c';
579+
});
580+
581+
it(`shouldn't do anything when there are no params`, () => {
582+
let result = (service as any).resolveSubstitutions(link, undefined);
583+
expect(result).toEqual(link);
584+
result = (service as any).resolveSubstitutions(link, null);
585+
expect(result).toEqual(link);
586+
result = (service as any).resolveSubstitutions(link, {});
587+
expect(result).toEqual(link);
588+
});
589+
590+
it(`should replace link params that are also route params`, () => {
591+
const result = (service as any).resolveSubstitutions(link,{ 'id': uuid });
592+
expect(result).toEqual(linkPrefix + uuid);
593+
});
594+
595+
it(`should not replace link params that aren't route params`, () => {
596+
const result = (service as any).resolveSubstitutions(link,{ 'something': 'else' });
597+
expect(result).toEqual(link);
598+
});
599+
600+
it(`should gracefully deal with routes that contain the name of the route param`, () => {
601+
const selfReferentialParam = `:id:something`;
602+
const result = (service as any).resolveSubstitutions(link,{ 'id': selfReferentialParam });
603+
expect(result).toEqual(linkPrefix + selfReferentialParam);
604+
});
605+
});
606+
570607
});

src/app/shared/menu/menu.service.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
ToggleActiveMenuSectionAction,
1818
ToggleMenuAction,
1919
} from './menu.actions';
20-
import { hasNoValue, hasValue, hasValueOperator, isNotEmpty } from '../empty.util';
20+
import { hasNoValue, hasValue, hasValueOperator, isNotEmpty, isEmpty } from '../empty.util';
2121
import { MenuState } from './menu-state.model';
2222
import { MenuSections } from './menu-sections.model';
2323
import { MenuSection } from './menu-section.model';
@@ -409,20 +409,14 @@ export class MenuService {
409409
}
410410

411411
protected resolveSubstitutions(object, params) {
412-
413412
let resolved;
414-
if (typeof object === 'string') {
413+
if (isEmpty(params)) {
415414
resolved = object;
416-
let match: RegExpMatchArray;
417-
do {
418-
match = resolved.match(/:(\w+)/);
419-
if (match) {
420-
const substitute = params[match[1]];
421-
if (hasValue(substitute)) {
422-
resolved = resolved.replace(match[0], `${substitute}`);
423-
}
424-
}
425-
} while (match);
415+
} else if (typeof object === 'string') {
416+
resolved = object;
417+
Object.entries(params).forEach(([key, value]: [string, string]) =>
418+
resolved = resolved.replaceAll(`:${key}`, value)
419+
);
426420
} else if (Array.isArray(object)) {
427421
resolved = [];
428422
object.forEach((entry, index) => {

src/app/shared/mocks/submission.mock.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,11 +1668,7 @@ export const mockFileFormData = {
16681668
],
16691669
endDate: [
16701670
{
1671-
value: {
1672-
year: 2019,
1673-
month: 1,
1674-
day: 16
1675-
},
1671+
value: new Date('2019-01-16'),
16761672
language: null,
16771673
authority: null,
16781674
display: {
@@ -1694,19 +1690,15 @@ export const mockFileFormData = {
16941690
value: 'embargo',
16951691
language: null,
16961692
authority: null,
1697-
display: 'lease',
1693+
display: 'embargo',
16981694
confidence: -1,
16991695
place: 0,
17001696
otherInformation: null
17011697
}
17021698
],
17031699
startDate: [
17041700
{
1705-
value: {
1706-
year: 2019,
1707-
month: 1,
1708-
day: 16
1709-
},
1701+
value: new Date('2019-01-16'),
17101702
language: null,
17111703
authority: null,
17121704
display: {

src/app/submission/sections/upload/file/edit/section-upload-file-edit.component.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
1+
import { ChangeDetectorRef, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
22
import { UntypedFormControl } from '@angular/forms';
33

44
import {
@@ -66,7 +66,8 @@ import { DynamicDateControlValue } from '@ng-dynamic-forms/core/lib/model/dynami
6666
styleUrls: ['./section-upload-file-edit.component.scss'],
6767
templateUrl: './section-upload-file-edit.component.html',
6868
})
69-
export class SubmissionSectionUploadFileEditComponent implements OnInit {
69+
export class SubmissionSectionUploadFileEditComponent
70+
implements OnInit, OnDestroy {
7071

7172
/**
7273
* The FormComponent reference
@@ -435,13 +436,31 @@ export class SubmissionSectionUploadFileEditComponent implements OnInit {
435436
delete currentAccessCondition.startDate;
436437
} else if (accessCondition.startDate) {
437438
const startDate = this.retrieveValueFromField(accessCondition.startDate);
438-
currentAccessCondition.startDate = dateToISOFormat(startDate);
439+
// Clamp the start date to the maximum, if any, since the
440+
// datepicker sometimes exceeds it.
441+
let startDateDate = new Date(startDate);
442+
if (accessConditionOpt.maxStartDate) {
443+
const maxStartDateDate = new Date(accessConditionOpt.maxStartDate);
444+
if (startDateDate > maxStartDateDate) {
445+
startDateDate = maxStartDateDate;
446+
}
447+
}
448+
currentAccessCondition.startDate = dateToISOFormat(startDateDate);
439449
}
440450
if (!accessConditionOpt.hasEndDate) {
441451
delete currentAccessCondition.endDate;
442452
} else if (accessCondition.endDate) {
443453
const endDate = this.retrieveValueFromField(accessCondition.endDate);
444-
currentAccessCondition.endDate = dateToISOFormat(endDate);
454+
// Clamp the end date to the maximum, if any, since the
455+
// datepicker sometimes exceeds it.
456+
let endDateDate = new Date(endDate);
457+
if (accessConditionOpt.maxEndDate) {
458+
const maxEndDateDate = new Date(accessConditionOpt.maxEndDate);
459+
if (endDateDate > maxEndDateDate) {
460+
endDateDate = maxEndDateDate;
461+
}
462+
}
463+
currentAccessCondition.endDate = dateToISOFormat(endDateDate);
445464
}
446465
accessConditionsToSave.push(currentAccessCondition);
447466
}

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10377,9 +10377,9 @@ socket.io-client@^4.4.1:
1037710377
socket.io-parser "~4.2.1"
1037810378

1037910379
socket.io-parser@~4.2.1:
10380-
version "4.2.2"
10381-
resolved "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.2.tgz"
10382-
integrity sha512-DJtziuKypFkMMHCm2uIshOYC7QaylbtzQwiMYDuCKy3OPkjLzu4B2vAhTlqipRHHzrI0NJeBAizTK7X+6m1jVw==
10380+
version "4.2.3"
10381+
resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-4.2.3.tgz#926bcc6658e2ae0883dc9dee69acbdc76e4e3667"
10382+
integrity sha512-JMafRntWVO2DCJimKsRTh/wnqVvO4hrfwOqtO7f+uzwsQMuxO6VwImtYxaQ+ieoyshWOTJyV0fA21lccEXRPpQ==
1038310383
dependencies:
1038410384
"@socket.io/component-emitter" "~3.1.0"
1038510385
debug "~4.3.1"

0 commit comments

Comments
 (0)