Skip to content

Commit dc1c6c8

Browse files
committed
fix(plugin-dashboard): open a drilled record at once when its rows are the whole drill
Claude-Session: https://claude.ai/code/session_01JQwxbZkNEjKLHtTo4edMVH Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7b66cc0 commit dc1c6c8

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

‎ui/packages/plugin-dashboard/src/DrillRecordList.tsx‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import React from 'react';
3636
import { PageRegionPostureReset } from '@object-ui/components';
3737
import { ComponentRegistry, resolveFilterPlaceholders, resolveNameField } from '@object-ui/core';
3838
import { SchemaRenderer, SchemaRendererContext, useDrillNavigation, useFilterScope } from '@object-ui/react';
39+
import type { DrillRecordOrigin } from '@object-ui/react';
3940
import { FILTER_DATE_LIKE_TYPES } from '@object-ui/types';
4041
import { Loader2 } from 'lucide-react';
4142
import { RecordDetailDrawer } from './RecordDetailDrawer';
@@ -189,14 +190,15 @@ export const DrillRecordList: React.FC<DrillRecordListProps> = ({
189190
if (!openRecord) return setOpened(record);
190191
const id = rowId(record);
191192
if (!id || opening.current) return;
192-
opening.current = true;
193+
const open = (origin: DrillRecordOrigin) => {
194+
openRecord(objectName, id, origin);
195+
onNavigate?.();
196+
};
193197
const { ids, total, findParams } = shown.current;
194-
void drillRecordOrigin({ dataSource, objectName, recordId: id, drawn: ids, total, findParams })
195-
.then((origin) => {
196-
openRecord(objectName, id, origin);
197-
onNavigate?.();
198-
})
199-
.finally(() => { opening.current = false; });
198+
const origin = drillRecordOrigin({ dataSource, objectName, recordId: id, drawn: ids, total, findParams });
199+
if (!(origin instanceof Promise)) return open(origin);
200+
opening.current = true;
201+
void origin.then(open).finally(() => { opening.current = false; });
200202
}}
201203
/>
202204
{!openRecord && (

‎ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ describe('drillRecordOrigin (#36554)', () => {
7878
expect(ds.find.mock.calls.map(([, params]) => (params as { $top?: number }).$top)).toEqual([250, 250]);
7979
});
8080

81-
it('control: a result all drawn reads nothing and hands the rows drawn with the count', async () => {
81+
it('control: a result all drawn reads nothing and hands the rows drawn with the count, at once', () => {
8282
const ds = source(3);
83-
const origin = await drillRecordOrigin({
83+
const origin = drillRecordOrigin({
8484
dataSource: ds, objectName: 'deal', recordId: 'd2', drawn: ['d1', 'd2', 'd3'], total: 3, findParams: QUERY,
8585
});
86+
// No read owed, so no promise: the record page opens on the click itself.
87+
expect(origin).not.toBeInstanceOf(Promise);
8688
expect(origin).toEqual({ siblings: ['d1', 'd2', 'd3'], total: 3 });
8789
expect(ds.find).not.toHaveBeenCalled();
8890
});

‎ui/packages/plugin-dashboard/src/drillRecordSteps.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ const rowsOf = (result: unknown): Row[] => {
7070
const positiveInt = (value: unknown): number | undefined =>
7171
typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined;
7272

73-
/** The origin a drilled record's page opens with (see the file header). */
74-
export async function drillRecordOrigin(input: DrillRecordStepInput): Promise<DrillRecordOrigin> {
73+
/**
74+
* The origin a drilled record's page opens with (see the file header). Answered
75+
* at once, with no read, when the rows drawn are the whole result; a promise
76+
* only when the rest has to be read.
77+
*/
78+
export function drillRecordOrigin(input: DrillRecordStepInput): DrillRecordOrigin | Promise<DrillRecordOrigin> {
7579
const { dataSource, objectName, recordId, drawn, total, findParams } = input;
7680
const siblings = drawn.includes(recordId) ? [...drawn] : [recordId];
7781
const drawnOrigin: DrillRecordOrigin = { siblings, ...(total != null ? { total } : {}) };
@@ -86,6 +90,17 @@ export async function drillRecordOrigin(input: DrillRecordStepInput): Promise<Dr
8690
return drawnOrigin;
8791
}
8892

93+
return readWholeResult(ds, objectName, recordId, total, findParams, drawnOrigin);
94+
}
95+
96+
async function readWholeResult(
97+
ds: FindCapable,
98+
objectName: string,
99+
recordId: string,
100+
total: number,
101+
findParams: Readonly<Record<string, unknown>>,
102+
drawnOrigin: DrillRecordOrigin,
103+
): Promise<DrillRecordOrigin> {
89104
const query: Record<string, unknown> = { ...findParams };
90105
for (const key of ['$top', '$skip', '$select', '$expand', '$count']) delete query[key];
91106
const window = Math.max(positiveInt(findParams.$top) ?? 0, MIN_STEP_WINDOW);

0 commit comments

Comments
 (0)