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
11 changes: 11 additions & 0 deletions .changeset/36554-drill-record-steps-whole-result.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@object-ui/plugin-dashboard': patch
'@object-ui/plugin-list': patch
---

fix(plugin-dashboard): a record opened from a drill counts and steps through the drill's whole result

Clause-②: yes (widening) — one additive member, `ListViewProps.onFindParamsChange` (`@object-ui/plugin-list`); nothing is removed or renamed
Metadata-protocol: none

A record opened from a dashboard or report drill showed 「1 of N」 and stepped ↑ ↓ only over the rows the drill's list had drawn on its page, so a drill that matched 40 records and drew 20 let the reader walk 20. The `list-view` page block handed its own `onTotalChange` (the tab badge's count) to the list after the host's, so the drill never heard the count; it now hands the count to both. The list now also reports the query behind the rows it draws (`onFindParamsChange`, a host prop answered where `onRowsChange` answers with rows), and the drill re-issues that query for record ids alone, with the same filter, sort and search, when the count exceeds the rows drawn or the rows drawn are a later page. The record page is handed every record the drill matched, in the drill list's order, up to 1,000, and the count it matched, so its counter says where the record sits in the whole drill and ↑ ↓ walk all of it. A read that fails, a record past the first 1,000, or a result that changed under the list keeps the rows drawn as the step set, as before.
145 changes: 145 additions & 0 deletions ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,148 @@ describe('the drill dialog draws the standard list (#36256)', () => {
expect(headers.slice(0, 3)).toEqual(['Name', 'Stage', 'Amount']);
});
});

