Skip to content

Commit d5315bf

Browse files
committed
feat(es2): Get rid of artifact viewer
1 parent 2a23aec commit d5315bf

2 files changed

Lines changed: 49 additions & 32 deletions

File tree

‎src/app/features/project/overview/components/overview-collections/overview-collections.component.html‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,19 @@ <h3 class="mb-2">{{ 'project.overview.metadata.collection' | translate }}</h3>
3333
@let cedarRecord = cedarRecordByTemplateId().get(templateId) ?? null;
3434
@let cedarTemplate = cedarTemplateById().get(templateId) ?? null;
3535

36-
@if (isCedarMode() && cedarRecord && cedarTemplate?.attributes?.template) {
37-
<div class="mt-2">
38-
<cedar-artifact-viewer
39-
[config]="cedarViewerConfig"
40-
[templateObject]="cedarTemplate!.attributes.template"
41-
[instanceObject]="cedarRecord.attributes.metadata"
42-
></cedar-artifact-viewer>
43-
</div>
44-
} @else {
45-
@let attributes = getSubmissionAttributes(submission);
36+
@let attributes =
37+
isCedarMode() && cedarRecord && cedarTemplate?.attributes?.template
38+
? getCedarAttributes(cedarRecord, cedarTemplate!)
39+
: getSubmissionAttributes(submission);
4640

47-
@if (attributes.length) {
48-
<div class="flex flex-column gap-2 mt-2">
49-
@for (attribute of attributes; track attribute.key) {
50-
<p class="font-normal">
51-
<span class="font-bold">{{ attribute.label }}:</span> {{ attribute.value }}
52-
</p>
53-
}
54-
</div>
55-
}
41+
@if (attributes.length) {
42+
<div class="flex flex-column gap-2 mt-2">
43+
@for (attribute of attributes; track attribute.key) {
44+
<p class="font-normal">
45+
<span class="font-bold">{{ attribute.label }}:</span> {{ attribute.value }}
46+
</p>
47+
}
48+
</div>
5649
}
5750
</p-accordion-content>
5851
</p-accordion-panel>

‎src/app/features/project/overview/components/overview-collections/overview-collections.component.ts‎

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@ import { Button } from 'primeng/button';
55
import { Skeleton } from 'primeng/skeleton';
66
import { Tag } from 'primeng/tag';
77

8-
import {
9-
ChangeDetectionStrategy,
10-
Component,
11-
computed,
12-
CUSTOM_ELEMENTS_SCHEMA,
13-
input,
14-
ViewEncapsulation,
15-
} from '@angular/core';
8+
import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
169
import { RouterLink } from '@angular/router';
1710

1811
import { collectionFilterNames } from '@osf/features/collections/constants';
19-
import { CEDAR_VIEWER_CONFIG } from '@osf/features/metadata/constants';
2012
import { CedarMetadataDataTemplateJsonApi, CedarMetadataRecordData } from '@osf/features/metadata/models';
2113
import { StopPropagationDirective } from '@osf/shared/directives/stop-propagation.directive';
2214
import { CollectionSubmission } from '@osf/shared/models/collections/collections.model';
@@ -41,8 +33,6 @@ import { CollectionStatusSeverityPipe } from '@osf/shared/pipes/collection-statu
4133
templateUrl: './overview-collections.component.html',
4234
styleUrl: './overview-collections.component.scss',
4335
changeDetection: ChangeDetectionStrategy.OnPush,
44-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
45-
encapsulation: ViewEncapsulation.None,
4636
})
4737
export class OverviewCollectionsComponent {
4838
projectSubmissions = input<CollectionSubmission[] | null>(null);
@@ -51,8 +41,6 @@ export class OverviewCollectionsComponent {
5141
cedarRecords = input<CedarMetadataRecordData[] | null>(null);
5242
cedarTemplates = input<CedarMetadataDataTemplateJsonApi[] | null>(null);
5343

54-
cedarViewerConfig = CEDAR_VIEWER_CONFIG;
55-
5644
cedarRecordByTemplateId = computed(() => {
5745
const records = this.cedarRecords();
5846
return new Map(
@@ -85,4 +73,40 @@ export class OverviewCollectionsComponent {
8573

8674
return attributes;
8775
}
76+
77+
getCedarAttributes(record: CedarMetadataRecordData, template: CedarMetadataDataTemplateJsonApi): KeyValueModel[] {
78+
const { order, propertyLabels } = template.attributes.template._ui;
79+
const metadata = record.attributes.metadata as Record<string, unknown>;
80+
const attributes: KeyValueModel[] = [];
81+
82+
for (const key of order) {
83+
const label = propertyLabels[key];
84+
const value = this.formatCedarValue(metadata[key]);
85+
if (label && value) {
86+
attributes.push({ key, label, value });
87+
}
88+
}
89+
90+
return attributes;
91+
}
92+
93+
private formatCedarValue(value: unknown): string {
94+
if (value == null) return '';
95+
96+
if (Array.isArray(value)) {
97+
return value
98+
.map((item) => this.formatCedarValue(item))
99+
.filter(Boolean)
100+
.join(', ');
101+
}
102+
103+
if (typeof value === 'object') {
104+
const obj = value as Record<string, unknown>;
105+
if ('@value' in obj && obj['@value'] != null) return String(obj['@value']);
106+
if ('rdfs:label' in obj && obj['rdfs:label'] != null) return String(obj['rdfs:label']);
107+
return '';
108+
}
109+
110+
return String(value);
111+
}
88112
}

0 commit comments

Comments
 (0)