From 8a7f2df2cceed0c56bb9d20a8ed9200c5014be13 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Fri, 17 Nov 2023 11:01:36 +0100 Subject: [PATCH 1/4] fix(metadata-info): handle updateFrequency correctly if not defined --- .../metadata-info.component.spec.ts | 16 ++++++++++++++++ .../lib/metadata-info/metadata-info.component.ts | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts index eb1bc28a3a..0d4b55577f 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts @@ -88,6 +88,22 @@ describe('MetadataInfoComponent', () => { }) }) describe('updateFrequency', () => { + describe('updateFrequency is null', () => { + beforeEach(() => { + fixture = TestBed.createComponent(MetadataInfoComponent) + component = fixture.componentInstance + component.metadata = { + ...DATASET_RECORDS[0], + updateFrequency: null, + } + fixture.detectChanges() + }) + it('should not display the updateFrequency section', () => { + const displayedElement = + fixture.nativeElement.querySelector('.updateFrequency') + expect(displayedElement).toBeFalsy() + }) + }) describe('updateFrequency as UpdateFrequencyCode', () => { beforeEach(() => { fixture = TestBed.createComponent(MetadataInfoComponent) diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts index 18b1990b20..f74ea4df78 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts @@ -42,8 +42,10 @@ export class MetadataInfoComponent { if (this.metadata.updateFrequency instanceof Object) { this.updatedTimes = this.metadata.updateFrequency.updatedTimes return `domain.record.updateFrequency.${this.metadata.updateFrequency.per}` - } else { + } else if (typeof this.metadata.updateFrequency === 'string') { return `domain.record.updateFrequency.${this.metadata.updateFrequency}` + } else { + return undefined } } From d9e43febbd682c3ac577599723c76cd4af6ff448 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Fri, 17 Nov 2023 11:06:15 +0100 Subject: [PATCH 2/4] fix(utils): handle undefined in html util functions this prevents displaying abstract 'undefined' as string in record-preview (although abstract should usually not be undefined) --- libs/util/shared/src/lib/utils/remove-whitespace.spec.ts | 4 ++++ libs/util/shared/src/lib/utils/remove-whitespace.ts | 2 +- libs/util/shared/src/lib/utils/strip-html.spec.ts | 6 ++++++ libs/util/shared/src/lib/utils/strip-html.ts | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/util/shared/src/lib/utils/remove-whitespace.spec.ts b/libs/util/shared/src/lib/utils/remove-whitespace.spec.ts index 20b5459045..4f21470524 100644 --- a/libs/util/shared/src/lib/utils/remove-whitespace.spec.ts +++ b/libs/util/shared/src/lib/utils/remove-whitespace.spec.ts @@ -1,6 +1,10 @@ import { removeWhitespace } from './remove-whitespace' describe('#removeWhitespace', () => { + it('returns undefined input is not defined', () => { + const html = null + expect(removeWhitespace(html)).toBe(undefined) + }) it('removes superfluent whitespace for a single word', () => { const html = ' hello ' expect(removeWhitespace(html)).toBe('hello') diff --git a/libs/util/shared/src/lib/utils/remove-whitespace.ts b/libs/util/shared/src/lib/utils/remove-whitespace.ts index c9dffa3aa5..696d88f457 100644 --- a/libs/util/shared/src/lib/utils/remove-whitespace.ts +++ b/libs/util/shared/src/lib/utils/remove-whitespace.ts @@ -1,3 +1,3 @@ export const removeWhitespace = function (str: string): string { - return str.replace(/\s+/g, ' ').trim() + return str ? str.replace(/\s+/g, ' ').trim() : undefined } diff --git a/libs/util/shared/src/lib/utils/strip-html.spec.ts b/libs/util/shared/src/lib/utils/strip-html.spec.ts index 1e0a44cf15..c72b4ee071 100644 --- a/libs/util/shared/src/lib/utils/strip-html.spec.ts +++ b/libs/util/shared/src/lib/utils/strip-html.spec.ts @@ -7,6 +7,12 @@ describe('strip HTML', () => { expect(stripHtml(html)).toBe('hello') }) }) + describe('when HTML not defined', () => { + it('returns undefined', () => { + const html = null + expect(stripHtml(html)).toBe(undefined) + }) + }) describe('when no HTML tags', () => { it('return same string', () => { const html = 'hello' diff --git a/libs/util/shared/src/lib/utils/strip-html.ts b/libs/util/shared/src/lib/utils/strip-html.ts index 5e5b8bf527..14170efd71 100644 --- a/libs/util/shared/src/lib/utils/strip-html.ts +++ b/libs/util/shared/src/lib/utils/strip-html.ts @@ -1,4 +1,5 @@ export const stripHtml = function (html: string): string { + if (!html) return undefined const doc = new DOMParser().parseFromString(html, 'text/html') return doc.body.textContent || '' } From 01c50c456d8037e9f1cb4db8f953be2c2048a128 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Tue, 21 Nov 2023 11:08:18 +0100 Subject: [PATCH 3/4] refactor(utils): simplify removeWhitespace --- libs/util/shared/src/lib/utils/remove-whitespace.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/util/shared/src/lib/utils/remove-whitespace.ts b/libs/util/shared/src/lib/utils/remove-whitespace.ts index 696d88f457..053514cd52 100644 --- a/libs/util/shared/src/lib/utils/remove-whitespace.ts +++ b/libs/util/shared/src/lib/utils/remove-whitespace.ts @@ -1,3 +1,3 @@ export const removeWhitespace = function (str: string): string { - return str ? str.replace(/\s+/g, ' ').trim() : undefined + return str?.replace(/\s+/g, ' ').trim() } From 0978e4bfb6555db9cfa6a56628a08b3ed8d4b755 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 22 Nov 2023 10:52:49 +0100 Subject: [PATCH 4/4] fix(md-converter): do not initialize updateFrequency with null --- .../src/lib/gn4/gn4.metadata.mapper.spec.ts | 2 -- .../api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts | 1 - .../src/lib/metadata-info/metadata-info.component.spec.ts | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.spec.ts b/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.spec.ts index f462b78ff2..4574665d33 100644 --- a/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.spec.ts +++ b/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.spec.ts @@ -96,7 +96,6 @@ describe('Gn4MetadataMapper', () => { website: new URL('http://my.org'), }, status: null, - updateFrequency: null, lineage: null, recordUpdated: null, distributions: [], @@ -136,7 +135,6 @@ describe('Gn4MetadataMapper', () => { website: new URL('http://my.org'), }, status: null, - updateFrequency: null, lineage: null, recordUpdated: null, distributions: [], diff --git a/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts b/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts index 9f782429fe..2870353baf 100644 --- a/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts +++ b/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts @@ -22,7 +22,6 @@ export class Gn4MetadataMapper extends MetadataBaseMapper { const emptyRecord: Partial = { kind: 'dataset', status: null, - updateFrequency: null, lineage: null, recordUpdated: null, ownerOrganization: null, diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts index 0d4b55577f..6c1125c866 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts @@ -88,13 +88,13 @@ describe('MetadataInfoComponent', () => { }) }) describe('updateFrequency', () => { - describe('updateFrequency is null', () => { + describe('updateFrequency is not defined', () => { beforeEach(() => { fixture = TestBed.createComponent(MetadataInfoComponent) component = fixture.componentInstance component.metadata = { ...DATASET_RECORDS[0], - updateFrequency: null, + updateFrequency: undefined, } fixture.detectChanges() })