/**
* objectstack-ai/objectstack#36554 — a record opened from a drill steps
* through the drill's whole result. The real list draws one page of the
* drill (2 of 40 rows); the record page the host opens is handed all 40 ids,
* read with the drill list's own query (its filter and sort, ids only), and
* the count the list matched, so it reads 「1 of 40」 and ↑ ↓ walk every
* record. A drill whose result is all drawn reads nothing more.
*/
describe('a record opened from a drill steps through the whole drill (#36554)', () => {
const ALL = Array.from({ length: 40 }, (_, i) => ({
id: `d${i + 1}`,
name: i === 0 ? 'Acme' : `Deal ${i + 1}`,
stage: 'negotiation',
amount: i + 1,
}));

function mountPaged(rows: typeof ALL, pageSize: number, { holdIdReads = false } = {}) {
// With `holdIdReads`, the drill's id reads wait until `releaseIdReads()`.
let releaseIdReads = () => {};
const idReadsHeld = new Promise<void>((resolve) => { releaseIdReads = resolve; });
const ds = {
find: vi.fn(async (_object: string, params: { $top?: number; $skip?: number; $select?: string[] } = {}) => {
if (holdIdReads && JSON.stringify(params.$select) === '["id"]') await idReadsHeld;
const skip = params.$skip ?? 0;
const top = params.$top ?? rows.length;
const page = rows.slice(skip, skip + top);
const select = params.$select;
return {
data: select ? page.map((row) => Object.fromEntries(select.map((f) => [f, (row as Record<string, unknown>)[f]]))) : page,
total: rows.length,
};
}),
findOne: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
bulk: vi.fn(),
getObjectSchema: vi.fn(async () => structuredClone(DEFINITION)),
};
const openRecord = vi.fn();
const onClose = vi.fn();
const drill = (open: boolean) => (
<SchemaRendererProvider dataSource={ds as any}>
<DrillNavigationProvider value={{ openRecord }}>
<DrillDownDrawer
open={open}
target="dialog"
onClose={onClose}
title="Negotiation"
objectName="deal_36256"
filter={{ stage: 'negotiation' }}
defaultColumns={['stage', 'amount']}
maxRows={pageSize}
dataSource={ds}
/>
</DrillNavigationProvider>
</SchemaRendererProvider>
);
const view = render(drill(true));
return { ds, openRecord, onClose, releaseIdReads, close: () => view.rerender(drill(false)), unmount: view.unmount };
}

const idReads = (ds: { find: ReturnType<typeof vi.fn> }) =>
ds.find.mock.calls.filter(([, params]) => JSON.stringify((params as { $select?: unknown })?.$select) === '["id"]');

it('hands the record page every record the drill matched, with its count, read by the drill list\'s own query', async () => {
const { ds, openRecord } = mountPaged(ALL, 2);
const dialog = await screen.findByTestId('drill-down-dialog');
await within(dialog).findByText('Acme');
// The list drew one page: 2 of the 40 rows.
expect(within(dialog).queryByText('Deal 3')).toBeNull();
await act(async () => fireEvent.click(within(dialog).getByText('Acme')));
await waitFor(() => expect(openRecord).toHaveBeenCalledTimes(1));

const [objectName, recordId, origin] = openRecord.mock.calls[0];
expect(objectName).toBe('deal_36256');
expect(recordId).toBe('d1');
expect(origin.total).toBe(40);
expect(origin.siblings).toEqual(ALL.map((row) => row.id));

// The ids came from the drill's query: its condition, no other read shape.
const reads = idReads(ds);
expect(reads.length).toBeGreaterThan(0);
for (const [object, params] of reads) {
expect(object).toBe('deal_36256');
expect(JSON.stringify((params as { $filter?: unknown }).$filter)).toContain('negotiation');
}
for (const write of [ds.create, ds.update, ds.delete, ds.bulk]) expect(write).not.toHaveBeenCalled();
});

it('opens no record when the drill is closed while its result is read', async () => {
const { ds, openRecord, onClose, releaseIdReads, close } = mountPaged(ALL, 2, { holdIdReads: true });
const dialog = await screen.findByTestId('drill-down-dialog');
await within(dialog).findByText('Acme');
await act(async () => fireEvent.click(within(dialog).getByText('Acme')));
await waitFor(() => expect(idReads(ds).length).toBeGreaterThan(0));

// The reader closes the drill (Esc, an outside click) before the ids come back.
act(() => close());
await waitFor(() => expect(screen.queryByTestId('drill-down-dialog')).toBeNull());
await act(async () => { releaseIdReads(); await Promise.resolve(); });
await new Promise((resolve) => setTimeout(resolve, 0));
expect(openRecord).not.toHaveBeenCalled();
expect(onClose).not.toHaveBeenCalled();
});

it('opens no record when the drill is gone while its result is read', async () => {
const { ds, openRecord, onClose, releaseIdReads, unmount } = mountPaged(ALL, 2, { holdIdReads: true });
const dialog = await screen.findByTestId('drill-down-dialog');
await within(dialog).findByText('Acme');
await act(async () => fireEvent.click(within(dialog).getByText('Acme')));
await waitFor(() => expect(idReads(ds).length).toBeGreaterThan(0));

unmount();
await act(async () => { releaseIdReads(); await Promise.resolve(); });
await new Promise((resolve) => setTimeout(resolve, 0));
expect(openRecord).not.toHaveBeenCalled();
expect(onClose).not.toHaveBeenCalled();
});

it('opens the record clicked last when a second record is clicked while the first is read', async () => {
const { openRecord, releaseIdReads } = mountPaged(ALL, 2, { holdIdReads: true });
const dialog = await screen.findByTestId('drill-down-dialog');
await within(dialog).findByText('Deal 2');
await act(async () => fireEvent.click(within(dialog).getByText('Acme')));
await act(async () => fireEvent.click(within(dialog).getByText('Deal 2')));
await act(async () => { releaseIdReads(); await Promise.resolve(); });
await waitFor(() => expect(openRecord).toHaveBeenCalled());
await new Promise((resolve) => setTimeout(resolve, 0));
expect(openRecord).toHaveBeenCalledTimes(1);
expect(openRecord.mock.calls[0][1]).toBe('d2');
expect(openRecord.mock.calls[0][2]).toEqual({ siblings: ALL.map((row) => row.id), total: 40 });
});

it('control: a drill whose result is all drawn hands those rows and reads nothing more', async () => {
const { ds, openRecord } = mountPaged(ALL.slice(0, 3), 10);
const dialog = await screen.findByTestId('drill-down-dialog');
await within(dialog).findByText('Deal 3');
await act(async () => fireEvent.click(within(dialog).getByText('Acme')));
await waitFor(() => expect(openRecord).toHaveBeenCalledTimes(1));
expect(openRecord.mock.calls[0][2]).toEqual({ siblings: ['d1', 'd2', 'd3'], total: 3 });
expect(idReads(ds)).toHaveLength(0);
});
});
1 change: 1 addition & 0 deletions ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export const DrillDownDrawer: React.FC<DrillDownDrawerProps> = ({
maxRows={maxRows}
dataSource={dataSource}
onNavigate={onClose}
open={open}
/>
)
: (
Expand Down
45 changes: 38 additions & 7 deletions ui/packages/plugin-dashboard/src/DrillRecordList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
* no create, no bulk action, no view switch, no saved view.
*
* The record's name opens its full page through the host
* (`DrillNavigationContext.openRecord`, item 6), with the rows the list shows
* as the page's ↑ ↓ set and the count it matched; no record panel is stacked
* over the drill. A host with no record page (a page block's metric or pivot
* (`DrillNavigationContext.openRecord`, item 6), with the drill's whole
* result as the page's ↑ ↓ set and the count it matched (`drillRecordOrigin`,
* objectstack-ai/objectstack#36554: the rows past the page drawn are read by
* the list's own query); no record panel is stacked over the drill. A host with no record page (a page block's metric or pivot
* mounts no navigation) opens the record in a dialog showing the fields the
* list lists: the list reads only those (`$select`), so a field it did not
* read is not drawn as empty.
Expand All @@ -35,10 +36,12 @@ import React from 'react';
import { PageRegionPostureReset } from '@object-ui/components';
import { ComponentRegistry, resolveFilterPlaceholders, resolveNameField } from '@object-ui/core';
import { SchemaRenderer, SchemaRendererContext, useDrillNavigation, useFilterScope } from '@object-ui/react';
import type { DrillRecordOrigin } from '@object-ui/react';
import { FILTER_DATE_LIKE_TYPES } from '@object-ui/types';
import { Loader2 } from 'lucide-react';
import { RecordDetailDrawer } from './RecordDetailDrawer';
import { drillListConditions } from './drillConditions';
import { drillRecordOrigin } from './drillRecordSteps';

/** The registry key of the standard list (`@object-ui/plugin-list`). */
export const DRILL_LIST_COMPONENT = 'list-view';
Expand All @@ -61,6 +64,11 @@ export interface DrillRecordListProps {
dataSource?: any;
/** Called after the host opened a record's page. */
onNavigate?: () => void;
/**
* Whether the drill's dialog is open (default: open). A record whose step
* set is still being read when it closes is not opened.
*/
open?: boolean;
}

type Summary = string | Record<string, unknown>;
Expand All @@ -81,6 +89,7 @@ export const DrillRecordList: React.FC<DrillRecordListProps> = ({
maxRows,
dataSource: ownDataSource,
onNavigate,
open: dialogOpen = true,
}) => {
const context = React.useContext(SchemaRendererContext);
const dataSource = ownDataSource ?? context?.dataSource;
Expand Down Expand Up @@ -116,7 +125,19 @@ export const DrillRecordList: React.FC<DrillRecordListProps> = ({

const [added, setAdded] = React.useState<string[]>([]);
const [summaries, setSummaries] = React.useState<Record<string, Summary>>({});
const shown = React.useRef<{ ids: string[]; total?: number }>({ ids: [] });
const shown = React.useRef<{
ids: string[];
total?: number;
findParams?: Readonly<Record<string, unknown>> | null;
}>({ ids: [] });
// The record a click asks for while its step set is read: the last click
// wins, and none opens once the drill is closed or gone (objectstack#36554).
const lastOpen = React.useRef(0);
const live = React.useRef(dialogOpen);
React.useLayoutEffect(() => {
live.current = dialogOpen;
return () => { live.current = false; };
}, [dialogOpen]);
const [opened, setOpened] = React.useState<Record<string, unknown> | null>(null);

const baseColumns = React.useMemo(() => {
Expand Down Expand Up @@ -173,14 +194,24 @@ export const DrillRecordList: React.FC<DrillRecordListProps> = ({
shown.current = { ...shown.current, ids: rows.map(rowId).filter((id): id is string => !!id) };
}}
onTotalChange={(total: number) => { shown.current = { ...shown.current, total }; }}
onFindParamsChange={(findParams: Readonly<Record<string, unknown>> | null) => {
shown.current = { ...shown.current, findParams };
}}
rowOpensRecord
onRowClick={(record: Record<string, unknown>) => {
if (!openRecord) return setOpened(record);
const id = rowId(record);
if (!id) return;
const { ids, total } = shown.current;
openRecord(objectName, id, { siblings: ids.includes(id) ? ids : [id], ...(total != null ? { total } : {}) });
onNavigate?.();
const click = ++lastOpen.current;
const open = (origin: DrillRecordOrigin) => {
if (click !== lastOpen.current || !live.current) return;
openRecord(objectName, id, origin);
onNavigate?.();
};
const { ids, total, findParams } = shown.current;
const origin = drillRecordOrigin({ dataSource, objectName, recordId: id, drawn: ids, total, findParams });
if (origin instanceof Promise) void origin.then(open);
else open(origin);
}}
/>
{!openRecord && (
Expand Down
Loading
Loading