Skip to content

Commit 1a9b924

Browse files
feat(schema): render the Referrals section under each instance
Mirrors the legacy Joomla /content/schema/instance/browser/{id} layout that lists every other instance referencing the current one, grouped by attribute name. Fetches the new /ContentService/data/instance/{id}/referrers endpoint (content-service@7b9eceb) after the instance loads and renders the groups in a table below the attribute view. Silently degrades to no section if the endpoint 500s or isn't deployed, so the page is still useful in that fallback state.
1 parent 57b96f7 commit 1a9b924

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

projects/website-angular/src/app/content/schema/instance-browser/instance-browser.component.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,32 @@ <h2>
5151
<p>No attributes found for this instance.</p>
5252
</div>
5353
}
54+
55+
@if (referrals.length > 0) {
56+
<div class="referrals-section">
57+
<h3>Referrals</h3>
58+
<p class="section-desc">Other instances that reference this one, grouped by attribute:</p>
59+
<table class="attr-table referrals">
60+
<tbody>
61+
@for (group of referrals; track group.referral) {
62+
<tr>
63+
<td class="attr-name">
64+
<em>({{ group.referral }})</em>
65+
</td>
66+
<td class="attr-value">
67+
@for (obj of group.objects; track obj.dbId; let last = $last) {
68+
<a
69+
class="instance-link"
70+
href="#"
71+
(click)="onLinkClick(obj.dbId, $event)"
72+
>[{{ obj.schemaClass }}:{{ obj.stId || obj.dbId }}] {{ obj.displayName }}</a>
73+
@if (!last) { <br /> }
74+
}
75+
</td>
76+
</tr>
77+
}
78+
</tbody>
79+
</table>
80+
</div>
81+
}
5482
}

projects/website-angular/src/app/content/schema/instance-browser/instance-browser.component.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@
8989
word-break: break-word;
9090
}
9191

92+
.referrals-section {
93+
margin-top: 32px;
94+
95+
h3 {
96+
margin-bottom: 4px;
97+
}
98+
99+
.section-desc {
100+
color: var(--on-surface-variant);
101+
font-size: 0.85rem;
102+
margin-bottom: 12px;
103+
}
104+
105+
.attr-name em {
106+
color: var(--on-surface-variant);
107+
font-style: italic;
108+
}
109+
}
110+
92111
.instance-link {
93112
color: var(--primary);
94113
text-decoration: none;

projects/website-angular/src/app/content/schema/instance-browser/instance-browser.component.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Subject } from 'rxjs';
1212
import { takeUntil } from 'rxjs/operators';
1313
import {
1414
ContentDataService,
15+
InstanceReferrals,
1516
SchemaAttribute,
1617
} from '../../../../services/content-data.service';
1718

@@ -43,6 +44,7 @@ export class InstanceBrowserComponent implements OnChanges, OnDestroy {
4344
schemaClass = '';
4445
dbId: number | string = '';
4546
rows: AttributeRow[] = [];
47+
referrals: InstanceReferrals[] = [];
4648
loading = true;
4749
error = false;
4850

@@ -63,6 +65,7 @@ export class InstanceBrowserComponent implements OnChanges, OnDestroy {
6365
this.loading = true;
6466
this.error = false;
6567
this.rows = [];
68+
this.referrals = [];
6669

6770
this.contentDataService
6871
.getInstance(this.instanceId)
@@ -73,6 +76,7 @@ export class InstanceBrowserComponent implements OnChanges, OnDestroy {
7376
this.schemaClass = instance.schemaClass || instance.className || '';
7477
this.dbId = instance.dbId;
7578
this.loadAttributes();
79+
this.loadReferrals();
7680
},
7781
error: () => {
7882
this.error = true;
@@ -81,6 +85,22 @@ export class InstanceBrowserComponent implements OnChanges, OnDestroy {
8185
});
8286
}
8387

88+
private loadReferrals() {
89+
this.contentDataService
90+
.getInstanceReferrers(this.instanceId)
91+
.pipe(takeUntil(this.destroy$))
92+
.subscribe({
93+
next: (groups) => {
94+
this.referrals = groups || [];
95+
},
96+
error: () => {
97+
// Endpoint absent or 500 -- silently degrade; the page is still
98+
// useful without the referrals list.
99+
this.referrals = [];
100+
},
101+
});
102+
}
103+
84104
private loadAttributes() {
85105
this.contentDataService.getSchemaAttributes(this.schemaClass).subscribe({
86106
next: (attrs) => {

projects/website-angular/src/services/content-data.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export interface SimpleDatabaseObject {
7878
schemaClass: string;
7979
}
8080

81+
export interface InstanceReferrals {
82+
referral: string;
83+
objects: SimpleDatabaseObject[];
84+
}
85+
8186
@Injectable({
8287
providedIn: 'root',
8388
})
@@ -136,4 +141,10 @@ export class ContentDataService {
136141
`${CONTENT_SERVICE}/data/query/enhanced/${id}`
137142
);
138143
}
144+
145+
getInstanceReferrers(id: string | number): Observable<InstanceReferrals[]> {
146+
return this.http.get<InstanceReferrals[]>(
147+
`${CONTENT_SERVICE}/data/instance/${id}/referrers`
148+
);
149+
}
139150
}

0 commit comments

Comments
 (0)