Skip to content

Commit 49aff81

Browse files
author
OCurdy
committed
Add a new web component for displaying metadata quality scores with configurable validation criteria.
1 parent 537f4da commit 49aff81

2 files changed

Lines changed: 33 additions & 15 deletions

File tree

apps/webcomponents/src/app/components/gn-metadata-quality/gn-metadata-quality.component.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,36 @@ export class GnMetadataQualityComponent extends BaseComponent {
2222
@Input() smaller = false
2323
@Input() metadataQualityDisplay = true
2424
@Input() popoverDisplay = true
25-
@Input() propsToValidate?: ValidatorMapperKeys[] | string // Can be JSON string array
2625
@Input() forceComputeScore = false
2726

27+
private _propsToValidate?: ValidatorMapperKeys[] | string
28+
public parsedPropsToValidate?: ValidatorMapperKeys[]
29+
30+
@Input()
31+
set propsToValidate(value: ValidatorMapperKeys[] | string | undefined) {
32+
this._propsToValidate = value
33+
if (!value) {
34+
this.parsedPropsToValidate = undefined
35+
return
36+
}
37+
if (typeof value === 'string') {
38+
try {
39+
const parsed = JSON.parse(value)
40+
this.parsedPropsToValidate = Array.isArray(parsed) ? parsed : undefined
41+
} catch (e) {
42+
console.warn('Failed to parse propsToValidate JSON:', e)
43+
this.parsedPropsToValidate = undefined
44+
}
45+
} else if (Array.isArray(value)) {
46+
this.parsedPropsToValidate = value
47+
} else {
48+
this.parsedPropsToValidate = undefined
49+
}
50+
}
51+
get propsToValidate() {
52+
return this._propsToValidate
53+
}
54+
2855
get parsedMetadata(): CatalogRecord | null {
2956
if (!this.metadata) return null
3057
if (typeof this.metadata === 'string') {
@@ -38,19 +65,6 @@ export class GnMetadataQualityComponent extends BaseComponent {
3865
return this.metadata
3966
}
4067

41-
get parsedPropsToValidate(): ValidatorMapperKeys[] | undefined {
42-
if (!this.propsToValidate) return undefined
43-
if (typeof this.propsToValidate === 'string') {
44-
try {
45-
return JSON.parse(this.propsToValidate)
46-
} catch (e) {
47-
console.warn('Failed to parse propsToValidate JSON:', e)
48-
return undefined
49-
}
50-
}
51-
return this.propsToValidate
52-
}
53-
5468
get parsedForceComputeScore(): boolean {
5569
if (typeof this.forceComputeScore === 'boolean') return this.forceComputeScore
5670
return this.forceComputeScore === 'true' || this.forceComputeScore === true

apps/webcomponents/src/app/webcomponents.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ import { RouterModule, TitleStrategy } from '@angular/router'
5353
// eslint-disable-next-line @nx/enforce-module-boundaries
5454
import { DATAHUB_ROUTER_PROVIDERS } from '@geonetwork-ui/apps/datahub/app.providers.ts'
5555
import { NoopTitleStrategy } from './noop-title-strategy.service'
56+
import { MetadataQualityComponent } from '@geonetwork-ui/ui/elements'
57+
type WebComponentConstructor = new (...args: any[]) => BaseComponent | GnDatahubComponent | MetadataQualityComponent;
5658

5759
const CUSTOM_ELEMENTS: [
58-
new (...args) => BaseComponent | GnDatahubComponent,
60+
WebComponentConstructor,
5961
string,
6062
][] = [
6163
[GnFacetsComponent, 'gn-facets'],
@@ -68,6 +70,7 @@ const CUSTOM_ELEMENTS: [
6870
[GnFigureDatasetsComponent, 'gn-figure-datasets'],
6971
[GnDatasetViewMapComponent, 'gn-dataset-view-map'],
7072
[GnMetadataQualityComponent, 'gn-metadata-quality'],
73+
[MetadataQualityComponent, 'gn-ui-metadata-quality'],
7174
[GnDatahubComponent, 'gn-datahub'],
7275
]
7376

@@ -114,6 +117,7 @@ const CUSTOM_ELEMENTS: [
114117
},
115118
}
116119
),
120+
MetadataQualityComponent,
117121
],
118122
providers: [
119123
importProvidersFrom(

0 commit comments

Comments
 (0)