Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/skills/react-webview-architecture/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ Animations: `Collapse` from `@fluentui/react-motion-components-preview`
| Hook | Purpose |
| ------------------------------------- | -------------------------------------------------------------------------------------------- |
| `useSelectiveContextMenuPrevention()` | Prevents browser context menu everywhere except Monaco editors. Call once in top-level view. |
| `useHideScrollbarsDuringResize()` | Returns a function that temporarily hides scrollbars during layout transitions (500ms). |

## Conditional Rendering Patterns

Expand Down Expand Up @@ -240,7 +239,7 @@ try {

## Common Pitfalls

1. **Forgetting refs with third-party components** → stale data in event handlers
1. **Using refs for event-handler freshness** → event handlers refresh during rendering; use refs only for a stable callback in a long-lived subscription or imperative API, and keep current values synchronized
2. **Not cleaning up** event listeners, Monaco instances, AbortControllers in `useEffect` return
3. **Not calling `editor.layout()`** after resize → blank Monaco panels
4. **Using `any`** → use proper types or `unknown` with type guards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ export type CollectionViewContextType = {
disableDeleteDocument: boolean;
};
dataSelection: {
selectedDocumentObjectIds: string[];
selectedDocumentIndexes: number[];
readonly selectedRowKeys: readonly string[];
};
queryEditor?: {
getCurrentQuery: () => {
Expand Down Expand Up @@ -769,16 +768,6 @@ const configuration = useConfiguration<CollectionViewWebviewConfigurationType>()

Prevents browser context menus everywhere except Monaco editors. Call once in the top-level view component.

### `useHideScrollbarsDuringResize`

Temporarily hides scrollbars during layout transitions (e.g., QueryEditor collapse animations) to prevent flickering:

```tsx
const hideScrollbarsTemporarily = useHideScrollbarsDuringResize();
// Call before triggering a layout change
hideScrollbarsTemporarily();
```

For tRPC-related hooks (`useTrpcClient`) and patterns, see the **webview-trpc-messaging** skill.

---
Expand Down
39 changes: 19 additions & 20 deletions build/verification/browser/collectionViewFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,10 @@ const heterogeneousPage: TablePageOutput = {
],
};

const deepRowKey = 'id:"deep-root"';
const deepRootKey = JSON.stringify([deepRowKey]);
const deepProfileKey = JSON.stringify([deepRowKey, 'profile']);
const deepAddressKey = JSON.stringify([deepRowKey, 'profile', 'address']);
const deepLocationKey = JSON.stringify([deepRowKey, 'profile', 'address', 'location']);
const deepRootKey = JSON.stringify([0]);
const deepProfileKey = JSON.stringify([0, 'profile']);
const deepAddressKey = JSON.stringify([0, 'profile', 'address']);
const deepLocationKey = JSON.stringify([0, 'profile', 'address', 'location']);
const deepNestingNodes: CollectionOutputs['getCurrentPageAsTree'] = [
{
key: deepRootKey,
Expand All @@ -192,7 +191,7 @@ const deepNestingNodes: CollectionOutputs['getCurrentPageAsTree'] = [
expandable: true,
},
{
key: JSON.stringify([deepRowKey, '_id']),
key: JSON.stringify([0, '_id']),
parentKey: deepRootKey,
depth: 1,
field: '_id',
Expand Down Expand Up @@ -224,40 +223,40 @@ const deepNestingNodes: CollectionOutputs['getCurrentPageAsTree'] = [
expandable: true,
},
{
key: JSON.stringify([deepRowKey, 'profile', 'address', 'location', 'coordinates']),
key: JSON.stringify([0, 'profile', 'address', 'location', 'coordinates']),
parentKey: deepLocationKey,
depth: 4,
field: 'coordinates',
value: { display: '{ 2 fields }', type: 'object' },
expandable: true,
},
{
key: JSON.stringify([deepRowKey, 'profile', 'address', 'location', 'coordinates', 'latitude']),
parentKey: JSON.stringify([deepRowKey, 'profile', 'address', 'location', 'coordinates']),
key: JSON.stringify([0, 'profile', 'address', 'location', 'coordinates', 'latitude']),
parentKey: JSON.stringify([0, 'profile', 'address', 'location', 'coordinates']),
depth: 5,
field: 'latitude',
value: { display: '47.6062', type: 'double' },
expandable: false,
},
{
key: JSON.stringify([deepRowKey, 'profile', 'address', 'location', 'coordinates', 'longitude']),
parentKey: JSON.stringify([deepRowKey, 'profile', 'address', 'location', 'coordinates']),
key: JSON.stringify([0, 'profile', 'address', 'location', 'coordinates', 'longitude']),
parentKey: JSON.stringify([0, 'profile', 'address', 'location', 'coordinates']),
depth: 5,
field: 'longitude',
value: { display: '-122.3321', type: 'double' },
expandable: false,
},
{
key: JSON.stringify(['id:"second-root"']),
key: JSON.stringify([1]),
parentKey: null,
depth: 0,
field: '"second-root"',
value: { display: '{ 1 field }', type: 'object' },
expandable: true,
},
{
key: JSON.stringify(['id:"second-root"', '_id']),
parentKey: JSON.stringify(['id:"second-root"']),
key: JSON.stringify([1, '_id']),
parentKey: JSON.stringify([1]),
depth: 1,
field: '_id',
value: { display: 'second-root', type: 'string' },
Expand All @@ -266,10 +265,10 @@ const deepNestingNodes: CollectionOutputs['getCurrentPageAsTree'] = [
];

const arraysRowKey = 'id:"arrays-root"';
const arraysRootKey = JSON.stringify([arraysRowKey]);
const emptyArrayKey = JSON.stringify([arraysRowKey, 'empty']);
const tenArrayKey = JSON.stringify([arraysRowKey, 'ten']);
const elevenArrayKey = JSON.stringify([arraysRowKey, 'eleven']);
const arraysRootKey = JSON.stringify([0]);
const emptyArrayKey = JSON.stringify([0, 'empty']);
const tenArrayKey = JSON.stringify([0, 'ten']);
const elevenArrayKey = JSON.stringify([0, 'eleven']);
const arrayNodes: CollectionOutputs['getCurrentPageAsTree'] = [
{
key: arraysRootKey,
Expand All @@ -280,7 +279,7 @@ const arrayNodes: CollectionOutputs['getCurrentPageAsTree'] = [
expandable: true,
},
{
key: JSON.stringify([arraysRowKey, '_id']),
key: JSON.stringify([0, '_id']),
parentKey: arraysRootKey,
depth: 1,
field: '_id',
Expand All @@ -306,7 +305,7 @@ const arrayNodes: CollectionOutputs['getCurrentPageAsTree'] = [
...Array.from(
{ length: 10 },
(_, index): TreeNode => ({
key: JSON.stringify([arraysRowKey, 'ten', index]),
key: JSON.stringify([0, 'ten', index]),
parentKey: tenArrayKey,
depth: 2,
field: `ten[${index}]`,
Expand Down
2 changes: 1 addition & 1 deletion build/verification/browser/scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ export const collectionViewContracts = {
selector: '[role="grid"]',
includes: ['nested Alpha'],
excludes: ['leaf Alpha'],
steps: [{ action: 'click', role: 'button', name: 'Up' }],
steps: [{ action: 'click', role: 'button', name: 'Level up' }],
},
{
kind: 'text',
Expand Down
5 changes: 5 additions & 0 deletions docs/ai-and-plans/features/data-grid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ released extension version or completion of the remaining handover gates.
visual glyph is decorative and there is no BSON type hover tooltip.
- Row selection and document-action eligibility are separate. Rows without a safe, unique
identity remain browsable and selectable, but cannot become View/Edit/Delete targets.
- Tree node keys use the zero-based page position plus typed field/array path segments, so their
size does not depend on `_id`; Table identity and actions keep the existing `rowKey` contract.
- A replacement Tree page starts collapsed. When that removes the focused cell, the Tree restores
focus in the same column at the root row, or the first row if the root is absent. It leaves
focus on controls outside the grid alone.
- Object `_id` values with more than one own key and an integer-like key at any depth are
conservatively ineligible for document actions. Their rows remain displayed and selectable.
- Table column sizing keeps neighbors stable during resizing, then reflows
Expand Down
14 changes: 14 additions & 0 deletions docs/ai-and-plans/features/data-grid/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ implementation remains subject to the planned work items and later gates.
| 0005 | Object `_id` values with integer-like keys | Accepted | The user-facing explanation moved to #1144 | 2026-11-27 | #1142 |
| 0006 | UX review: sizing gate, previews, copy and hover | Accepted | Sizing accepted; native platform Copy clarified | 2026-11-30 | #1142 |
| 0007 | Column-width hold release and width scope | Accepted | Remount by scope rejected; frozen widths deferred | 2026-12-01 | #1142 |
| 0008 | Position-based Tree node keys | Accepted | Replaces document-identity-based Tree keys | 2026-12-01 | #1142 |

## 0001 - React Data Grid, beta candidate and document tree

Expand Down Expand Up @@ -311,3 +312,16 @@ never fires, the hold stays until the next gesture or column change.
registered in the capture phase instead.
- `CollectionView.test.tsx` checks that each Table page keeps the query and path it was
loaded for, through step-in, view switches and a new query.

## 0008 - Position-based Tree node keys

**Status:** Accepted · **Date:** 2026-12-01

The Tree key contract is `JSON.stringify([index, ...segments])`, where `index` is the document's
zero-based position in the current page and path segments retain their field-string or array-index
number types. Table row identity and document-action eligibility are unchanged and continue to
use `documentId`/`rowKey`. This changes only Tree node identity; root labels and display values,
field/path order, preorder, and the array expansion bound remain unchanged.

This approval is recorded as WI-R1/C4 option A in the
[Copilot PR review triage table](./iterations/08-copilot-pr-review-triage.md#operator-decisions-2026-12-01).
13 changes: 10 additions & 3 deletions docs/ai-and-plans/features/data-grid/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ shapes fetched documents into the grid-neutral types in `src/utils/documentGrid/
components consume `TablePage` and `TreeNode` data rather than raw database documents.

`TablePage` contains the root `_id` column, the fields at the active nested path, and rows in
server order. Each cell has separate display text and BSON type metadata. `toTreeNodes` creates
stable hierarchical nodes from documents; `useTreeRows` sorts siblings by field name and exposes
only roots and descendants whose ancestors are expanded. The tree is application-owned rather
server order. Each cell has separate display text and BSON type metadata. `toTreeNodes` creates hierarchical nodes from documents; `useTreeRows` sorts siblings by field
name and exposes only roots and descendants whose ancestors are expanded. Its node keys are
`JSON.stringify([index, ...segments])`, with a zero-based page index and typed string/number
path segments. The keys do not contain or depend on `_id`. The tree is application-owned rather
than RDG's `TreeDataGrid`, so it can represent arbitrary document nesting and the current array
expansion bound.

Expand All @@ -41,6 +42,8 @@ Identity and action eligibility are distinct from whether a row can be browsed o
JavaScript array-index range are still guarded.
- IDs are counted within the current fetched page. A unique safe ID yields `id:<canonical-id>`;
otherwise the row gets a page-position key (`pos:<index>`) and no `documentId`.
- Table row identity remains separate from Tree node keys. Tree keys identify nodes only within
the current page and never imply action eligibility.
- All rows remain visible and selectable. Document actions resolve selected keys against the
current `TablePage` and fail closed if a page/key is stale or any row lacks `documentId`.
- A Document View save preserves an owned falsy `_id` (`0`, `false`, `""`, or `null`) by passing its
Expand Down Expand Up @@ -128,6 +131,10 @@ The 24 px expander and matching leaf slot align field names. The Fluent chevron
over 100 ms when motion is allowed; reduced-motion preference removes the transition. The Tree
fills the results area and reserves a stable scrollbar gutter.

A replacement Tree page starts collapsed. If that removes the focused descendant, focus returns
to its root row in the same column, or to the first row in that column if the root key is absent.
The restore runs only when focus is on the document body or inside the Tree grid.

RDG owns grid-cell navigation. Arrow keys move through visible cells; Tab and Shift+Tab traverse
cells and row boundaries. Focus capture synchronizes RDG's active position with the cell reached
by native Tab navigation. A popup gets Escape first. In Table, when rows are selected, the first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,11 @@ export function toTablePage(
export function toTreeNodes(documents: readonly Document[], identityTrusted: boolean): TreeNode[];
```

**Contract amendment (2026-12-01, WI-R1/C4):** the approved Tree contract is now
`toTreeNodes(documents: readonly Document[])`, with keys
`JSON.stringify([index, ...segments])` using a zero-based page index and typed path segments.
Table identity and `rowKey` are unchanged. See [decision 0008](../decisions.md#0008---position-based-tree-node-keys).

**Host invariants:**

- `toDocumentId`: require an own `_id` and reject `undefined`, array, regexp, DBRef, Map and unknown
Expand Down
Loading
Loading