MemberJunction / MemberJunction/MJ
Query grid: entity-link cells can only display their own key -- allow showing a name while linking by ID
- Dominant language
- TSQL
- Stars
- 29
- Forks
- 6
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 323
Description
## Summary
In the query/data grid (`@memberjunction/ng-query-viewer`), an entity-link cell uses **the cell's own value** as both the link text and the record key. There is no way to show a human-readable field (a name) while opening the record by its primary key.
So a link can only ever display a key. A table of animals, customers or orders that should read **"Willa →"** instead reads **"88617A16-431F-478C-88C2-D36CE15FE73B →"**.
## Where it comes from
`packages/Angular/Generic/query-viewer/src/lib/query-data-grid/query-data-grid.component.ts`, `renderEntityLinkCell`:
```ts
link.textContent = String(params.value); // what the user sees
...
this.EntityLinkClick.emit({
entityName: col.targetEntityName!,
recordId: String(params.value), // what gets opened -- the SAME value
column: col,
rowData: params.data
});
```
A column is a link when `resolveTargetEntity(sourceEntity, sourceFieldName)` lands on a primary or foreign key. The link therefore has to sit on the key column, and the key column shows the key.
The row-detail panel (`query-row-detail.component.ts`) works the same way.
## Why it matters
This is most visible in **agent-produced Data artifacts**. `data-artifact-viewer` renders them through this grid. That makes it the path by which an agent shows a user the records it is talking about. An agent recommending specific records gets a table where the clickable column is a column of UUIDs.
We hit it on a visitor-facing kiosk: an adoption agent recommends animals, and the only way to open an animal's profile (photo, full details) is a link labelled with its ID. It works, but it is the one part of the screen that looks broken to a member of the public.
There is also no fallback in the chat text. `mj-markdown` exposes only `rendered`, `headingClick` and `codeCopied`, so a link in an agent's message cannot open a record either.
## Proposed
Let a column **display one field while linking by another**. For example, an optional `linkKeyField` on the column descriptor / `QueryGridColumnConfig`:
```jsonc
{ "field": "Name", "sourceEntity": "MJ: Animals", "sourceFieldName": "Name", "linkKeyField": "ID" }
```
Then `renderEntityLinkCell` shows `params.value` (the name) and emits `recordId: String(params.data[linkKeyField])`.
Other shapes that would also work:
- Infer it: when a row carries the entity's primary key, a column mapped to the entity's `IsNameField` links by that key automatically.
- Flip it: keep linking on the key column, but let it render a chosen display field.
The first is explicit and changes nothing for existing payloads. Either inference option would make agent artifacts look right with no prompt changes.
## Observed on
MJ **6.1.0-edge.4** (`43217fa139`). `renderEntityLinkCell` is unchanged on `next`.
Contributor guide
Research direction
Start with renderEntityLinkCell in packages/Angular/Generic/query-viewer/src/lib/query-data-grid/query-data-grid.component.ts and compare it with query-row-detail.component.ts. Trace the column descriptor or QueryGridColumnConfig used by both paths, then determine how the proposed display field and link key should be represented. Done means a name can be displayed while the corresponding record still opens by its primary key, without changing existing payload behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100