From 69ee46935de10c54a67dc7b2b18145ce89a93f42 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 10:35:57 +0000 Subject: [PATCH 01/15] wip(plugin-dashboard): drill opens a centred dialog over the standard list Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../app-shell/src/views/DashboardView.tsx | 8 +- .../app-shell/src/views/ReportView.tsx | 18 +- .../app-shell/src/views/useOpenRecordList.ts | 35 +++- .../plugin-dashboard/src/DatasetWidget.tsx | 24 ++- .../plugin-dashboard/src/DrillDownDrawer.tsx | 61 +++++-- .../plugin-dashboard/src/DrillRecordList.tsx | 160 ++++++++++++++++++ .../plugin-dashboard/src/drillConditions.ts | 121 +++++++++++++ .../src/DatasetReportRenderer.tsx | 135 ++++++++++++--- .../src/context/DrillNavigationContext.tsx | 15 ++ 9 files changed, 523 insertions(+), 54 deletions(-) create mode 100644 ui/packages/plugin-dashboard/src/DrillRecordList.tsx create mode 100644 ui/packages/plugin-dashboard/src/drillConditions.ts diff --git a/ui/packages/app-shell/src/views/DashboardView.tsx b/ui/packages/app-shell/src/views/DashboardView.tsx index 7b9e294577e..9ad4389217b 100644 --- a/ui/packages/app-shell/src/views/DashboardView.tsx +++ b/ui/packages/app-shell/src/views/DashboardView.tsx @@ -98,8 +98,6 @@ type DashboardRefreshState = Parameters< // --------------------------------------------------------------------------- export function DashboardView({ dataSource }: { dataSource?: any }) { - // Drill "escape hatch": lets the drill drawers open an object's full list page. - const drillNavigation = useRecordListDrillNavigation(); const { dashboardName } = useParams<{ dashboardName: string }>(); // Setup's own System Overview (`platform-objects`' `system_overview`). const isSystemOverview = useInSetupApp() && dashboardName === 'system_overview'; @@ -254,6 +252,12 @@ export function DashboardView({ dataSource }: { dataSource?: any }) { return { ...dashboard, widgets: filtered }; }, [dashboard, unregistered]); + // Drill navigation: the drill list's 「Open in list」 and its record pages, + // which name this dashboard as their way back (objectstack-ai/objectstack#36256). + const drillNavigation = useRecordListDrillNavigation( + dashboard ? resolveKeyedI18nLabel(dashboard.label, t) || dashboard.name : undefined, + ); + // ---- Loading / not-found guards ----------------------------------------- if (isLoading) { return ; diff --git a/ui/packages/app-shell/src/views/ReportView.tsx b/ui/packages/app-shell/src/views/ReportView.tsx index cea581b7a76..03a09bb7d8a 100644 --- a/ui/packages/app-shell/src/views/ReportView.tsx +++ b/ui/packages/app-shell/src/views/ReportView.tsx @@ -71,8 +71,10 @@ export function ReportView({ dataSource }: { dataSource?: DataSource }) { // Drill-through (ADR-0021 D2): clicking an aggregated row/cell opens the // underlying records in an in-place drawer (peek without leaving the report), // with an "Open in list →" escape hatch to the full object list page. - const drillNavigation = useRecordListDrillNavigation(); - const [drill, setDrill] = useState<{ object: string; filter: Record; title: string } | null>(null); + const drillNavigation = useRecordListDrillNavigation( + metadataText(reportData?.title, language) ?? metadataText(reportData?.label, language), + ); + const [drill, setDrill] = useState<{ object: string; filter: Record; title: string; fields?: string[] } | null>(null); const getFieldsForObject = useCallback( (objName: string | undefined) => { @@ -118,7 +120,7 @@ export function ReportView({ dataSource }: { dataSource?: DataSource }) { // dim (the drill lands on a superset rather than filtering wrongly) // - granularity-bucketed dates → need a range, not equality; skip too const handleDatasetDrill = useCallback( - async ({ dataset, groupKey, object, objectFilter }: DatasetDrillArgs) => { + async ({ dataset, groupKey, object, objectFilter, fields }: DatasetDrillArgs) => { try { // Drawer header: the clicked group's display values (e.g. "West / Q3"), // else the report's label in the viewer's language (objectui#13470). @@ -131,7 +133,7 @@ export function ReportView({ dataSource }: { dataSource?: DataSource }) { // server's drillRawRows — correct for select/lookup dims (a stored // value, not a display label) with NO dataset-definition round-trip. if (object && objectFilter) { - setDrill({ object, filter: objectFilter, title }); + setDrill({ object, filter: objectFilter, title, fields }); return; } @@ -550,15 +552,17 @@ export function ReportView({ dataSource }: { dataSource?: DataSource }) { /> - {/* Drill-through drawer: peek the records behind a clicked group, then - click a row to open a record, or use "Open in list →" to escalate to - the full object list page. */} + {/* Drill-through dialog: the records behind a clicked group or bar in the + standard list; a record's name opens its page, 「Open in list」 the + object's list page (objectstack-ai/objectstack#36256). */} setDrill(null)} title={drill?.title ?? ''} objectName={drill?.object ?? ''} filter={drill?.filter} + defaultColumns={drill?.fields} + target="dialog" dataSource={dataSource as any} /> diff --git a/ui/packages/app-shell/src/views/useOpenRecordList.ts b/ui/packages/app-shell/src/views/useOpenRecordList.ts index 3302a7ee1f2..ad907cfef3c 100644 --- a/ui/packages/app-shell/src/views/useOpenRecordList.ts +++ b/ui/packages/app-shell/src/views/useOpenRecordList.ts @@ -7,14 +7,14 @@ */ import { useCallback, useMemo } from 'react'; -import { useNavigate, useParams } from 'react-router-dom'; +import { useLocation, useNavigate, useParams } from 'react-router-dom'; import { convertFiltersToAST, resolveFilterPlaceholders, toFilterNodeSafely, type FilterTokenScope, } from '@object-ui/core'; -import { useFilterScope } from '@object-ui/react'; +import { useFilterScope, type DrillRecordOrigin } from '@object-ui/react'; import { usePermissions } from '@object-ui/permissions'; import { parseFilterAST } from '@objectstack/spec/data'; import { @@ -248,6 +248,8 @@ export interface RecordListDrillNavigation { openRecordList: (objectName: string, filter?: Record) => void; /** Whether the list route can say this drill's filter exactly. */ canOpenRecordList: (objectName: string, filter?: Record) => boolean; + /** Open a drilled record's page, this page as its way back (objectstack-ai/objectstack#36256). */ + openRecord: (objectName: string, recordId: string, origin?: DrillRecordOrigin) => void; } /** @@ -308,8 +310,9 @@ export interface RecordListDrillNavigation { * everything else through untouched, so a placeholder-free drill produces a * byte-identical URL. */ -export function useRecordListDrillNavigation(): RecordListDrillNavigation { +export function useRecordListDrillNavigation(originLabel?: string): RecordListDrillNavigation { const navigate = useNavigate(); + const location = useLocation(); const { appName } = useParams<{ appName?: string }>(); // Session scope for `{current_user_id}` / `{current_org_id}`. Read at hook // level — the returned handlers are callbacks, and hooks cannot be called @@ -337,7 +340,31 @@ export function useRecordListDrillNavigation(): RecordListDrillNavigation { }, [navigate, appName, filterScope, canRead], ); - return useMemo(() => ({ openRecordList, canOpenRecordList }), [openRecordList, canOpenRecordList]); + // objectstack-ai/objectstack#36256 — a drilled record opens as its page, + // with the history-state `from` a list hands the page it opens + // (`listOriginOf`): this page as the way back, the drill list's rows as the + // ↑ ↓ set and the count it matched for 「N of M」. + const openRecord = useCallback( + (objectName: string, recordId: string, origin?: DrillRecordOrigin) => { + const base = appName ? `/apps/${appName}` : ''; + const siblings = origin?.siblings?.length ? [...origin.siblings] : undefined; + navigate(`${base}/${objectName}/record/${encodeURIComponent(recordId)}`, { + state: { + from: { + pathname: location.pathname + location.search, + label: originLabel ?? '', + ...(siblings ? { siblings } : {}), + ...(siblings && origin?.total != null && origin.total >= siblings.length ? { total: origin.total } : {}), + }, + }, + }); + }, + [navigate, appName, location.pathname, location.search, originLabel], + ); + return useMemo( + () => ({ openRecordList, canOpenRecordList, openRecord }), + [openRecordList, canOpenRecordList, openRecord], + ); } /** The navigate half of {@link useRecordListDrillNavigation}. */ diff --git a/ui/packages/plugin-dashboard/src/DatasetWidget.tsx b/ui/packages/plugin-dashboard/src/DatasetWidget.tsx index c40bc3e3213..f47b5fcc2aa 100644 --- a/ui/packages/plugin-dashboard/src/DatasetWidget.tsx +++ b/ui/packages/plugin-dashboard/src/DatasetWidget.tsx @@ -112,6 +112,7 @@ import { DrillDownDrawer, type DrillDownNotice } from './DrillDownDrawer'; import { DatasetQueryCoalescerContext } from './datasetQueryBatch'; import { metricDrillFilter, readMeasureDrillScope } from './metricDrill'; import { sharedMeasureDrillScope, scopeDrillFilter } from './measureDrill'; +import { measuredFieldsOf } from './drillConditions'; import { specDefaultWidgetType } from './widgetDispatch'; import { DASHBOARD_WIDGET_MULTI_MEASURE_TYPES } from '@objectstack/spec/ui'; import { SnakeCaseIdentifierSchema } from '@objectstack/spec/shared'; @@ -1054,7 +1055,7 @@ export function DatasetWidget({ widget, dataSource, heading, onForbidden, packag // while each hop's schema is read, and keeps one when the path cannot be // drilled (`resolveDatasetDrillFilter`); `filter` is set once there is a list // to read. - const [drill, setDrill] = useState<{ filter?: Record; title: string; notice?: DrillDownNotice } | null>(null); + const [drill, setDrill] = useState<{ filter?: Record; title: string; notice?: DrillDownNotice; columns?: string[] } | null>(null); // The click a pending relationship resolution answers: a later click, or the // drawer closing, makes an earlier answer stale. const drillRequest = useRef(0); @@ -1495,6 +1496,15 @@ export function DatasetWidget({ widget, dataSource, heading, onForbidden, packag const scope = sharedMeasureDrillScope(state, measures); if (!scope) return; const drillTitle = title || String(widget?.title ?? ''); + // objectstack-ai/objectstack#36256 item 4 — the list shows the record's + // name, the fields this bucket is grouped by (a base-object field; a + // relationship path has no column on the base list) and the fields the + // measure aggregates; the reader adds the rest. + const columns = Array.from(new Set([ + ...drillDims.map((d) => dimensionFields?.[d]).filter((f): f is string => !!f && !f.includes('.')), + ...Object.values(drillRanges?.[index] ?? {}).map((range) => range.field), + ...measuredFieldsOf(scope), + ])); const request = ++drillRequest.current; const scopedFilter = scopeDrillFilter(runtimeFilter, scope); // A dimension whose field is a `relationship.field` path drills as one @@ -1517,7 +1527,7 @@ export function DatasetWidget({ widget, dataSource, heading, onForbidden, packag }).then( (resolution) => { if (drillRequest.current !== request) return; - if (resolution.status === 'resolved') setDrill({ filter: resolution.filter, title: drillTitle }); + if (resolution.status === 'resolved') setDrill({ filter: resolution.filter, title: drillTitle, columns }); else setDrill({ title: drillTitle, notice: resolution.status === 'too-many' ? 'too-many' : 'unavailable' }); }, (error: unknown) => { @@ -1545,7 +1555,7 @@ export function DatasetWidget({ widget, dataSource, heading, onForbidden, packag console.warn(`[DatasetWidget] drill-down refused — the drilled list cannot be scoped: ${error.message}`); return; } - setDrill({ filter: merged, title: drillTitle }); + setDrill({ filter: merged, title: drillTitle, columns }); }; const closeDrill = () => { drillRequest.current += 1; @@ -1559,6 +1569,8 @@ export function DatasetWidget({ widget, dataSource, heading, onForbidden, packag objectName={drillObject} filter={drill.filter} notice={drill.notice} + defaultColumns={drill.columns} + target="dialog" dataSource={dataSource} /> ) : null; @@ -1626,7 +1638,11 @@ export function DatasetWidget({ widget, dataSource, heading, onForbidden, packag ranges: drillRanges?.[0], }); const openTileDrill = tileDrillFilter - ? () => setDrill({ filter: tileDrillFilter, title: heading?.title || measureLabel }) + ? () => setDrill({ + filter: tileDrillFilter, + title: heading?.title || measureLabel, + columns: measuredFieldsOf(readMeasureDrillScope(state, tileMeasure)), + }) : undefined; const tileDrillProps = openTileDrill ? { diff --git a/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx b/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx index baa9251a489..e5ba36fe6b3 100644 --- a/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx +++ b/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx @@ -2,12 +2,17 @@ * ObjectUI * Copyright (c) 2024-present ObjectStack Inc. * - * DrillDownDrawer — opens a side drawer (or dialog) that lists the - * underlying records behind a clicked pivot cell / chart segment. + * DrillDownDrawer — lists the underlying records behind a clicked pivot + * cell / chart segment / metric tile, in a centred dialog (or a side drawer). * - * Composition: + . The data table receives - * the merged filter (widget filter ∧ drill filter) and the data source - * inherited from the schema renderer context. + * The dialog (objectstack-ai/objectstack#36256) floats over the page about + * 70% wide and 65% tall with the shared dialog card, and dims and blurs + * nothing behind it: it is non-modal, so the page stays readable, and a + * click outside it closes it. A phone keeps the side drawer. Either way the + * body is the standard list (`DrillRecordList`) when the renderer has one + * registered; a renderer without `@object-ui/plugin-list` lists the records + * in `ObjectDataTable`. No record panel is ever stacked over the drill: a + * record's name opens its page. */ import React from 'react'; @@ -21,12 +26,14 @@ import { DialogHeader, DialogTitle, cn, + useIsMobile, } from '@object-ui/components'; import { SchemaRenderer, useDrillNavigation } from '@object-ui/react'; import { useSafeTranslate } from '@object-ui/i18n'; import { AlertTriangle, Loader2 } from 'lucide-react'; import { ObjectDataTable } from './ObjectDataTable'; import { OpenInListButton } from './OpenInListButton'; +import { DrillRecordList, drillListAvailable } from './DrillRecordList'; export interface DrillDownDrawerProps { open: boolean; @@ -48,6 +55,12 @@ export interface DrillDownDrawerProps { dataSource?: any; /** Optional column whitelist. */ columns?: string[]; + /** + * The fields the drilled number stands for — its grouped and measured + * fields — shown after the record's name when no `columns` whitelist is + * given (objectstack-ai/objectstack#36256 item 4). The reader adds the rest. + */ + defaultColumns?: string[]; /** Optional max rows. */ maxRows?: number; /** Optional className on the inner container. */ @@ -144,11 +157,13 @@ export const DrillDownDrawer: React.FC = ({ filter, dataSource, columns, + defaultColumns, maxRows, className, report, notice, }) => { + const phone = useIsMobile(); const { openRecordList, canOpenRecordList } = useDrillNavigation(); const tt = useSafeTranslate(); const isReportDrill = isDatasetBoundReport(report); @@ -223,6 +238,20 @@ export const DrillDownDrawer: React.FC = ({ }; return ; })() + : drillListAvailable() + ? ( + + ) : ( = ({ pagination: true, searchable: false, pageSize: maxRows, - // Complete the drill chain: a row in this filtered record list - // opens that record. Dialog target so it stacks over this drawer. - // Mirrors the chart / KPI drill tables — every drill-through list - // (pivot, dataset, chart, metric) lands on a clickable record. - drillDown: { enabled: true, mode: 'record', target: 'dialog' }, }} dataSource={dataSource} failureMessage={tt(DRILL_NOTICE_COPY.failed.key, DRILL_NOTICE_COPY.failed.fallback)} @@ -246,15 +270,20 @@ export const DrillDownDrawer: React.FC = ({ ); - if (target === 'dialog') { + if (target === 'dialog' && !phone) { + // Non-modal: Radix draws no overlay for it, so nothing behind is dimmed + // or blurred, and an outside click dismisses it like a popover. return ( - !v && onClose()}> - - - {title} + !v && onClose()}> + + + {title} {escapeHatch} - {body} +
{body}
); diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx new file mode 100644 index 00000000000..2441ca7450e --- /dev/null +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -0,0 +1,160 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * The records behind a drilled number, drawn by the standard list + * (objectstack-ai/objectstack#36256 item 5): the `list-view` block the object + * list page draws its table with, mounted through the registry, so the drill + * has the list's row height, sorting, filter chips, added columns, record + * count and column calculations, and no table of its own. + * + * What the reader does here is this mount's state alone (item 8): the sort, + * the edited chips, the added columns and the column calculations live in the + * list and in this component, are written nowhere (no view, no preference), + * and are gone when the drill closes. The list is read-only: no inline edit, + * 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. + */ + +import React from 'react'; +import { ComponentRegistry, resolveFilterPlaceholders, resolveNameField } from '@object-ui/core'; +import { SchemaRenderer, SchemaRendererContext, useDrillNavigation, useFilterScope } from '@object-ui/react'; +import { Loader2 } from 'lucide-react'; +import { drillListConditions } from './drillConditions'; + +/** The registry key of the standard list (`@object-ui/plugin-list`). */ +export const DRILL_LIST_COMPONENT = 'list-view'; + +/** Whether the standard list is registered in this renderer. */ +export function drillListAvailable(): boolean { + return !!ComponentRegistry.get(DRILL_LIST_COMPONENT); +} + +export interface DrillRecordListProps { + objectName: string; + /** The drill's filter, as composed (placeholders still authored). */ + filter?: Record; + /** An authored column whitelist (`drillDown.columns`): shown as written. */ + columns?: string[]; + /** The columns the drill stands for (the grouped and measured fields), after the record's name. */ + defaultColumns?: string[]; + /** Rows per page (`drillDown.maxRows`). */ + maxRows?: number; + dataSource?: any; + /** Called after the host opened a record's page. */ + onNavigate?: () => void; +} + +type Summary = string | Record; + +const rowId = (row: Record): string | undefined => { + const id = row?.id ?? row?._id; + return id == null || id === '' ? undefined : String(id); +}; + +export const DrillRecordList: React.FC = ({ + objectName, + filter, + columns, + defaultColumns, + maxRows, + dataSource: ownDataSource, + onNavigate, +}) => { + const context = React.useContext(SchemaRendererContext); + const dataSource = ownDataSource ?? context?.dataSource; + const { openRecord } = useDrillNavigation(); + const scope = useFilterScope(); + // One resolution per mount: a chip shows the value the query compares. + const conditions = React.useMemo( + () => drillListConditions(resolveFilterPlaceholders(filter, scope) as Record | undefined), + // The drill's filter is fixed for the life of this mount (the dialog keys it). + // eslint-disable-next-line react-hooks/exhaustive-deps + [], + ); + + // The object's name field leads the default columns, as on the list page. + const [nameField, setNameField] = React.useState( + columns?.length || typeof dataSource?.getObjectSchema !== 'function' ? null : undefined, + ); + React.useEffect(() => { + if (nameField !== undefined) return; + let live = true; + Promise.resolve(dataSource.getObjectSchema(objectName)) + .then((def: unknown) => { if (live) setNameField(resolveNameField(def) ?? null); }) + .catch(() => { if (live) setNameField(null); }); + return () => { live = false; }; + }, [dataSource, objectName, nameField]); + + const [added, setAdded] = React.useState([]); + const [summaries, setSummaries] = React.useState>({}); + const shown = React.useRef<{ ids: string[]; total?: number }>({ ids: [] }); + + const baseColumns = React.useMemo(() => { + if (columns?.length) return columns; + const lead = nameField ? [nameField] : []; + return Array.from(new Set([...lead, ...(defaultColumns ?? [])])); + }, [columns, defaultColumns, nameField]); + + if (nameField === undefined) { + return ( +
+
+ ); + } + + const listColumns = [...baseColumns, ...added.filter((f) => !baseColumns.includes(f))].map((field) => + summaries[field] ? { field, summary: summaries[field] } : field, + ); + const schema = { + type: DRILL_LIST_COMPONENT, + objectName, + viewType: 'grid', + ...(conditions.rest ? { filter: conditions.rest } : {}), + // An empty list lets the list pick its own columns (no name field known). + ...(listColumns.length > 0 ? { columns: listColumns } : {}), + ...(maxRows ? { pagination: { pageSize: maxRows } } : {}), + userActions: { editInline: false, addRecordForm: false, rowColor: false, group: false }, + }; + + return ( + { + setSummaries((prev) => { + const next = { ...prev }; + if (summary) next[field] = summary; + else delete next[field]; + return next; + }); + }} + onRowsChange={(rows: ReadonlyArray>) => { + shown.current = { ...shown.current, ids: rows.map(rowId).filter((id): id is string => !!id) }; + }} + onTotalChange={(total: number) => { shown.current = { ...shown.current, total }; }} + rowOpensRecord={!!openRecord} + onRowClick={openRecord ? (record: 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?.(); + } : undefined} + /> + ); +}; diff --git a/ui/packages/plugin-dashboard/src/drillConditions.ts b/ui/packages/plugin-dashboard/src/drillConditions.ts new file mode 100644 index 00000000000..f1d1391d311 --- /dev/null +++ b/ui/packages/plugin-dashboard/src/drillConditions.ts @@ -0,0 +1,121 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * The drill list's conditions, as the list's own filter chips + * (objectstack-ai/objectstack#36256 item 3). + * + * A drill hands the list one filter object (the widget filter, the clicked + * bucket and the measure's scope, composed by `composeDrillFilter`). The list + * draws the reader's conditions as chips that can be changed and removed, and + * the view's own filter as locked chips it can only read when it is a rule + * array. So each condition of the drill that is one field compared with one + * value becomes a row of the list's filter group (`initialFilters`), drawn as an + * ordinary chip; everything else (a nested relationship condition, an `$or`, an + * operator the rows have no id for) stays the list's base `filter`, applied + * as it was. Both are ANDed, so the list matches the drill exactly until the + * reader edits a chip. + * + * Values must already be resolved (`resolveFilterPlaceholders`): a chip shows + * what the query compares, never a `{token}`. + */ + +import type { FilterBuilderRow, FilterBuilderRowGroup } from '@object-ui/components'; + +/** The row operator each comparison operator of the filter dialect reads as. */ +const ROW_OPERATOR: Readonly> = { + $eq: 'equals', + $ne: 'not_equals', + $in: 'in', + $nin: 'not_in', + $gt: 'greater_than', + $gte: 'greater_than_or_equal', + $lt: 'less_than', + $lte: 'less_than_or_equal', + $contains: 'contains', +}; + +type Scalar = string | number | boolean; + +const isScalar = (v: unknown): v is Scalar => + typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean'; + +const isPlainObject = (v: unknown): v is Record => + !!v && typeof v === 'object' && !Array.isArray(v); + +/** Split a filter into its ANDed single-key parts: `$and` members and the keys of one object. */ +function andParts(filter: unknown): Record[] { + if (!isPlainObject(filter)) return []; + const parts: Record[] = []; + for (const [key, value] of Object.entries(filter)) { + if (key === '$and' && Array.isArray(value)) { + for (const member of value) parts.push(...andParts(member)); + } else { + parts.push({ [key]: value }); + } + } + return parts; +} + +/** The rows one `{ field: condition }` part reads as, or `null` when it is no row. */ +function rowsOf(field: string, condition: unknown): Omit[] | null { + if (field.startsWith('$')) return null; + if (isScalar(condition)) return [{ field, operator: 'equals', value: condition }]; + if (!isPlainObject(condition)) return null; + const entries = Object.entries(condition); + if (entries.length === 0) return null; + const rows: Omit[] = []; + for (const [op, value] of entries) { + if (op === '$null' && typeof value === 'boolean') { + rows.push({ field, operator: value ? 'is_null' : 'is_not_null' }); + continue; + } + const operator = ROW_OPERATOR[op]; + if (!operator) return null; + const list = operator === 'in' || operator === 'not_in'; + if (list ? !Array.isArray(value) || !value.every(isScalar) : !isScalar(value)) return null; + rows.push({ field, operator, value: value as FilterBuilderRow['value'] }); + } + return rows; +} + +export interface DrillListConditions { + /** The conditions drawn as the list's chips, its `initialFilters`. */ + chips: FilterBuilderRowGroup; + /** What no chip can say, kept as the list's base `filter`; `undefined` when nothing is left. */ + rest: Record | undefined; +} + +/** Split a resolved drill filter into chip rows and the rest (see the file header). */ +export function drillListConditions(filter: Record | undefined): DrillListConditions { + const conditions: FilterBuilderRow[] = []; + const rest: Record[] = []; + for (const part of andParts(filter)) { + const [field, condition] = Object.entries(part)[0]; + const rows = rowsOf(field, condition); + if (rows) rows.forEach((row) => conditions.push({ ...row, id: `drill-${conditions.length}` })); + else rest.push(part); + } + return { + chips: { logic: 'and', conditions }, + rest: rest.length === 0 ? undefined : rest.length === 1 ? rest[0] : { $and: rest }, + }; +} + +/** + * The fields a drill's measure scope says hold a value — `{ field: { $null: + * false } }`, which the dataset answer's `drillScopes` writes for a measure + * over a field (the spec's `drillScopes` description). Those are the fields + * the clicked number aggregates, so the list shows them by default. + */ +export function measuredFieldsOf(scope: unknown): string[] { + return andParts(scope) + .map((part) => Object.entries(part)[0]) + .filter(([field, c]) => !field.startsWith('$') && isPlainObject(c) && c.$null === false && Object.keys(c).length === 1) + .map(([field]) => field); +} diff --git a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx index 9d6ad9b5bc4..0626344f0c2 100644 --- a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx +++ b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx @@ -110,6 +110,8 @@ import { // family lives (#4466 / #4497 / #4673 / #4500 / #4508), so routing through it // INHERITS those fixes instead of re-deriving them on a third surface. buildChartSeries, + findChartSeriesRow, + type ChartSegmentClickEvent, // The authored half of objectui#4229's data/presentation split (objectui#4877): // the chrome and the per-series presentation. No axis is lowered, and none // needs to be: a report's `chart.xAxis`/`chart.yAxis` are bare @@ -215,6 +217,12 @@ export interface DatasetDrillArgs { * would mis-filter — without re-fetching the dataset definition. */ objectFilter?: Record; + /** + * The object fields the clicked number stands for — the bucket's grouped + * fields and the measure's aggregated ones — which the drill list shows + * after the record's name (objectstack-ai/objectstack#36256). + */ + fields?: string[]; } /** A report (or joined block) bound to a dataset. Field access is permissive — */ @@ -921,6 +929,74 @@ function resolveRelationshipDrill( ); } +/** + * Drill one clicked bucket — a table line or a chart mark — to its records: + * the exact field-to-stored-value filter when the answer names its `object` + * (a relationship path resolved first), else the host's `groupKey` fallback. + * One function for both, so a bar and the table line it stands for open the + * same list (objectstack-ai/objectstack#36256). `fields` names the grouped + * and measured fields the drill list shows by default. + */ +function emitBucketDrill({ + state, + dataset, + groupKey, + drillDims, + rawRow, + rowRanges, + scope, + runtimeFilter, + dataSource, + onDrill, +}: { + state: { object?: string; dimensionFields?: Record }; + dataset: string; + groupKey: Record; + drillDims: string[]; + rawRow: Record | undefined; + rowRanges: Record | undefined; + scope: MeasureDrillScope; + runtimeFilter: Record | undefined; + dataSource: unknown; + onDrill: (args: DatasetDrillArgs) => void; +}): void { + const hasRange = !!rowRanges && Object.keys(rowRanges).length > 0; + const fields = Array.from(new Set([ + ...drillDims.map((d) => state.dimensionFields?.[d]).filter((f): f is string => !!f && !f.includes('.')), + ...Object.values(rowRanges ?? {}).map((range) => range.field), + ...measuredFieldsOf(scope), + ])); + if (state.object && datasetDrillHasRelationshipPath(drillDims, state.dimensionFields)) { + const object = state.object; + resolveRelationshipDrill(object, scope, rawRow, drillDims, state.dimensionFields ?? {}, runtimeFilter, rowRanges, dataSource, (resolved) => + onDrill({ dataset, groupKey, runtimeFilter, object, objectFilter: resolved, fields })); + return; + } + let objectFilter: Record | undefined; + if (state.object && (drillDims.length > 0 || hasRange)) { + const built = drillFilterOrRefusal(scope, rawRow, drillDims, state.dimensionFields ?? {}, runtimeFilter, rowRanges); + // Refused: no drill at all — see `drillFilterOrRefusal`. + if (built === null) return; + objectFilter = built; + } else if (Object.keys(scope).length > 0) { + // No exact bucket filter to carry the scope, and the host's groupKey + // fallback rebuilds the list from the bucket ALONE: no drill. + return; + } + onDrill({ dataset, groupKey, runtimeFilter, object: state.object, objectFilter, fields }); +} + +/** + * The fields a measure scope says hold a value (`{ field: { $null: false } }`, + * which `drillScopes` writes for a measure over a field): the fields the + * clicked number aggregates. + */ +function measuredFieldsOf(scope: MeasureDrillScope): string[] { + return Object.entries(scope ?? {}) + .filter(([field, c]) => !field.startsWith('$') && !!c && typeof c === 'object' && (c as { $null?: unknown }).$null === false) + .map(([field]) => field); +} + function EmptyMeasures({ dataset }: { dataset: string }) { return (
@@ -1111,25 +1187,7 @@ function DatasetReportTable({ const rowRanges = members ? spanDrillRanges(members.map((i) => state.drillRanges?.[i])) : state.drillRanges?.[index]; - const hasRange = !!rowRanges && Object.keys(rowRanges).length > 0; - let objectFilter: Record | undefined; - if (state.object && datasetDrillHasRelationshipPath(drillDims, state.dimensionFields)) { - const object = state.object; - resolveRelationshipDrill(object, scope, state.drillRawRows?.[index], drillDims, state.dimensionFields ?? {}, runtimeFilter, rowRanges, dataSource, (resolved) => - onDrill!({ dataset, groupKey, runtimeFilter, object, objectFilter: resolved })); - return; - } - if (state.object && (drillDims.length > 0 || hasRange)) { - const built = drillFilterOrRefusal(scope, state.drillRawRows?.[index], drillDims, state.dimensionFields ?? {}, runtimeFilter, rowRanges); - // Refused: no drill at all — see `drillFilterOrRefusal`. - if (built === null) return; - objectFilter = built; - } else if (Object.keys(scope).length > 0) { - // No exact bucket filter to carry the scope, and the host's groupKey - // fallback rebuilds the list from the bucket ALONE: no drill. - return; - } - onDrill!({ dataset, groupKey, runtimeFilter, object: state.object, objectFilter }); + emitBucketDrill({ state, dataset, groupKey, drillDims, rawRow: state.drillRawRows?.[index], rowRanges, scope, runtimeFilter, dataSource, onDrill: onDrill! }); }; // objectui#7534 — resolve a BUILT-IN default measure's caption through the @@ -1435,7 +1493,7 @@ export function planReportChart(t: unknown): ReportChartPlan { */ function useRegistryComponent( type: string, -): React.ComponentType<{ schema: Record }> | undefined { +): React.ComponentType<{ schema: Record; onChartClick?: (event: ChartSegmentClickEvent) => void }> | undefined { const [, bump] = React.useReducer((x: number) => x + 1, 0); React.useEffect(() => { if (ComponentRegistry.get(type)) return; @@ -1452,7 +1510,7 @@ function useRegistryComponent( return unsub; }, [type]); return ComponentRegistry.get(type) as - | React.ComponentType<{ schema: Record }> + | React.ComponentType<{ schema: Record; onChartClick?: (event: ChartSegmentClickEvent) => void }> | undefined; } @@ -1548,6 +1606,7 @@ function DatasetReportChart({ dataSource, order, timeWindow, + onDrill, }: { dataset: string; chart: Record; @@ -1555,6 +1614,8 @@ function DatasetReportChart({ dataSource?: unknown; order?: SelectionOrder; timeWindow?: ReportTimeWindow; + /** The report's drill sink: a clicked mark drills like its table line (objectstack-ai/objectstack#36256). */ + onDrill?: (args: DatasetDrillArgs) => void; }) { const xAxis = typeof chart.xAxis === 'string' ? chart.xAxis : ''; const yAxis = typeof chart.yAxis === 'string' ? chart.yAxis : ''; @@ -1851,6 +1912,36 @@ function DatasetReportChart({ // itself — not spec `ChartAxis` objects, so there is no axis presentation to // merge. (`@object-ui/core`'s object-axis lowering, `mergeAuthoredPresentation`, // was deliberately not used here and was removed by objectui#11372.) + // objectstack-ai/objectstack#36256 — a mark drills to the records its + // bucket counted, through the table's own `emitBucketDrill`, so a bar and + // its summary line open the same list. A measure the answer gives no record + // list (`drillScopes`) offers no click. + const markScope: MeasureDrillScope | undefined = state.object ? measureDrillScope(state.drillScopes, yAxis) : {}; + const handleMarkClick = onDrill && markScope !== undefined + ? (ev: ChartSegmentClickEvent) => { + const at = findChartSeriesRow(plotRows, queryDimensions, [yAxis], ev?.category, ev?.series, { + nullCategoryLabel, + bucketId: ev?.categoryId, + }); + if (at < 0) return; + const index = plotLayout ? plotLayout[at] : at; + const groupKey: Record = {}; + for (const dim of queryDimensions) groupKey[dim] = displayRows[index]?.[dim]; + emitBucketDrill({ + state, + dataset, + groupKey, + drillDims: state.dimensionFields ? queryDimensions.filter((d) => d in state.dimensionFields!) : [], + rawRow: state.drillRawRows?.[index], + rowRanges: state.drillRanges?.[index], + scope: markScope, + runtimeFilter, + dataSource, + onDrill, + }); + } + : undefined; + const authoredSeries = mergeAuthoredSeries(derivedSeries, chart.series); // #4020's three-level display name OUTRANKS both of the labels above: the // derivation's `fields[].label` (level ② without the i18n field-label @@ -1922,6 +2013,7 @@ function DatasetReportChart({ // chart's own default (value-descending) still applies. ...(categoryOrder ? { categoryOrder } : {}), }} + onChartClick={handleMarkClick} />
); @@ -2555,6 +2647,7 @@ const DatasetReportRendererBody: React.FC = ({ dataSource={dataSource} order={reportOrder} timeWindow={timeWindow} + onDrill={drillSink} /> ) : null; diff --git a/ui/packages/react/src/context/DrillNavigationContext.tsx b/ui/packages/react/src/context/DrillNavigationContext.tsx index 3cbc890f4f4..a143a45e002 100644 --- a/ui/packages/react/src/context/DrillNavigationContext.tsx +++ b/ui/packages/react/src/context/DrillNavigationContext.tsx @@ -63,6 +63,21 @@ export interface DrillNavigationValue { * destination, which is how a host behaved before this member existed. */ canOpenRecordList?: (objectName: string, filter?: Record) => boolean; + /** + * Open one drilled record's full page (objectstack-ai/objectstack#36256): + * the drill list's record name calls it. `origin` is the drill list the + * page came from: the ids of the rows it shows, in order, which the page + * steps through with ↑ ↓ under its 「N of M」 counter, and the count it + * matched. The host makes the page it opened from (the dashboard, the + * report) the page's way back. Absent ⇒ the drill list opens no record. + */ + openRecord?: (objectName: string, recordId: string, origin?: DrillRecordOrigin) => void; +} + +/** The drill list a record page was opened from — see {@link DrillNavigationValue.openRecord}. */ +export interface DrillRecordOrigin { + siblings: readonly string[]; + total?: number; } export const DrillNavigationContext = createContext({}); From 184bb3c6a27293a6754316f4b78d9f83071bf14c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 11:14:15 +0000 Subject: [PATCH 02/15] test(plugin-dashboard): pin the drill dialog over the standard list, the chart mark drill and the record page set Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../36256-drill-dialog-standard-list.md | 17 +++ .../drillDialogStandardList-36256.test.tsx | 104 ++++++++++++++ ...nRecordList.drillRecordPage-36256.test.tsx | 57 ++++++++ .../plugin-dashboard/src/DrillRecordList.tsx | 9 +- .../__tests__/DrillDownDialog-36256.test.tsx | 129 ++++++++++++++++++ .../__tests__/DrillDownDrawer.chain.test.tsx | 20 +-- .../__tests__/drillConditions-36256.test.ts | 49 +++++++ ...portRenderer.chartMarkDrill-36256.test.tsx | 73 ++++++++++ 8 files changed, 444 insertions(+), 14 deletions(-) create mode 100644 .changeset/36256-drill-dialog-standard-list.md create mode 100644 ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx create mode 100644 ui/packages/app-shell/src/views/useOpenRecordList.drillRecordPage-36256.test.tsx create mode 100644 ui/packages/plugin-dashboard/src/__tests__/DrillDownDialog-36256.test.tsx create mode 100644 ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts create mode 100644 ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartMarkDrill-36256.test.tsx diff --git a/.changeset/36256-drill-dialog-standard-list.md b/.changeset/36256-drill-dialog-standard-list.md new file mode 100644 index 00000000000..59a55c3721b --- /dev/null +++ b/.changeset/36256-drill-dialog-standard-list.md @@ -0,0 +1,17 @@ +--- +'@object-ui/plugin-dashboard': patch +'@object-ui/plugin-report': patch +'@object-ui/react': patch +'@object-ui/app-shell': patch +--- + +feat(plugin-dashboard): a dashboard or report drill opens a centred dialog over the standard list, and a report's chart marks drill + +Clause-②: no +Metadata-protocol: none + +Clicking a number on a dashboard (a chart mark, a metric tile, a table cell) or on a dataset report used to open a full-height side drawer whose table listed every field of the object, with no sort, no filter and no word on which conditions selected the records; a row stacked a second record panel on top. The drill now opens a dialog about 70% wide and 65% tall that dims and blurs nothing behind it, and its body is the standard list the object list page draws (`list-view`): the same row height, column-header sort, filter chips, added columns, record count and column calculations. The drill's conditions (the clicked bucket, the widget's filter, the measure's scope) are the list's own chips and can be changed or removed; a condition no chip can say (a relationship path, an `$or`) still filters the list. The default columns are the record's name, the grouped fields and the measured fields. Nothing done in the dialog is saved, and it writes nothing. A record's name opens the record's full page, whose 「N of M」 stepper walks the drill's rows and whose way back is the dashboard or report; no second panel is stacked. 「Open in list」 is unchanged. On a phone the drill keeps the side drawer, with the same list. + +A dataset report's chart marks now drill too: a bar opens the same records as the summary line it stands for. + +Additive members: `DrillNavigationValue.openRecord` and the `DrillRecordOrigin` type (`@object-ui/react`), `DrillDownDrawerProps.defaultColumns` (`@object-ui/plugin-dashboard`), `DatasetDrillArgs.fields` (`@object-ui/plugin-report`). A renderer without `@object-ui/plugin-list` registered lists the drilled records in the dashboard's data table, whose rows no longer open a record panel. diff --git a/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx b/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx new file mode 100644 index 00000000000..cb5453bb3f5 --- /dev/null +++ b/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx @@ -0,0 +1,104 @@ +/** + * objectstack-ai/objectstack#36256 items 3, 5 and 8 — the drill dialog draws + * the REAL standard list (`@object-ui/plugin-list`'s `list-view`): the + * drill's conditions are the list's own chips, removable; the default + * columns are the record's name and the drilled fields; and nothing the + * reader does in it writes anything — no record write through the data + * source, no request that is not a read, no stored preference. + */ +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import React from 'react'; +import { DrillNavigationProvider, SchemaRendererProvider } from '@object-ui/react'; +import { DrillDownDrawer } from '@object-ui/plugin-dashboard'; +import '@object-ui/plugin-list'; + +const DEFINITION = { + name: 'deal_36256', + label: 'Deal', + nameField: 'name', + fields: { + name: { type: 'text', label: 'Name' }, + stage: { + type: 'select', + label: 'Stage', + options: [ + { value: 'proposal', label: 'Proposal' }, + { value: 'negotiation', label: 'Negotiation' }, + ], + }, + amount: { type: 'number', label: 'Amount' }, + owner: { type: 'text', label: 'Owner' }, + }, +}; + +function mount() { + const ds = { + find: vi.fn().mockResolvedValue({ data: [{ id: 'd1', name: 'Acme', stage: 'negotiation', amount: 3 }], total: 1 }), + findOne: vi.fn(), + create: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + bulk: vi.fn(), + getObjectSchema: vi.fn(async () => structuredClone(DEFINITION)), + }; + const fetchSpy = vi.fn(async () => ({ ok: true, json: async () => ({}) })); + vi.stubGlobal('fetch', fetchSpy); + const setItem = vi.spyOn(Storage.prototype, 'setItem'); + const openRecord = vi.fn(); + render( + + + + + , + ); + return { ds, fetchSpy, setItem, openRecord }; +} + +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); + vi.restoreAllMocks(); +}); + +describe('the drill dialog draws the standard list (#36256)', () => { + it('shows the drill conditions as removable chips, and removing one re-reads without writing', async () => { + const { ds, fetchSpy, setItem } = mount(); + const dialog = await screen.findByTestId('drill-down-dialog'); + const chip = await within(dialog).findByTestId('filter-chip-stage'); + expect(chip).toHaveTextContent('Stage: Negotiation'); + await waitFor(() => expect(ds.find).toHaveBeenCalled()); + const firstQuery = JSON.stringify(ds.find.mock.calls.at(-1)); + expect(firstQuery).toContain('negotiation'); + + const reads = ds.find.mock.calls.length; + await act(async () => fireEvent.click(within(dialog).getByTestId('filter-chip-remove-stage'))); + await waitFor(() => expect(ds.find.mock.calls.length).toBeGreaterThan(reads)); + expect(JSON.stringify(ds.find.mock.calls.at(-1))).not.toContain('negotiation'); + + for (const write of [ds.create, ds.update, ds.delete, ds.bulk]) expect(write).not.toHaveBeenCalled(); + for (const [, init] of fetchSpy.mock.calls as unknown as Array<[unknown, { method?: string } | undefined]>) { + expect((init?.method ?? 'GET').toUpperCase()).toBe('GET'); + } + expect(setItem).not.toHaveBeenCalled(); + }); + + it("leads with the record's name, then the drilled fields", async () => { + mount(); + const dialog = await screen.findByTestId('drill-down-dialog'); + await within(dialog).findByText('Acme'); + const headers = within(dialog).getAllByRole('columnheader').map((h) => h.textContent?.trim()).filter(Boolean); + expect(headers.slice(0, 3)).toEqual(['Name', 'Stage', 'Amount']); + }); +}); diff --git a/ui/packages/app-shell/src/views/useOpenRecordList.drillRecordPage-36256.test.tsx b/ui/packages/app-shell/src/views/useOpenRecordList.drillRecordPage-36256.test.tsx new file mode 100644 index 00000000000..b6a1574f12e --- /dev/null +++ b/ui/packages/app-shell/src/views/useOpenRecordList.drillRecordPage-36256.test.tsx @@ -0,0 +1,57 @@ +/** + * objectstack-ai/objectstack#36256 item 6 — a drilled record's name opens its + * page with the history-state `from` a list hands the page it opens: the + * record page's 「N of M」 stepper walks the drill list's rows, and its way + * back is the dashboard the drill was opened on. Read here through the record + * page's own reader (`useRecordPageReturn`), so the page needs no change. + */ +import { describe, it, expect } from 'vitest'; +import { renderHook, act } from '@testing-library/react'; +import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom'; +import type { ReactNode } from 'react'; +import { FilterScopeProvider } from '@object-ui/react'; +import { useRecordListDrillNavigation } from './useOpenRecordList'; +import { useRecordPageReturn } from './recordDrawerStack'; + +function Wrapper({ children }: { children: ReactNode }) { + return ( + + + + {children}} /> + + + + ); +} + +function useHarness() { + const nav = useRecordListDrillNavigation('Executive Overview'); + const location = useLocation(); + const recordId = location.pathname.match(/\/record\/([^/]+)$/)?.[1]; + const pageReturn = useRecordPageReturn(recordId); + return { nav, location, pageReturn }; +} + +describe('a drilled record opens its page with the drill list as its set (#36256)', () => { + it('pages through the drill rows and returns to the dashboard', () => { + const { result } = renderHook(useHarness, { wrapper: Wrapper }); + act(() => result.current.nav.openRecord('crm_opportunity', 'o2', { siblings: ['o1', 'o2', 'o3'], total: 3 })); + + expect(result.current.location.pathname).toBe('/apps/crm/crm_opportunity/record/o2'); + expect((result.current.location.state as any).from).toEqual({ + pathname: '/apps/crm/dashboard/executive?tab=1', + label: 'Executive Overview', + siblings: ['o1', 'o2', 'o3'], + total: 3, + }); + expect(result.current.pageReturn.stepper?.position).toEqual({ index: 1, total: 3 }); + + act(() => result.current.pageReturn.stepper!.onNext!()); + expect(result.current.location.pathname).toBe('/apps/crm/crm_opportunity/record/o3'); + expect(result.current.pageReturn.stepper?.position).toEqual({ index: 2, total: 3 }); + + act(() => result.current.pageReturn.toList!()); + expect(result.current.location.pathname + result.current.location.search).toBe('/apps/crm/dashboard/executive?tab=1'); + }); +}); diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx index 2441ca7450e..9ba206a0344 100644 --- a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -34,9 +34,9 @@ import { drillListConditions } from './drillConditions'; /** The registry key of the standard list (`@object-ui/plugin-list`). */ export const DRILL_LIST_COMPONENT = 'list-view'; -/** Whether the standard list is registered in this renderer. */ +/** Whether the standard list is registered in this renderer, loaded or lazily (the Console registers it lazily). */ export function drillListAvailable(): boolean { - return !!ComponentRegistry.get(DRILL_LIST_COMPONENT); + return ComponentRegistry.has(DRILL_LIST_COMPONENT) || ComponentRegistry.hasLazy(DRILL_LIST_COMPONENT); } export interface DrillRecordListProps { @@ -118,8 +118,9 @@ export const DrillRecordList: React.FC = ({ ); const schema = { type: DRILL_LIST_COMPONENT, - objectName, - viewType: 'grid', + // The page node's binding (`PageComponentSchema.dataSource`): the block + // lands its `object` on the list's `objectName`. The default kind is the grid. + dataSource: { object: objectName }, ...(conditions.rest ? { filter: conditions.rest } : {}), // An empty list lets the list pick its own columns (no name field known). ...(listColumns.length > 0 ? { columns: listColumns } : {}), diff --git a/ui/packages/plugin-dashboard/src/__tests__/DrillDownDialog-36256.test.tsx b/ui/packages/plugin-dashboard/src/__tests__/DrillDownDialog-36256.test.tsx new file mode 100644 index 00000000000..4944dd5b6f1 --- /dev/null +++ b/ui/packages/plugin-dashboard/src/__tests__/DrillDownDialog-36256.test.tsx @@ -0,0 +1,129 @@ +/** + * objectstack-ai/objectstack#36256 — the drill opens a centred, non-modal + * dialog whose body is the standard list (`list-view`), with the drill's + * conditions as the list's own chips, the record's name and the drilled + * fields as its default columns, a read-only toolbar, and the record's name + * opening its page through the host with the shown rows as its ↑ ↓ set. No + * record panel is stacked over the drill. + * + * The registered `list-view` here is a stub that records the props it is + * handed: what the real list does with them is pinned in app-shell + * (`drillDialogStandardList-36256.test.tsx`). + */ +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import React from 'react'; +import { ComponentRegistry } from '@object-ui/core'; +import { DrillNavigationProvider } from '@object-ui/react'; +import '@object-ui/components'; +import { DrillDownDrawer } from '../DrillDownDrawer'; + +let listProps: Record | null = null; +const StubList = (props: Record) => { + listProps = props; + return ( + + ); +}; + +const dataSource = { + find: vi.fn(async () => ({ data: [] })), + getObjectSchema: vi.fn(async () => ({ name: 'opportunity', nameField: 'name', fields: { name: { type: 'text' } } })), +}; + +function renderDialog(props: Record = {}, openRecord = vi.fn()) { + const onClose = props.onClose ?? vi.fn(); + render( + + + , + ); + return { onClose, openRecord }; +} + +describe('drill dialog over the standard list (#36256)', () => { + beforeEach(() => { + listProps = null; + ComponentRegistry.register('list-view', StubList as any); + }); + afterEach(() => { + ComponentRegistry.unregister('list-view'); + }); + + it('is a centred dialog with no overlay behind it', async () => { + renderDialog(); + const dialog = await screen.findByTestId('drill-down-dialog'); + expect(dialog).toHaveAttribute('role', 'dialog'); + expect(dialog.className).toContain('w-[70vw]'); + expect(dialog.className).toContain('h-[65vh]'); + // Radix draws its overlay only for a modal dialog. + expect(document.querySelector('[data-state="open"].fixed.inset-0')).toBeNull(); + }); + + it('mounts the standard list read-only, with the drill conditions as chips and the drilled fields as columns', async () => { + renderDialog(); + await waitFor(() => expect(listProps).not.toBeNull()); + const { schema, initialFilters, showViewSwitcher } = listProps!; + expect(schema).toMatchObject({ + type: 'list-view', + dataSource: { object: 'opportunity' }, + columns: ['name', 'industry', 'amount'], + userActions: { editInline: false, addRecordForm: false }, + }); + expect(schema.filter).toBeUndefined(); + expect(initialFilters.conditions.map((c: any) => [c.field, c.operator, c.value])).toEqual([ + ['stage', 'equals', 'closed_won'], + ['industry', 'equals', 'tech'], + ['amount', 'is_not_null', undefined], + ]); + expect(showViewSwitcher).toBe(false); + for (const door of ['onSaveView', 'onAddRecord', 'onBulkAction', 'onEdit', 'onDelete', 'onSortChange', 'onFilterChange']) { + expect(listProps![door]).toBeUndefined(); + } + }); + + it("an added column and a picked calculation stay in the dialog's own state", async () => { + renderDialog(); + await waitFor(() => expect(listProps).not.toBeNull()); + React.act(() => listProps!.onAddedFieldsChange(['owner_id'])); + React.act(() => { listProps!.onColumnSummaryPick('amount', 'sum'); }); + expect(listProps!.schema.columns).toEqual(['name', 'industry', { field: 'amount', summary: 'sum' }, 'owner_id']); + }); + + it("the record's name opens its page with the shown rows, and closes the drill", async () => { + const { onClose, openRecord } = renderDialog(); + fireEvent.click(await screen.findByTestId('stub-row')); + expect(openRecord).toHaveBeenCalledWith('opportunity', 'o2', { siblings: ['o1', 'o2', 'o3'], total: 3 }); + expect(onClose).toHaveBeenCalled(); + }); + + it('keeps the side drawer and the same list when target is drawer', async () => { + renderDialog({ target: 'drawer' }); + await waitFor(() => expect(listProps).not.toBeNull()); + expect(screen.queryByTestId('drill-down-dialog')).toBeNull(); + }); +}); + +describe('drill dialog without the standard list registered (#36256)', () => { + it('lists the records in the data table and stacks no record panel on a row', async () => { + renderDialog(); + expect(await screen.findByTestId('drill-down-dialog')).toBeInTheDocument(); + expect(screen.queryByTestId('stub-row')).toBeNull(); + expect(document.querySelectorAll('[role="dialog"]')).toHaveLength(1); + }); +}); diff --git a/ui/packages/plugin-dashboard/src/__tests__/DrillDownDrawer.chain.test.tsx b/ui/packages/plugin-dashboard/src/__tests__/DrillDownDrawer.chain.test.tsx index cd276e12744..6ce9fb53a88 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/DrillDownDrawer.chain.test.tsx +++ b/ui/packages/plugin-dashboard/src/__tests__/DrillDownDrawer.chain.test.tsx @@ -2,9 +2,10 @@ * ObjectUI * Copyright (c) 2024-present ObjectStack Inc. * - * Verifies the drill chain completes through DrillDownDrawer: the filtered - * record list it renders (for pivot / dataset / chart drill-through) is itself - * drill-to-record, so clicking a row opens that record. + * The drill list stacks no record panel over the drill + * (objectstack-ai/objectstack#36256 item 6): a record opens as its page from + * the standard list's record name. Without the standard list registered, the + * data-table fallback lists the records and its rows open nothing. */ import { describe, it, expect, vi } from 'vitest'; import { render, screen, waitFor } from '@testing-library/react'; @@ -31,8 +32,8 @@ function makeDataSource() { }; } -describe('DrillDownDrawer — completes the drill chain to a record', () => { - it('wires record drill on the filtered drill list (chain completion)', async () => { +describe('DrillDownDrawer — no record panel stacked over the drill', () => { + it('the data-table fallback rows open no record drawer', async () => { render( { // The drill-through list renders the underlying records. await waitFor(() => expect(screen.getByText('Acme Renewal')).toBeInTheDocument()); - // Its rows are drill-to-record: the data-table marks clickable rows with - // `cursor-pointer` only when an onRowClick is wired, which ObjectDataTable - // does only when record drill is enabled. (The record drawer opening on - // click is covered by ObjectDataTable.drill.test.) + // The data-table marks clickable rows with `cursor-pointer` only when an + // onRowClick is wired, which ObjectDataTable does only when record drill + // is enabled — and the drill list no longer enables it. const row = screen.getByText('Acme Renewal').closest('tr') as HTMLElement; - expect(row.className).toContain('cursor-pointer'); + expect(row.className).not.toContain('cursor-pointer'); }); }); diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts new file mode 100644 index 00000000000..ceb4104d37d --- /dev/null +++ b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts @@ -0,0 +1,49 @@ +/** + * objectstack-ai/objectstack#36256 item 3 — a drill's conditions become the + * standard list's own chips where a chip can say them, and stay its base + * filter where none can. + */ +import { describe, it, expect } from 'vitest'; +import { drillListConditions, measuredFieldsOf } from '../drillConditions'; + +const rows = (filter: Record) => + drillListConditions(filter).chips.conditions.map(({ field, operator, value }) => ({ field, operator, value })); + +describe('drillListConditions', () => { + it('reads each field compared with a value as one chip row, through $and', () => { + expect(rows({ + $and: [ + { stage: 'closed_won', close_date: { $gte: '2026-01-01', $lt: '2026-04-01' } }, + { lead_source: { $in: ['web', 'referral'] }, amount: { $null: false } }, + ], + })).toEqual([ + { field: 'stage', operator: 'equals', value: 'closed_won' }, + { field: 'close_date', operator: 'greater_than_or_equal', value: '2026-01-01' }, + { field: 'close_date', operator: 'less_than', value: '2026-04-01' }, + { field: 'lead_source', operator: 'in', value: ['web', 'referral'] }, + { field: 'amount', operator: 'is_not_null', value: undefined }, + ]); + }); + + it('keeps what no chip can say as the base filter, ANDed', () => { + const { chips, rest } = drillListConditions({ + stage: { $ne: 'closed_lost' }, + account: { industry: 'tech' }, + $or: [{ a: 1 }, { b: 2 }], + owner: { $regex: 'x' }, + }); + expect(chips.conditions.map((c) => c.operator)).toEqual(['not_equals']); + expect(rest).toEqual({ $and: [{ account: { industry: 'tech' } }, { $or: [{ a: 1 }, { b: 2 }] }, { owner: { $regex: 'x' } }] }); + }); + + it('answers no rows and no rest for no filter', () => { + expect(drillListConditions(undefined)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: undefined }); + }); +}); + +describe('measuredFieldsOf', () => { + it('names the fields a measure scope says hold a value', () => { + expect(measuredFieldsOf({ $and: [{ stage: 'won' }, { amount: { $null: false } }] })).toEqual(['amount']); + expect(measuredFieldsOf({})).toEqual([]); + }); +}); diff --git a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartMarkDrill-36256.test.tsx b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartMarkDrill-36256.test.tsx new file mode 100644 index 00000000000..0acfea41f17 --- /dev/null +++ b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartMarkDrill-36256.test.tsx @@ -0,0 +1,73 @@ +/** + * objectstack-ai/objectstack#36256 item 2 — a report's chart mark drills, and + * a bar opens the same records as the summary line it stands for: both go + * through one drill builder, with the same object filter and the same default + * fields (the grouped field and the measured one). + */ +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen, fireEvent, waitFor, cleanup, act } from '@testing-library/react'; +import { ComponentRegistry } from '@object-ui/core'; +import { DatasetReportRenderer } from '../DatasetReportRenderer'; + +let chartProps: Record | null = null; + +function makeSource() { + return { + queryDataset: vi.fn(async () => ({ + rows: [{ stage: 'Negotiation', total_amount: 30 }, { stage: 'Prospecting', total_amount: 10 }], + object: 'opportunity', + dimensionFields: { stage: 'stage' }, + drillRawRows: [{ stage: 'negotiation' }, { stage: 'prospecting' }], + drillScopes: { total_amount: { amount: { $null: false } } }, + })), + }; +} + +beforeEach(() => { + chartProps = null; + vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, json: async () => ({}) }))); + ComponentRegistry.register('chart', (props: any) => { + chartProps = props; + return null; + }); +}); +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); + vi.restoreAllMocks(); +}); + +const report = { + name: 'opps_by_stage', + type: 'summary', + dataset: 'opportunity_metrics', + rows: ['stage'], + values: ['total_amount'], + chart: { type: 'bar', xAxis: 'stage', yAxis: 'total_amount' }, +}; + +describe('a report chart mark drills like its table line (#36256)', () => { + it('emits the same drill for the bar and the summary line', async () => { + const onDrill = vi.fn(); + render(); + await waitFor(() => expect(chartProps?.onChartClick).toBeTypeOf('function')); + act(() => chartProps!.onChartClick({ category: 'Negotiation', series: 'total_amount' })); + + const rows = await screen.findAllByTestId('dataset-drill-row'); + fireEvent.click(rows.find((r) => r.textContent?.includes('Negotiation'))!); + + expect(onDrill).toHaveBeenCalledTimes(2); + const [bar, line] = onDrill.mock.calls.map((c) => c[0]); + expect(bar.object).toBe('opportunity'); + expect(bar.objectFilter).toEqual(line.objectFilter); + expect(JSON.stringify(bar.objectFilter)).toContain('negotiation'); + expect(bar.fields).toEqual(['stage', 'amount']); + expect(line.fields).toEqual(bar.fields); + }); + + it('offers no click when the report turns drill off', async () => { + render(); + await waitFor(() => expect(chartProps).not.toBeNull()); + expect(chartProps!.onChartClick).toBeUndefined(); + }); +}); From 65b1a666207f48e17df1d32d5ff1f23716a88a91 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 11:44:22 +0000 Subject: [PATCH 03/15] fix(plugin-dashboard): one chip for a drill condition stated twice; the report drill names its fields only when it has some Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../src/__tests__/drillConditions-36256.test.ts | 9 +++++++++ .../plugin-dashboard/src/drillConditions.ts | 15 +++++++++++++-- .../plugin-report/src/DatasetReportRenderer.tsx | 4 ++-- ...ReportRenderer.summarySubtotals-27975.test.tsx | 2 ++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts index ceb4104d37d..d4a763a2444 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts +++ b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts @@ -36,6 +36,15 @@ describe('drillListConditions', () => { expect(rest).toEqual({ $and: [{ account: { industry: 'tech' } }, { $or: [{ a: 1 }, { b: 2 }] }, { owner: { $regex: 'x' } }] }); }); + it('draws a condition stated twice as one chip', () => { + expect(rows({ + $and: [{ close_date: { $gte: '2026-10-01' } }, { close_date: { $gte: '2026-10-01', $lt: '2027-01-01' } }], + })).toEqual([ + { field: 'close_date', operator: 'greater_than_or_equal', value: '2026-10-01' }, + { field: 'close_date', operator: 'less_than', value: '2027-01-01' }, + ]); + }); + it('answers no rows and no rest for no filter', () => { expect(drillListConditions(undefined)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: undefined }); }); diff --git a/ui/packages/plugin-dashboard/src/drillConditions.ts b/ui/packages/plugin-dashboard/src/drillConditions.ts index f1d1391d311..c0fcd9a49ec 100644 --- a/ui/packages/plugin-dashboard/src/drillConditions.ts +++ b/ui/packages/plugin-dashboard/src/drillConditions.ts @@ -95,11 +95,22 @@ export interface DrillListConditions { export function drillListConditions(filter: Record | undefined): DrillListConditions { const conditions: FilterBuilderRow[] = []; const rest: Record[] = []; + const seen = new Set(); for (const part of andParts(filter)) { const [field, condition] = Object.entries(part)[0]; const rows = rowsOf(field, condition); - if (rows) rows.forEach((row) => conditions.push({ ...row, id: `drill-${conditions.length}` })); - else rest.push(part); + if (!rows) { + rest.push(part); + continue; + } + // A condition stated twice (the widget filter's range and the clicked + // bucket's) ANDs to itself: one chip says it. + for (const row of rows) { + const key = JSON.stringify([row.field, row.operator, row.value]); + if (seen.has(key)) continue; + seen.add(key); + conditions.push({ ...row, id: `drill-${conditions.length}` }); + } } return { chips: { logic: 'and', conditions }, diff --git a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx index 0626344f0c2..e35d924e0f2 100644 --- a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx +++ b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx @@ -969,7 +969,7 @@ function emitBucketDrill({ if (state.object && datasetDrillHasRelationshipPath(drillDims, state.dimensionFields)) { const object = state.object; resolveRelationshipDrill(object, scope, rawRow, drillDims, state.dimensionFields ?? {}, runtimeFilter, rowRanges, dataSource, (resolved) => - onDrill({ dataset, groupKey, runtimeFilter, object, objectFilter: resolved, fields })); + onDrill({ dataset, groupKey, runtimeFilter, object, objectFilter: resolved, ...(fields.length ? { fields } : {}) })); return; } let objectFilter: Record | undefined; @@ -983,7 +983,7 @@ function emitBucketDrill({ // fallback rebuilds the list from the bucket ALONE: no drill. return; } - onDrill({ dataset, groupKey, runtimeFilter, object: state.object, objectFilter, fields }); + onDrill({ dataset, groupKey, runtimeFilter, object: state.object, objectFilter, ...(fields.length ? { fields } : {}) }); } /** diff --git a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.summarySubtotals-27975.test.tsx b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.summarySubtotals-27975.test.tsx index fa3244b08ba..122ad286737 100644 --- a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.summarySubtotals-27975.test.tsx +++ b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.summarySubtotals-27975.test.tsx @@ -296,6 +296,8 @@ describe('summary report subtotals (objectstack-ai/objectstack#27975)', () => { runtimeFilter: undefined, object: 'opportunity', objectFilter: { owner_id: 'usr_amy' }, + // objectstack-ai/objectstack#36256 — the grouped field the drill list shows. + fields: ['owner_id'], }); }); From 132cb18ab3809a97e0165e69a613a3a99eef84d2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 12:09:01 +0000 Subject: [PATCH 04/15] fix(plugin-dashboard): a drilled date bound reads as the list's date filter words it The dashboard's drill wiring moves next to the dashboard read, clear of the in-page edit work on the same view. Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../app-shell/src/views/DashboardView.tsx | 12 ++++---- .../plugin-dashboard/src/DrillRecordList.tsx | 29 +++++++++++++------ .../__tests__/drillConditions-36256.test.ts | 12 ++++++++ .../plugin-dashboard/src/drillConditions.ts | 25 ++++++++++++++-- 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/ui/packages/app-shell/src/views/DashboardView.tsx b/ui/packages/app-shell/src/views/DashboardView.tsx index 9ad4389217b..ce008efc504 100644 --- a/ui/packages/app-shell/src/views/DashboardView.tsx +++ b/ui/packages/app-shell/src/views/DashboardView.tsx @@ -213,6 +213,12 @@ export function DashboardView({ dataSource }: { dataSource?: any }) { const missedName = !dashboard && dashboardsSettled && !previewDrafts && dashboardName ? dashboardName : null; const access = useMetaItemRefusal('dashboard', missedName); + // Drill navigation: the drill list's 「Open in list」 and its record pages, + // which name this dashboard as their way back (objectstack-ai/objectstack#36256). + const drillNavigation = useRecordListDrillNavigation( + dashboard ? resolveKeyedI18nLabel(dashboard.label, t) || dashboard.name : undefined, + ); + // ---- Runtime capability gate -------------------------------------------- // Hide widgets whose `requiresObject` is not registered (mirrors // NavigationItem.requiresObject for nav entries). Defaults to widget.object @@ -252,12 +258,6 @@ export function DashboardView({ dataSource }: { dataSource?: any }) { return { ...dashboard, widgets: filtered }; }, [dashboard, unregistered]); - // Drill navigation: the drill list's 「Open in list」 and its record pages, - // which name this dashboard as their way back (objectstack-ai/objectstack#36256). - const drillNavigation = useRecordListDrillNavigation( - dashboard ? resolveKeyedI18nLabel(dashboard.label, t) || dashboard.name : undefined, - ); - // ---- Loading / not-found guards ----------------------------------------- if (isLoading) { return ; diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx index 9ba206a0344..c9444c9f210 100644 --- a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -28,6 +28,7 @@ import React from 'react'; import { ComponentRegistry, resolveFilterPlaceholders, resolveNameField } from '@object-ui/core'; import { SchemaRenderer, SchemaRendererContext, useDrillNavigation, useFilterScope } from '@object-ui/react'; +import { FILTER_DATE_LIKE_TYPES } from '@object-ui/types'; import { Loader2 } from 'lucide-react'; import { drillListConditions } from './drillConditions'; @@ -56,6 +57,9 @@ export interface DrillRecordListProps { type Summary = string | Record; +/** The types the list's filter draws as dates (its own set). */ +const DATE_TYPES: ReadonlySet = new Set(FILTER_DATE_LIKE_TYPES); + const rowId = (row: Record): string | undefined => { const id = row?.id ?? row?._id; return id == null || id === '' ? undefined : String(id); @@ -75,25 +79,32 @@ export const DrillRecordList: React.FC = ({ const { openRecord } = useDrillNavigation(); const scope = useFilterScope(); // One resolution per mount: a chip shows the value the query compares. - const conditions = React.useMemo( - () => drillListConditions(resolveFilterPlaceholders(filter, scope) as Record | undefined), + const resolved = React.useMemo( + () => resolveFilterPlaceholders(filter, scope) as Record | undefined, // The drill's filter is fixed for the life of this mount (the dialog keys it). // eslint-disable-next-line react-hooks/exhaustive-deps [], ); - // The object's name field leads the default columns, as on the list page. - const [nameField, setNameField] = React.useState( - columns?.length || typeof dataSource?.getObjectSchema !== 'function' ? null : undefined, + // The object's definition: its name field leads the default columns, as on + // the list page, and its date fields word their bounds as the list does. + const [definition, setDefinition] = React.useState( + typeof dataSource?.getObjectSchema !== 'function' ? null : undefined, ); React.useEffect(() => { - if (nameField !== undefined) return; + if (definition !== undefined) return; let live = true; Promise.resolve(dataSource.getObjectSchema(objectName)) - .then((def: unknown) => { if (live) setNameField(resolveNameField(def) ?? null); }) - .catch(() => { if (live) setNameField(null); }); + .then((def: unknown) => { if (live) setDefinition(def ?? null); }) + .catch(() => { if (live) setDefinition(null); }); return () => { live = false; }; - }, [dataSource, objectName, nameField]); + }, [dataSource, objectName, definition]); + const nameField = definition === undefined ? undefined : columns?.length ? null : resolveNameField(definition) ?? null; + const conditions = React.useMemo(() => { + const fields = (definition as { fields?: Record } | null)?.fields ?? {}; + const dateFields = new Set(Object.keys(fields).filter((f) => DATE_TYPES.has(fields[f]?.type ?? ''))); + return drillListConditions(resolved, { dateFields }); + }, [definition, resolved]); const [added, setAdded] = React.useState([]); const [summaries, setSummaries] = React.useState>({}); diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts index d4a763a2444..c0c2471a046 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts +++ b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts @@ -45,6 +45,18 @@ describe('drillListConditions', () => { ]); }); + it("words a date field's open bounds as the list's date filter does", () => { + const { chips } = drillListConditions( + { close_date: { $gt: '2026-09-30', $lt: '2027-01-01' }, amount: { $lt: 5 } }, + { dateFields: new Set(['close_date']) }, + ); + expect(chips.conditions.map((c) => [c.field, c.operator])).toEqual([ + ['close_date', 'after'], + ['close_date', 'before'], + ['amount', 'less_than'], + ]); + }); + it('answers no rows and no rest for no filter', () => { expect(drillListConditions(undefined)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: undefined }); }); diff --git a/ui/packages/plugin-dashboard/src/drillConditions.ts b/ui/packages/plugin-dashboard/src/drillConditions.ts index c0fcd9a49ec..48fe63bc037 100644 --- a/ui/packages/plugin-dashboard/src/drillConditions.ts +++ b/ui/packages/plugin-dashboard/src/drillConditions.ts @@ -91,8 +91,27 @@ export interface DrillListConditions { rest: Record | undefined; } +/** + * The words the list's chips give a date bound: `before` / `after` lower to + * the same `<` / `>` as `less_than` / `greater_than`, and are the operators + * the list's date filter draws, so a half-open date bucket reads 「before + * 2027-01-01」, not an operator id. + */ +const DATE_ROW_OPERATOR: Readonly> = { + less_than: 'before', + greater_than: 'after', +}; + +export interface DrillListConditionOptions { + /** The fields that hold a date or a date-time (read from the object's definition). */ + dateFields?: ReadonlySet; +} + /** Split a resolved drill filter into chip rows and the rest (see the file header). */ -export function drillListConditions(filter: Record | undefined): DrillListConditions { +export function drillListConditions( + filter: Record | undefined, + { dateFields }: DrillListConditionOptions = {}, +): DrillListConditions { const conditions: FilterBuilderRow[] = []; const rest: Record[] = []; const seen = new Set(); @@ -105,7 +124,9 @@ export function drillListConditions(filter: Record | undefined) } // A condition stated twice (the widget filter's range and the clicked // bucket's) ANDs to itself: one chip says it. - for (const row of rows) { + for (const stated of rows) { + const dated = dateFields?.has(stated.field) ? DATE_ROW_OPERATOR[stated.operator] : undefined; + const row = dated ? { ...stated, operator: dated } : stated; const key = JSON.stringify([row.field, row.operator, row.value]); if (seen.has(key)) continue; seen.add(key); From 546668be7452a0626e73bd419666e0ccd3aa2545 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 12:40:46 +0000 Subject: [PATCH 05/15] =?UTF-8?q?chore(changeset):=20the=20drill=20dialog?= =?UTF-8?q?=20changeset=20declares=20Clause-=E2=91=A1=20yes=20(widening),?= =?UTF-8?q?=20as=20amended?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .changeset/36256-drill-dialog-standard-list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/36256-drill-dialog-standard-list.md b/.changeset/36256-drill-dialog-standard-list.md index 59a55c3721b..c7391b8ed37 100644 --- a/.changeset/36256-drill-dialog-standard-list.md +++ b/.changeset/36256-drill-dialog-standard-list.md @@ -7,7 +7,7 @@ feat(plugin-dashboard): a dashboard or report drill opens a centred dialog over the standard list, and a report's chart marks drill -Clause-②: no +Clause-②: yes (widening) Metadata-protocol: none Clicking a number on a dashboard (a chart mark, a metric tile, a table cell) or on a dataset report used to open a full-height side drawer whose table listed every field of the object, with no sort, no filter and no word on which conditions selected the records; a row stacked a second record panel on top. The drill now opens a dialog about 70% wide and 65% tall that dims and blurs nothing behind it, and its body is the standard list the object list page draws (`list-view`): the same row height, column-header sort, filter chips, added columns, record count and column calculations. The drill's conditions (the clicked bucket, the widget's filter, the measure's scope) are the list's own chips and can be changed or removed; a condition no chip can say (a relationship path, an `$or`) still filters the list. The default columns are the record's name, the grouped fields and the measured fields. Nothing done in the dialog is saved, and it writes nothing. A record's name opens the record's full page, whose 「N of M」 stepper walks the drill's rows and whose way back is the dashboard or report; no second panel is stacked. 「Open in list」 is unchanged. On a phone the drill keeps the side drawer, with the same list. From f8140a7d406461d59a527f75a4a48a02cbe8e436 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 12:53:31 +0000 Subject: [PATCH 06/15] fix(plugin-dashboard): the drill chip split names no spec-owned type, and its dialog test writes nothing outside the stub during render Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../__tests__/DrillDownDialog-36256.test.tsx | 25 +++++++++++-------- .../plugin-dashboard/src/drillConditions.ts | 5 ++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ui/packages/plugin-dashboard/src/__tests__/DrillDownDialog-36256.test.tsx b/ui/packages/plugin-dashboard/src/__tests__/DrillDownDialog-36256.test.tsx index 4944dd5b6f1..01fd5130ea2 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/DrillDownDialog-36256.test.tsx +++ b/ui/packages/plugin-dashboard/src/__tests__/DrillDownDialog-36256.test.tsx @@ -19,9 +19,12 @@ import { DrillNavigationProvider } from '@object-ui/react'; import '@object-ui/components'; import { DrillDownDrawer } from '../DrillDownDrawer'; -let listProps: Record | null = null; +// The props each render handed the stub, read back through the spy: a +// component writes nothing outside itself during render. +const seenProps = vi.fn(); +const lastProps = (): Record | null => seenProps.mock.calls.at(-1)?.[0] ?? null; const StubList = (props: Record) => { - listProps = props; + seenProps(props); return ( +); + +afterEach(() => { + cleanup(); + ComponentRegistry.unregister('list-view'); +}); + +const adapter = () => ({ + aggregate: vi.fn(async () => [{ amount_sum: 120 }]), + find: vi.fn(async () => ({ data: [{ id: '1', name: 'Acme Renewal' }] })), + getObjectSchema: vi.fn(async () => ({ name: 'deal', nameField: 'name', fields: { name: { type: 'text', label: 'Name' } } })), +}); + +const mount = () => + render( + + + , + ); + +describe('a page block with no record page opens the drilled record in a dialog (#36256)', () => { + it('from the standard list', async () => { + ComponentRegistry.register('list-view', StubList as any); + mount(); + fireEvent.click(await screen.findByRole('button', { name: /revenue|120/i })); + fireEvent.click(await screen.findByTestId('stub-row')); + const body = await screen.findByTestId('record-detail-body'); + expect(within(body).getByText('Acme Renewal')).toBeTruthy(); + expect(body.closest('[role="dialog"]')).not.toBeNull(); + }); + + it('from the data table when no list is registered', async () => { + mount(); + fireEvent.click(await screen.findByRole('button', { name: /revenue|120/i })); + fireEvent.click(await screen.findByText('Acme Renewal')); + const body = await screen.findByTestId('record-detail-body'); + expect(within(body).getByText('Acme Renewal')).toBeTruthy(); + expect(body.closest('[role="dialog"]')).not.toBeNull(); + }); +}); diff --git a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx index e35d924e0f2..d19f4188c5c 100644 --- a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx +++ b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx @@ -962,7 +962,8 @@ function emitBucketDrill({ }): void { const hasRange = !!rowRanges && Object.keys(rowRanges).length > 0; const fields = Array.from(new Set([ - ...drillDims.map((d) => state.dimensionFields?.[d]).filter((f): f is string => !!f && !f.includes('.')), + // A relationship path shows its lookup field: the list draws no dotted column. + ...drillDims.map((d) => state.dimensionFields?.[d]).filter((f): f is string => !!f).map((f) => f.split('.')[0]), ...Object.values(rowRanges ?? {}).map((range) => range.field), ...measuredFieldsOf(scope), ])); diff --git a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartMarkDrill-36256.test.tsx b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartMarkDrill-36256.test.tsx index 0acfea41f17..6ea75537227 100644 --- a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartMarkDrill-36256.test.tsx +++ b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartMarkDrill-36256.test.tsx @@ -65,6 +65,29 @@ describe('a report chart mark drills like its table line (#36256)', () => { expect(line.fields).toEqual(bar.fields); }); + it("a relationship-path bucket drills on the nested condition with its lookup field as the column", async () => { + const onDrill = vi.fn(); + const pathSource = { + queryDataset: vi.fn(async () => ({ + rows: [{ industry: 'Technology', total_amount: 30 }], + object: 'opportunity', + dimensionFields: { industry: 'crm_account.industry' }, + drillRawRows: [{ industry: 'technology' }], + drillScopes: { total_amount: { amount: { $null: false } } }, + })), + find: vi.fn(async () => ({ data: [] })), + getObjectSchema: vi.fn(async (object: string) => (object === 'opportunity' + ? { fields: { crm_account: { type: 'lookup', reference: 'crm_account' }, amount: { type: 'currency' } } } + : { fields: { industry: { type: 'select' } } })), + }; + render(); + fireEvent.click(await screen.findByTestId('dataset-drill-row')); + await waitFor(() => expect(onDrill).toHaveBeenCalled()); + const [args] = onDrill.mock.calls[0]; + expect(JSON.stringify(args.objectFilter)).toContain('{"crm_account":{"industry":"technology"}}'); + expect(args.fields).toEqual(['crm_account', 'amount']); + }); + it('offers no click when the report turns drill off', async () => { render(); await waitFor(() => expect(chartProps).not.toBeNull()); From 5af2f6e3af23273bcdcc47296ae981eebe4767b1 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 16:08:04 +0000 Subject: [PATCH 09/15] test(plugin-dashboard): split the drill chain pin by host kind A host that offers a record page keeps the data-table rows inert; a host with none (a page block) keeps them drill-to-record. Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../__tests__/DrillDownDrawer.chain.test.tsx | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/ui/packages/plugin-dashboard/src/__tests__/DrillDownDrawer.chain.test.tsx b/ui/packages/plugin-dashboard/src/__tests__/DrillDownDrawer.chain.test.tsx index 6ce9fb53a88..b5134f35ae4 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/DrillDownDrawer.chain.test.tsx +++ b/ui/packages/plugin-dashboard/src/__tests__/DrillDownDrawer.chain.test.tsx @@ -5,13 +5,16 @@ * The drill list stacks no record panel over the drill * (objectstack-ai/objectstack#36256 item 6): a record opens as its page from * the standard list's record name. Without the standard list registered, the - * data-table fallback lists the records and its rows open nothing. + * data-table fallback lists the records and, when the host offers a record + * page, its rows open nothing. A host with no record page (a page block) + * keeps the rows drill-to-record, as before. */ import { describe, it, expect, vi } from 'vitest'; import { render, screen, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom'; import React from 'react'; +import { DrillNavigationProvider } from '@object-ui/react'; import { DrillDownDrawer } from '../DrillDownDrawer'; // Registers the renderers at module scope, NOT inside a `beforeAll` — there the // cold transform is billed to `hookTimeout`, which is why this carried a raised @@ -32,26 +35,31 @@ function makeDataSource() { }; } -describe('DrillDownDrawer — no record panel stacked over the drill', () => { - it('the data-table fallback rows open no record drawer', async () => { - render( - , - ); +const drill = () => ( + +); + +/** The data-table marks a row `cursor-pointer` only when an onRowClick is wired. */ +const rowOf = async (name: string) => { + await waitFor(() => expect(screen.getByText(name)).toBeInTheDocument()); + return screen.getByText(name).closest('tr') as HTMLElement; +}; - // The drill-through list renders the underlying records. - await waitFor(() => expect(screen.getByText('Acme Renewal')).toBeInTheDocument()); +describe('DrillDownDrawer — no record panel stacked over the drill', () => { + it('the data-table fallback rows open no record drawer when the host offers a record page', async () => { + render({drill()}); + expect((await rowOf('Acme Renewal')).className).not.toContain('cursor-pointer'); + }); - // The data-table marks clickable rows with `cursor-pointer` only when an - // onRowClick is wired, which ObjectDataTable does only when record drill - // is enabled — and the drill list no longer enables it. - const row = screen.getByText('Acme Renewal').closest('tr') as HTMLElement; - expect(row.className).not.toContain('cursor-pointer'); + it('a host with no record page keeps the rows drill-to-record', async () => { + render(drill()); + expect((await rowOf('Acme Renewal')).className).toContain('cursor-pointer'); }); }); From 6df500004cd61aac87ab366c79af656cbca5157a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 17:30:13 +0000 Subject: [PATCH 10/15] fix(dashboard): the off-page record dialog draws the fields the drill list read A host with no record page opens the drilled record in a dialog. On the standard-list body that dialog now draws the listed fields (the authored drill columns when given), the fields the list's projected read holds, and masks values while the field types are unknown. A range field over a relationship path reduces to its lookup field as a default column. The openRecord jsdoc and the changeset say what an absent openRecord does. Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../36256-drill-dialog-standard-list.md | 2 +- .../plugin-dashboard/src/DatasetWidget.tsx | 2 +- .../plugin-dashboard/src/DrillRecordList.tsx | 12 ++++- ...tricWidget.drillOpensRecord-36256.test.tsx | 47 +++++++++++++++++-- .../src/DatasetReportRenderer.tsx | 2 +- .../src/context/DrillNavigationContext.tsx | 2 +- 6 files changed, 57 insertions(+), 10 deletions(-) diff --git a/.changeset/36256-drill-dialog-standard-list.md b/.changeset/36256-drill-dialog-standard-list.md index c7391b8ed37..42f5be2f999 100644 --- a/.changeset/36256-drill-dialog-standard-list.md +++ b/.changeset/36256-drill-dialog-standard-list.md @@ -14,4 +14,4 @@ Clicking a number on a dashboard (a chart mark, a metric tile, a table cell) or A dataset report's chart marks now drill too: a bar opens the same records as the summary line it stands for. -Additive members: `DrillNavigationValue.openRecord` and the `DrillRecordOrigin` type (`@object-ui/react`), `DrillDownDrawerProps.defaultColumns` (`@object-ui/plugin-dashboard`), `DatasetDrillArgs.fields` (`@object-ui/plugin-report`). A renderer without `@object-ui/plugin-list` registered lists the drilled records in the dashboard's data table, whose rows no longer open a record panel. +Additive members: `DrillNavigationValue.openRecord` and the `DrillRecordOrigin` type (`@object-ui/react`), `DrillDownDrawerProps.defaultColumns` (`@object-ui/plugin-dashboard`), `DatasetDrillArgs.fields` (`@object-ui/plugin-report`). A renderer without `@object-ui/plugin-list` registered lists the drilled records in the dashboard's data table. A host that gives no `openRecord` (a page block's metric or pivot) opens the drilled record in a dialog, from either body. diff --git a/ui/packages/plugin-dashboard/src/DatasetWidget.tsx b/ui/packages/plugin-dashboard/src/DatasetWidget.tsx index 3b6106fc7ed..cf7366307c5 100644 --- a/ui/packages/plugin-dashboard/src/DatasetWidget.tsx +++ b/ui/packages/plugin-dashboard/src/DatasetWidget.tsx @@ -1503,7 +1503,7 @@ export function DatasetWidget({ widget, dataSource, heading, onForbidden, packag // list draws no dotted column. const columns = Array.from(new Set([ ...drillDims.map((d) => dimensionFields?.[d]).filter((f): f is string => !!f).map((f) => f.split('.')[0]), - ...Object.values(drillRanges?.[index] ?? {}).map((range) => range.field), + ...Object.values(drillRanges?.[index] ?? {}).map((range) => range.field.split('.')[0]), ...measuredFieldsOf(scope), ])); const request = ++drillRequest.current; diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx index 7063d79d68b..be60bb12934 100644 --- a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -23,7 +23,9 @@ * (`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 - * mounts no navigation) opens the record in a dialog, as it did before. + * 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. */ import React from 'react'; @@ -127,7 +129,8 @@ export const DrillRecordList: React.FC = ({ ); } - const listColumns = [...baseColumns, ...added.filter((f) => !baseColumns.includes(f))].map((field) => + const listedFields = [...baseColumns, ...added.filter((f) => !baseColumns.includes(f))]; + const listColumns = listedFields.map((field) => summaries[field] ? { field, summary: summaries[field] } : field, ); const schema = { @@ -178,6 +181,11 @@ export const DrillRecordList: React.FC = ({ record={opened} objectName={objectName} objectSchema={definition ?? undefined} + // The fields the list read; with none listed, the list picks its own + // and reads the whole record. + fields={listedFields.length > 0 ? listedFields : undefined} + // Values stay masked while the field types are unknown (objectui#10657). + objectTypesPending={typeof dataSource?.getObjectSchema === 'function' && !(definition as { fields?: unknown } | null | undefined)?.fields} target="dialog" onClose={() => setOpened(null)} /> diff --git a/ui/packages/plugin-dashboard/src/__tests__/ObjectMetricWidget.drillOpensRecord-36256.test.tsx b/ui/packages/plugin-dashboard/src/__tests__/ObjectMetricWidget.drillOpensRecord-36256.test.tsx index 1f9eab8644f..a6d17439840 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/ObjectMetricWidget.drillOpensRecord-36256.test.tsx +++ b/ui/packages/plugin-dashboard/src/__tests__/ObjectMetricWidget.drillOpensRecord-36256.test.tsx @@ -7,9 +7,13 @@ * * Both drill bodies are covered: the standard list (`list-view`, a stub here * that clicks a row) and the data table used when no list is registered. + * + * The standard list reads only the fields it lists (`$select`), so the row it + * hands back holds only those. The dialog draws exactly those fields, each + * with its value: a field the list did not read is not drawn as empty. */ import { describe, it, expect, vi, afterEach } from 'vitest'; -import { render, screen, cleanup, fireEvent, within } from '@testing-library/react'; +import { render, screen, cleanup, fireEvent, within, waitFor } from '@testing-library/react'; import { ComponentRegistry } from '@object-ui/core'; import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react'; import '../index'; @@ -20,6 +24,16 @@ const StubList = (props: Record) => ( ); +/** The record as stored: more fields than the drill lists. */ +const DEAL = { id: '1', name: 'Acme Renewal', stage: 'won', amount: 120, owner: 'Dana', description: 'Three-year renewal' }; + +/** Answers with the record projected to the listed columns, as the list's `$select` read does. */ +const ProjectingList = (props: Record) => { + const listed: string[] = (props.schema?.columns ?? []).map((c: any) => (typeof c === 'string' ? c : c.field)); + const row = Object.fromEntries(Object.entries(DEAL).filter(([k]) => k === 'id' || listed.includes(k))); + return ; +}; + afterEach(() => { cleanup(); ComponentRegistry.unregister('list-view'); @@ -28,10 +42,20 @@ afterEach(() => { const adapter = () => ({ aggregate: vi.fn(async () => [{ amount_sum: 120 }]), find: vi.fn(async () => ({ data: [{ id: '1', name: 'Acme Renewal' }] })), - getObjectSchema: vi.fn(async () => ({ name: 'deal', nameField: 'name', fields: { name: { type: 'text', label: 'Name' } } })), + getObjectSchema: vi.fn(async () => ({ + name: 'deal', + nameField: 'name', + fields: { + name: { type: 'text', label: 'Name' }, + stage: { type: 'text', label: 'Stage' }, + amount: { type: 'number', label: 'Amount' }, + owner: { type: 'text', label: 'Owner' }, + description: { type: 'text', label: 'Description' }, + }, + })), }); -const mount = () => +const mount = (drillDown: Record = { enabled: true, target: 'dialog' }) => render( objectName: 'deal', label: 'Revenue', aggregate: { field: 'amount', function: 'sum' }, - drillDown: { enabled: true, target: 'dialog' }, + drillDown, } as never} /> , @@ -57,6 +81,21 @@ describe('a page block with no record page opens the drilled record in a dialog expect(body.closest('[role="dialog"]')).not.toBeNull(); }); + it('draws the fields the list read, each with its value, and no field it did not read', async () => { + ComponentRegistry.register('list-view', ProjectingList as any); + mount({ enabled: true, target: 'dialog', columns: ['name', 'stage', 'amount'] }); + fireEvent.click(await screen.findByRole('button', { name: /revenue|120/i })); + fireEvent.click(await screen.findByTestId('stub-row')); + const body = await screen.findByTestId('record-detail-body'); + // The values are masked until the field types are in; wait for them. + await waitFor(() => expect(within(body).getByText('Acme Renewal')).toBeTruthy()); + const labels = Array.from(body.querySelectorAll('dt')).map((dt) => dt.textContent); + expect(labels).toEqual(['Name', 'Stage', 'Amount']); + for (const dd of Array.from(body.querySelectorAll('dd'))) { + expect(dd.textContent?.trim()).not.toMatch(/^(—|No value)?$/); + } + }); + it('from the data table when no list is registered', async () => { mount(); fireEvent.click(await screen.findByRole('button', { name: /revenue|120/i })); diff --git a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx index d19f4188c5c..19b5f63ddfa 100644 --- a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx +++ b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx @@ -964,7 +964,7 @@ function emitBucketDrill({ const fields = Array.from(new Set([ // A relationship path shows its lookup field: the list draws no dotted column. ...drillDims.map((d) => state.dimensionFields?.[d]).filter((f): f is string => !!f).map((f) => f.split('.')[0]), - ...Object.values(rowRanges ?? {}).map((range) => range.field), + ...Object.values(rowRanges ?? {}).map((range) => range.field.split('.')[0]), ...measuredFieldsOf(scope), ])); if (state.object && datasetDrillHasRelationshipPath(drillDims, state.dimensionFields)) { diff --git a/ui/packages/react/src/context/DrillNavigationContext.tsx b/ui/packages/react/src/context/DrillNavigationContext.tsx index a143a45e002..dec928276b1 100644 --- a/ui/packages/react/src/context/DrillNavigationContext.tsx +++ b/ui/packages/react/src/context/DrillNavigationContext.tsx @@ -69,7 +69,7 @@ export interface DrillNavigationValue { * page came from: the ids of the rows it shows, in order, which the page * steps through with ↑ ↓ under its 「N of M」 counter, and the count it * matched. The host makes the page it opened from (the dashboard, the - * report) the page's way back. Absent ⇒ the drill list opens no record. + * report) the page's way back. Absent ⇒ the drill opens the record in a dialog. */ openRecord?: (objectName: string, recordId: string, origin?: DrillRecordOrigin) => void; } From b91ec497b5952dc4679efea36adbbc09c76b5d6d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 17:51:39 +0000 Subject: [PATCH 11/15] test(plugin-dashboard): type the projecting list stub Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../ObjectMetricWidget.drillOpensRecord-36256.test.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/packages/plugin-dashboard/src/__tests__/ObjectMetricWidget.drillOpensRecord-36256.test.tsx b/ui/packages/plugin-dashboard/src/__tests__/ObjectMetricWidget.drillOpensRecord-36256.test.tsx index a6d17439840..ab230f4b857 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/ObjectMetricWidget.drillOpensRecord-36256.test.tsx +++ b/ui/packages/plugin-dashboard/src/__tests__/ObjectMetricWidget.drillOpensRecord-36256.test.tsx @@ -28,8 +28,12 @@ const StubList = (props: Record) => ( const DEAL = { id: '1', name: 'Acme Renewal', stage: 'won', amount: 120, owner: 'Dana', description: 'Three-year renewal' }; /** Answers with the record projected to the listed columns, as the list's `$select` read does. */ -const ProjectingList = (props: Record) => { - const listed: string[] = (props.schema?.columns ?? []).map((c: any) => (typeof c === 'string' ? c : c.field)); +interface ListProps { + schema?: { columns?: Array }; + onRowClick?: (row: Record) => void; +} +const ProjectingList = (props: ListProps) => { + const listed = (props.schema?.columns ?? []).map((c) => (typeof c === 'string' ? c : c.field)); const row = Object.fromEntries(Object.entries(DEAL).filter(([k]) => k === 'id' || listed.includes(k))); return ; }; @@ -82,7 +86,7 @@ describe('a page block with no record page opens the drilled record in a dialog }); it('draws the fields the list read, each with its value, and no field it did not read', async () => { - ComponentRegistry.register('list-view', ProjectingList as any); + ComponentRegistry.register('list-view', ProjectingList as never); mount({ enabled: true, target: 'dialog', columns: ['name', 'stage', 'amount'] }); fireEvent.click(await screen.findByRole('button', { name: /revenue|120/i })); fireEvent.click(await screen.findByTestId('stub-row')); From 62d97e4cd65b940fd307331711d825639243414b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 19:12:00 +0000 Subject: [PATCH 12/15] fix(dashboard): a page block's drill keeps its rule-array filter The drill list split only an object-form filter, so a page block's authored rule array ([{ field, operator, value }]) reached the list as nothing and the drill listed every record. A filter that is not the object form is now lowered through composeDrillFilter (mergeFilterNodes, then the spec's parseFilterAST) before the split; a shape that cannot be lowered stays the list's base filter exactly as it arrived, so no condition is dropped. Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- .../views/pageBlockDrillFilter-36256.test.tsx | 84 ++++++++++++++ .../plugin-dashboard/src/DrillRecordList.tsx | 2 +- .../__tests__/drillConditions-36256.test.ts | 19 ++++ .../pageBlockDrillFilter-36256.test.tsx | 106 ++++++++++++++++++ .../plugin-dashboard/src/drillConditions.ts | 50 +++++++-- 5 files changed, 253 insertions(+), 8 deletions(-) create mode 100644 ui/packages/app-shell/src/views/pageBlockDrillFilter-36256.test.tsx create mode 100644 ui/packages/plugin-dashboard/src/__tests__/pageBlockDrillFilter-36256.test.tsx diff --git a/ui/packages/app-shell/src/views/pageBlockDrillFilter-36256.test.tsx b/ui/packages/app-shell/src/views/pageBlockDrillFilter-36256.test.tsx new file mode 100644 index 00000000000..39c8bf31bb9 --- /dev/null +++ b/ui/packages/app-shell/src/views/pageBlockDrillFilter-36256.test.tsx @@ -0,0 +1,84 @@ +/** + * objectstack-ai/objectstack#36256 — a page block's drill lists the records + * its number counts. + * + * HotCRM's 销售主页 KPI tile is an `object-metric` block whose `filter` is the + * spec's rule-array form, `[{ field: 'stage', operator: 'equals', value: + * 'closed_won' }]`, handed to the drill as written. The drill draws the REAL + * standard list (`@object-ui/plugin-list`) over an in-memory matcher + * (`ValueDataSource`), so the read it sends is judged as a server would judge + * it. The tile counts the won deals. The drill must read with that condition + * and list exactly those deals, never every record of the object. + */ +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import React from 'react'; +import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react'; +import { ValueDataSource } from '@object-ui/core'; +import '@object-ui/plugin-dashboard'; +import '@object-ui/plugin-list'; + +const DEFINITION = { + name: 'opp_36256', + label: 'Opportunity', + nameField: 'name', + fields: { + name: { type: 'text', label: 'Name' }, + stage: { type: 'text', label: 'Stage' }, + amount: { type: 'number', label: 'Amount' }, + }, +}; + +const ROWS = [ + { id: 'o1', name: 'Initech Phase 1', stage: 'closed_won', amount: 90000 }, + { id: 'o2', name: 'Wayne Q1 Expansion', stage: 'closed_won', amount: 380000 }, + { id: 'o3', name: 'Apex Logistics Data Hub', stage: 'needs_analysis', amount: 93000 }, +]; +const WON = ROWS.filter((r) => r.stage === 'closed_won'); + +function mount() { + const matcher = new ValueDataSource({ items: ROWS }); + const ds = { + find: vi.fn((object: string, params?: Record) => matcher.find(object, params as never)), + // The tile's own number: the won deals' sum. + aggregate: vi.fn(async (_object: string, _params: Record) => [{ amount_sum: WON.reduce((a, r) => a + r.amount, 0) }]), + getObjectSchema: vi.fn(async () => structuredClone(DEFINITION)), + }; + vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, json: async () => ({}) }))); + render( + + + , + ); + return ds; +} + +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); + vi.restoreAllMocks(); +}); + +describe("a page block's rule-array filter reaches its drill's read (#36256)", () => { + it('lists exactly the records the tile counts, and the read carries the condition', async () => { + const ds = mount(); + fireEvent.click(await screen.findByRole('button', { name: /revenue won|470,000/i })); + const dialog = await screen.findByTestId('drill-down-dialog'); + for (const won of WON) expect(await within(dialog).findByText(won.name)).toBeInTheDocument(); + await waitFor(() => expect(within(dialog).queryByText('Apex Logistics Data Hub')).toBeNull()); + // The read the list sent, and the condition it carries. + const reads = ds.find.mock.calls.filter(([object]) => object === 'opp_36256'); + expect(reads.length).toBeGreaterThan(0); + expect(JSON.stringify(reads.at(-1)?.[1]?.$filter)).toContain('closed_won'); + }); +}); diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx index be60bb12934..fc2b02561df 100644 --- a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -84,7 +84,7 @@ export const DrillRecordList: React.FC = ({ const scope = useFilterScope(); // One resolution per mount: a chip shows the value the query compares. const resolved = React.useMemo( - () => resolveFilterPlaceholders(filter, scope) as Record | undefined, + () => resolveFilterPlaceholders(filter, scope) as unknown, // The drill's filter is fixed for the life of this mount (the dialog keys it). // eslint-disable-next-line react-hooks/exhaustive-deps [], diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts index c0c2471a046..33da8e88427 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts +++ b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts @@ -57,6 +57,25 @@ describe('drillListConditions', () => { ]); }); + it("lowers a page block's rule array, and an AST node, to chips", () => { + // HotCRM's 销售主页 KPI tile: the spec's rule-array form, handed as written. + expect(drillListConditions([{ field: 'stage', operator: 'equals', value: 'closed_won' }]).chips.conditions + .map(({ field, operator, value }) => ({ field, operator, value }))) + .toEqual([{ field: 'stage', operator: 'equals', value: 'closed_won' }]); + expect(drillListConditions([['stage', '=', 'closed_won'], ['amount', '>', 5]]).chips.conditions + .map(({ field, operator, value }) => ({ field, operator, value }))) + .toEqual([ + { field: 'stage', operator: 'equals', value: 'closed_won' }, + { field: 'amount', operator: 'greater_than', value: 5 }, + ]); + }); + + it('keeps a filter it cannot lower as the base filter, exactly as it arrived', () => { + // A scalar on a list operator: the spec's lowering refuses it. + const refused = [['stage', 'in', 'won']]; + expect(drillListConditions(refused)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: refused }); + }); + it('answers no rows and no rest for no filter', () => { expect(drillListConditions(undefined)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: undefined }); }); diff --git a/ui/packages/plugin-dashboard/src/__tests__/pageBlockDrillFilter-36256.test.tsx b/ui/packages/plugin-dashboard/src/__tests__/pageBlockDrillFilter-36256.test.tsx new file mode 100644 index 00000000000..cc60dd614f7 --- /dev/null +++ b/ui/packages/plugin-dashboard/src/__tests__/pageBlockDrillFilter-36256.test.tsx @@ -0,0 +1,106 @@ +/** + * objectstack-ai/objectstack#36256 — a page block's drill keeps its filter. + * + * A page block's `filter` is authored in the spec's rule-array form + * (`[{ field, operator, value }]`; HotCRM's 销售主页 KPI tiles). The + * `object-metric` block hands it to the drill as written. The `object-pivot` + * block composes it with the clicked cell through `composeDrillFilter` first. + * Either way, every condition must reach the drill list: as one of its chips, + * or as its base filter. + * + * The registered `list-view` is a stub that records the props it is handed. + * What the real list reads with them is pinned in app-shell + * (`pageBlockDrillFilter-36256.test.tsx` there). + */ +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react'; +import { ComponentRegistry } from '@object-ui/core'; +import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react'; +import '../index'; + +const seen = vi.fn(); +const StubList = (props: Record) => { + seen(props); + return null; +}; +const last = () => seen.mock.calls.at(-1)?.[0] as + | { schema: { filter?: unknown }; initialFilters?: { conditions: Array<{ field: string; operator: string; value?: unknown }> } } + | undefined; + +/** The drill list's conditions: its chips and its base filter. */ +const conditionsSeen = () => ({ + chips: (last()?.initialFilters?.conditions ?? []).map(({ field, operator, value }) => ({ field, operator, value })), + base: last()?.schema.filter, +}); + +beforeEach(() => { + seen.mockClear(); + ComponentRegistry.register('list-view', StubList as never); + vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, json: async () => ({}) }))); +}); +afterEach(() => { + cleanup(); + ComponentRegistry.unregister('list-view'); + vi.unstubAllGlobals(); +}); + +const adapter = () => ({ + aggregate: vi.fn(async () => [{ amount_sum: 1290000 }]), + find: vi.fn(async () => ({ data: [] })), + getObjectSchema: vi.fn(async () => ({ + name: 'crm_opportunity', + nameField: 'name', + fields: { name: { type: 'text' }, stage: { type: 'text' }, lead_source: { type: 'text' }, amount: { type: 'number' } }, + })), +}); + +const mount = (schema: Record) => + render( + + + , + ); + +describe("a page block's drill keeps its rule-array filter (#36256)", () => { + it('object-metric: the tile\'s `stage = closed_won` reaches the drill list', async () => { + mount({ + type: 'object-metric', + objectName: 'crm_opportunity', + label: 'Revenue won', + aggregate: { field: 'amount', function: 'sum' }, + filter: [{ field: 'stage', operator: 'equals', value: 'closed_won' }], + drillDown: { enabled: true, target: 'dialog' }, + }); + fireEvent.click(await screen.findByRole('button', { name: /revenue won|1,290,000/i })); + await waitFor(() => expect(last()).toBeDefined()); + expect(conditionsSeen()).toEqual({ + chips: [{ field: 'stage', operator: 'equals', value: 'closed_won' }], + base: undefined, + }); + }); + + it('object-pivot: the block\'s filter and the clicked cell both reach the drill list', async () => { + mount({ + type: 'object-pivot', + objectName: 'crm_opportunity', + rowField: 'stage', + columnField: 'lead_source', + valueField: 'amount', + aggregation: 'sum', + data: [ + { id: 'a', stage: 'closed_won', lead_source: 'web', amount: 10 }, + { id: 'b', stage: 'prospecting', lead_source: 'web', amount: 20 }, + ], + filter: [{ field: 'stage', operator: 'equals', value: 'closed_won' }], + drillDown: { enabled: true, target: 'dialog' }, + }); + fireEvent.click(await screen.findByLabelText('Drill into stage=closed_won, lead_source=web')); + await waitFor(() => expect(last()).toBeDefined()); + const { chips, base } = conditionsSeen(); + expect(base).toBeUndefined(); + expect(chips).toEqual(expect.arrayContaining([ + { field: 'stage', operator: 'equals', value: 'closed_won' }, + { field: 'lead_source', operator: 'equals', value: 'web' }, + ])); + }); +}); diff --git a/ui/packages/plugin-dashboard/src/drillConditions.ts b/ui/packages/plugin-dashboard/src/drillConditions.ts index 653329a071f..42540903fb6 100644 --- a/ui/packages/plugin-dashboard/src/drillConditions.ts +++ b/ui/packages/plugin-dashboard/src/drillConditions.ts @@ -21,11 +21,18 @@ * as it was. Both are ANDed, so the list matches the drill exactly until the * reader edits a chip. * + * A filter that is not the object form (a page block's authored rule array + * `[{ field, operator, value }]`, an AST node) is lowered to it first, through + * the drill's own composition (`composeDrillFilter`: `mergeFilterNodes`, then + * the spec's `parseFilterAST`). A shape that cannot be lowered stays the base + * `filter` exactly as it arrived. No condition is ever dropped. + * * Values must already be resolved (`resolveFilterPlaceholders`): a chip shows * what the query compares, never a `{token}`. */ import type { FilterBuilderRow, FilterBuilderRowGroup } from '@object-ui/components'; +import { composeDrillFilter, FilterOperatorError } from '@object-ui/core'; /** The row operator each comparison operator of the filter dialect reads as. */ const ROW_OPERATOR: Readonly> = { @@ -47,10 +54,14 @@ const isScalar = (v: unknown): v is string | number | boolean => const isPlainObject = (v: unknown): v is Record => !!v && typeof v === 'object' && !Array.isArray(v); -/** Split a filter into its ANDed single-key parts: `$and` members and the keys of one object. */ -function andParts(filter: unknown): Record[] { - if (!isPlainObject(filter)) return []; - const parts: Record[] = []; +/** + * Split a filter into its ANDed parts: `$and` members and the keys of one + * object, each `{ field: condition }`. A member that is not an object is one + * part as it is, never dropped. + */ +function andParts(filter: unknown): unknown[] { + if (!isPlainObject(filter)) return [filter]; + const parts: unknown[] = []; for (const [key, value] of Object.entries(filter)) { if (key === '$and' && Array.isArray(value)) { for (const member of value) parts.push(...andParts(member)); @@ -61,6 +72,26 @@ function andParts(filter: unknown): Record[] { return parts; } +/** Does every ANDed part read as `{ field: condition }`? */ +const splits = (filter: unknown): filter is Record => + isPlainObject(filter) && andParts(filter).every(isPlainObject); + +/** + * The filter in the object form, or `null` when it cannot be lowered (see the + * file header). `undefined` is no filter. + */ +function objectFormOf(filter: unknown): Record | undefined | null { + if (filter === undefined || filter === null) return undefined; + if (splits(filter)) return filter; + try { + const lowered: unknown = composeDrillFilter(filter, undefined); + return lowered === undefined || splits(lowered) ? lowered : null; + } catch (error) { + if (error instanceof FilterOperatorError) return null; + throw error; + } +} + /** The rows one `{ field: condition }` part reads as, or `null` when it is no row. */ function rowsOf(field: string, condition: unknown): Omit[] | null { if (field.startsWith('$')) return null; @@ -87,7 +118,7 @@ export interface DrillListConditions { /** The conditions drawn as the list's chips, its `initialFilters`. */ chips: FilterBuilderRowGroup; /** What no chip can say, kept as the list's base `filter`; `undefined` when nothing is left. */ - rest: Record | undefined; + rest: Record | unknown[] | undefined; } /** @@ -108,13 +139,18 @@ export interface DrillListConditionOptions { /** Split a resolved drill filter into chip rows and the rest (see the file header). */ export function drillListConditions( - filter: Record | undefined, + filter: unknown, { dateFields }: DrillListConditionOptions = {}, ): DrillListConditions { const conditions: FilterBuilderRow[] = []; + const lowered = objectFormOf(filter); + // Not lowered: the list's base filter, exactly as it arrived. + if (lowered === null) { + return { chips: { logic: 'and', conditions }, rest: filter as Record | unknown[] }; + } const rest: Record[] = []; const seen = new Set(); - for (const part of andParts(filter)) { + for (const part of andParts(lowered ?? {}) as Record[]) { const [field, condition] = Object.entries(part)[0]; const rows = rowsOf(field, condition); if (!rows) { From 942e9c2f17ff0830a342a19cd7b06b6533e493d6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 19:33:51 +0000 Subject: [PATCH 13/15] fix(dashboard): read measured fields from object parts only Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg Co-authored-by: Claude --- ui/packages/plugin-dashboard/src/drillConditions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/packages/plugin-dashboard/src/drillConditions.ts b/ui/packages/plugin-dashboard/src/drillConditions.ts index 42540903fb6..e7153634354 100644 --- a/ui/packages/plugin-dashboard/src/drillConditions.ts +++ b/ui/packages/plugin-dashboard/src/drillConditions.ts @@ -182,6 +182,7 @@ export function drillListConditions( */ export function measuredFieldsOf(scope: unknown): string[] { return andParts(scope) + .filter(isPlainObject) .map((part) => Object.entries(part)[0]) .filter(([field, c]) => !field.startsWith('$') && isPlainObject(c) && c.$null === false && Object.keys(c).length === 1) .map(([field]) => field); From 8e8c3bfb7867ab75d8a6e89ccf59bfae391e73b8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 21:08:00 +0000 Subject: [PATCH 14/15] fix(dashboard): a drill keeps every filter it cannot lower, and draws in full inside a page A non-empty filter the conversion answers nothing for (an array that is neither rules nor AST, a rule with no field) stays the drill list's base filter as it arrived, and a string or number filter lists nothing instead of every record. The drill dialog clears the page region's posture through the new PageRegionPostureReset, so a page block's drill draws the standard list with its chips, count and pager, and no View all link. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg --- .../36256-drill-dialog-standard-list.md | 7 +- .../views/pageBlockDrillFilter-36256.test.tsx | 33 +++- .../pageBlockDrillPosture-36550.test.tsx | 147 ++++++++++++++++++ ui/packages/components/src/index.ts | 4 +- .../renderers/layout/page-region-posture.tsx | 15 ++ .../plugin-dashboard/src/DrillDownDrawer.tsx | 8 +- .../plugin-dashboard/src/DrillRecordList.tsx | 11 +- .../__tests__/drillConditions-36256.test.ts | 41 ++++- .../plugin-dashboard/src/drillConditions.ts | 19 ++- 9 files changed, 272 insertions(+), 13 deletions(-) create mode 100644 ui/packages/app-shell/src/views/pageBlockDrillPosture-36550.test.tsx diff --git a/.changeset/36256-drill-dialog-standard-list.md b/.changeset/36256-drill-dialog-standard-list.md index 42f5be2f999..5d162ab04cc 100644 --- a/.changeset/36256-drill-dialog-standard-list.md +++ b/.changeset/36256-drill-dialog-standard-list.md @@ -3,15 +3,18 @@ '@object-ui/plugin-report': patch '@object-ui/react': patch '@object-ui/app-shell': patch +'@object-ui/components': minor --- feat(plugin-dashboard): a dashboard or report drill opens a centred dialog over the standard list, and a report's chart marks drill -Clause-②: yes (widening) +Clause-②: yes (widening) — additive members only, among them the new `PageRegionPostureReset` export of `@object-ui/components`; nothing is removed or renamed Metadata-protocol: none Clicking a number on a dashboard (a chart mark, a metric tile, a table cell) or on a dataset report used to open a full-height side drawer whose table listed every field of the object, with no sort, no filter and no word on which conditions selected the records; a row stacked a second record panel on top. The drill now opens a dialog about 70% wide and 65% tall that dims and blurs nothing behind it, and its body is the standard list the object list page draws (`list-view`): the same row height, column-header sort, filter chips, added columns, record count and column calculations. The drill's conditions (the clicked bucket, the widget's filter, the measure's scope) are the list's own chips and can be changed or removed; a condition no chip can say (a relationship path, an `$or`) still filters the list. The default columns are the record's name, the grouped fields and the measured fields. Nothing done in the dialog is saved, and it writes nothing. A record's name opens the record's full page, whose 「N of M」 stepper walks the drill's rows and whose way back is the dashboard or report; no second panel is stacked. 「Open in list」 is unchanged. On a phone the drill keeps the side drawer, with the same list. A dataset report's chart marks now drill too: a bar opens the same records as the summary line it stands for. -Additive members: `DrillNavigationValue.openRecord` and the `DrillRecordOrigin` type (`@object-ui/react`), `DrillDownDrawerProps.defaultColumns` (`@object-ui/plugin-dashboard`), `DatasetDrillArgs.fields` (`@object-ui/plugin-report`). A renderer without `@object-ui/plugin-list` registered lists the drilled records in the dashboard's data table. A host that gives no `openRecord` (a page block's metric or pivot) opens the drilled record in a dialog, from either body. +Additive members: `DrillNavigationValue.openRecord` and the `DrillRecordOrigin` type (`@object-ui/react`), `DrillDownDrawerProps.defaultColumns` (`@object-ui/plugin-dashboard`), `DatasetDrillArgs.fields` (`@object-ui/plugin-report`), `PageRegionPostureReset` (`@object-ui/components`). A renderer without `@object-ui/plugin-list` registered lists the drilled records in the dashboard's data table. A host that gives no `openRecord` (a page block's metric or pivot) opens the drilled record in a dialog, from either body. + +Inside a page the drill draws the same standard list: the page region's posture (the compact or capped list a page block draws) is cleared for the drill's dialog by the new `PageRegionPostureReset` (`@object-ui/components`), so a page block's metric or pivot drill shows its chips, its record count and its pager, and no 「View all」 link to a list without the drill's condition. A drill whose filter names no condition any read can carry (a string, a number) lists nothing and says so, instead of listing every record. diff --git a/ui/packages/app-shell/src/views/pageBlockDrillFilter-36256.test.tsx b/ui/packages/app-shell/src/views/pageBlockDrillFilter-36256.test.tsx index 39c8bf31bb9..7db63bc5317 100644 --- a/ui/packages/app-shell/src/views/pageBlockDrillFilter-36256.test.tsx +++ b/ui/packages/app-shell/src/views/pageBlockDrillFilter-36256.test.tsx @@ -37,7 +37,7 @@ const ROWS = [ ]; const WON = ROWS.filter((r) => r.stage === 'closed_won'); -function mount() { +function mount(filter: unknown = [{ field: 'stage', operator: 'equals', value: 'closed_won' }]) { const matcher = new ValueDataSource({ items: ROWS }); const ds = { find: vi.fn((object: string, params?: Record) => matcher.find(object, params as never)), @@ -54,7 +54,7 @@ function mount() { objectName: 'opp_36256', label: 'Revenue won', aggregate: { field: 'amount', function: 'sum' }, - filter: [{ field: 'stage', operator: 'equals', value: 'closed_won' }], + filter, drillDown: { enabled: true, target: 'dialog', columns: ['name', 'stage', 'amount'] }, } as never} /> @@ -81,4 +81,33 @@ describe("a page block's rule-array filter reaches its drill's read (#36256)", ( expect(reads.length).toBeGreaterThan(0); expect(JSON.stringify(reads.at(-1)?.[1]?.$filter)).toContain('closed_won'); }); + + it.each([ + ['an array that is neither rules nor AST', [{ stage: 'closed_won' }]], + ['a rule with a blank field', [{ field: '', operator: 'equals', value: 'closed_won' }]], + ['a valid rule beside a malformed one', [{ field: 'stage', operator: 'equals', value: 'closed_won' }, { stage: 'x' }]], + ])('hands a filter the conversion answers nothing for to the list as its base filter, never an unfiltered read: %s', async (_, filter) => { + const ds = mount(filter); + fireEvent.click(await screen.findByRole('button', { name: /revenue won|470,000/i })); + const dialog = await screen.findByTestId('drill-down-dialog'); + await waitFor(() => expect(ds.find.mock.calls.some(([object]) => object === 'opp_36256')).toBe(true)); + // Every read carries the filter (a server refuses it as malformed; it is + // never read as no filter). + for (const [object, params] of ds.find.mock.calls) { + if (object === 'opp_36256') expect(params?.$filter).toBeDefined(); + } + await waitFor(() => expect(within(dialog).queryByText('Apex Logistics Data Hub')).toBeNull()); + }); + + it.each([ + ['a string', 'stage = closed_won'], + ['a number', 7], + ])('lists nothing for a filter no read can carry, and sends no read: %s', async (_, filter) => { + const ds = mount(filter); + fireEvent.click(await screen.findByRole('button', { name: /revenue won|470,000/i })); + const dialog = await screen.findByTestId('drill-down-dialog'); + expect(within(dialog).getByTestId('drill-down-notice')).toHaveAttribute('data-notice', 'unavailable'); + await new Promise((r) => setTimeout(r, 50)); + expect(ds.find.mock.calls.filter(([object]) => object === 'opp_36256')).toEqual([]); + }); }); diff --git a/ui/packages/app-shell/src/views/pageBlockDrillPosture-36550.test.tsx b/ui/packages/app-shell/src/views/pageBlockDrillPosture-36550.test.tsx new file mode 100644 index 00000000000..3ecbfedcbdc --- /dev/null +++ b/ui/packages/app-shell/src/views/pageBlockDrillPosture-36550.test.tsx @@ -0,0 +1,147 @@ +/** + * objectstack-ai/objectstack#36550 (#36256) — a page block's drill draws the + * standard list, not the page region's posture. + * + * A page region tells its blocks their posture (compact or capped), and React + * context crosses the drill dialog's portal. So a metric block's drill, opened + * from a region half the page or wider, drew its list capped: no toolbar, no + * chips, no pager, and a 「View all N」 link to the object's list without the + * drill's condition. The drill clears the posture for its own subtree. + * + * Everything renders through the REAL page renderer, the REAL `list-view` and + * the REAL `object-metric`, with the stand-in `ResizeObserver` the + * objectui#12703 / objectstack#26613 pins use for the region widths. CONTROL: + * the page's own list block in the same region stays capped. + */ +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import React from 'react'; +import { + ActionProvider, + I18nProvider, + RelatedRecordActionsProvider, + SchemaRenderer, + SchemaRendererProvider, + type RelatedRecordActionsValue, +} from '@object-ui/react'; +import { ValueDataSource } from '@object-ui/core'; +import '@object-ui/components'; +import '@object-ui/plugin-dashboard'; +import '@object-ui/plugin-list'; + +const OBJECT = 'opp_36550'; +const DEFINITION = { + name: OBJECT, + label: 'Opportunity', + nameField: 'name', + fields: { + name: { type: 'text', label: 'Name' }, + stage: { type: 'text', label: 'Stage' }, + amount: { type: 'number', label: 'Amount' }, + }, +}; +const ROWS = [ + { id: 'o1', name: 'Initech Phase 1', stage: 'closed_won', amount: 90000 }, + { id: 'o2', name: 'Wayne Q1 Expansion', stage: 'closed_won', amount: 380000 }, + { id: 'o3', name: 'Apex Logistics Data Hub', stage: 'needs_analysis', amount: 93000 }, +]; + +/** Installs a `ResizeObserver` that reports these widths for the page body and each region. */ +function stubWidths(widths: { page: number; regions: Record }) { + class WidthReportingObserver { + constructor(private readonly callback: ResizeObserverCallback) {} + observe(target: Element) { + const region = target.getAttribute('data-region'); + const width = region != null + ? widths.regions[region] + : target.matches('[data-page-type] > div') ? widths.page : undefined; + if (width === undefined) return; + this.callback([{ target, contentRect: { width } } as unknown as ResizeObserverEntry], this as never); + } + unobserve() {} + disconnect() {} + } + vi.stubGlobal('ResizeObserver', WidthReportingObserver); +} + +const host = (): RelatedRecordActionsValue => ({ + resolve: () => ({}), + listHref: (objectName: string) => `/apps/crm/${objectName}`, + openList: vi.fn(), +}); + +function mount() { + const matcher = new ValueDataSource({ items: ROWS }); + const ds = { + find: vi.fn((object: string, params?: Record) => matcher.find(object, params as never)), + aggregate: vi.fn(async () => [{ amount_sum: 470000 }]), + getObjectSchema: vi.fn(async () => structuredClone(DEFINITION)), + }; + vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, json: async () => ({}) }))); + stubWidths({ page: 1200, regions: { main: 856, aside: 320 } }); + const view = render( + + + + + + + + + , + ); + return { ds, ...view }; +} + +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); + vi.restoreAllMocks(); +}); + +describe("a page block's drill draws the standard list, not the region's posture (#36550)", () => { + it('shows its chips and its record count and no 「View all」, while the block list beside it stays capped', async () => { + const { container } = mount(); + const main = container.querySelector('[data-region="main"]') as HTMLElement; + + // CONTROL: the page's own list block in the same region is capped. + await waitFor(() => expect(within(main).getAllByTestId('list-capped-row')).toHaveLength(3)); + expect(within(main).getByRole('link', { name: /^View all 3/ })).toBeInTheDocument(); + + fireEvent.click(await screen.findByRole('button', { name: /revenue won|470,000/i })); + const dialog = await screen.findByTestId('drill-down-dialog'); + for (const name of ['Initech Phase 1', 'Wayne Q1 Expansion']) { + expect(await within(dialog).findByText(name)).toBeInTheDocument(); + } + // The standard list: the drill's condition as a chip, and its record count. + expect(await within(dialog).findByTestId('filter-chip-stage')).toBeInTheDocument(); + expect(await within(dialog).findByText('2 records')).toBeInTheDocument(); + // Not the capped list, and no link to a list without the condition. + expect(within(dialog).queryByTestId('list-capped-table')).toBeNull(); + expect(within(dialog).queryByRole('link', { name: /View all/ })).toBeNull(); + expect(within(dialog).queryByText('Apex Logistics Data Hub')).toBeNull(); + }); +}); diff --git a/ui/packages/components/src/index.ts b/ui/packages/components/src/index.ts index d5ce96187f0..0a56c97d0e6 100644 --- a/ui/packages/components/src/index.ts +++ b/ui/packages/components/src/index.ts @@ -103,7 +103,9 @@ export type { PageBlockSpan } from './renderers/layout/page-block-span'; // renderer (objectui#12703): `compact` when the region is narrower than half // the page. Exported for the blocks that read it in other packages — the // `list-view` block in `@object-ui/plugin-list` draws a short list there. -export { usePageRegionPosture } from './renderers/layout/page-region-posture'; +// `PageRegionPostureReset` clears it for a surface a block opens over the page +// (a drill dialog), so the list there draws in full (objectstack#36256). +export { usePageRegionPosture, PageRegionPostureReset } from './renderers/layout/page-region-posture'; export type { PageRegionPosture } from './renderers/layout/page-region-posture'; // The count channel a `page:tabs` panel opens to the blocks inside it diff --git a/ui/packages/components/src/renderers/layout/page-region-posture.tsx b/ui/packages/components/src/renderers/layout/page-region-posture.tsx index 761c974f5b5..d0ec4ee9882 100644 --- a/ui/packages/components/src/renderers/layout/page-region-posture.tsx +++ b/ui/packages/components/src/renderers/layout/page-region-posture.tsx @@ -174,6 +174,21 @@ export const PageRegionPostureProvider: React.FC<{ return {children}; }; +/** + * Clears the page-region posture for its subtree, so a block under it reads + * `null` and draws its full rendering, as it would outside any page. + * + * For a surface a page block opens over the page that is not a part of the + * block's region: a drill dialog (objectstack-ai/objectstack#36256). React + * context crosses a dialog's portal, so without this the dialog's list would + * take the posture of the region that holds the block that opened it, and + * draw the compact or capped list there: no toolbar, no chips, no pager, and + * a 「View all」 link to a list that does not carry the dialog's condition. + */ +export const PageRegionPostureReset: React.FC<{ children: React.ReactNode }> = ({ children }) => ( + {children} +); + /** * The posture of the page region this block renders in: `'compact'` when the * region is narrower than half the page, `'full'` when it is not, `null` diff --git a/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx b/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx index 92c4716c9e9..2d82d9adbca 100644 --- a/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx +++ b/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx @@ -162,8 +162,14 @@ export const DrillDownDrawer: React.FC = ({ maxRows, className, report, - notice, + notice: givenNotice, }) => { + // A filter that is neither an object nor an array (a string, a number) + // names no condition any read can carry: every list below would read it as + // no filter and list every record (objectstack-ai/objectstack#36256). So no + // list is drawn, and no read is sent. + const notice: DrillDownNotice | undefined = + givenNotice ?? (filter != null && typeof filter !== 'object' ? 'unavailable' : undefined); const phone = useIsMobile(); const { openRecordList, canOpenRecordList, openRecord } = useDrillNavigation(); const tt = useSafeTranslate(); diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx index fc2b02561df..9c50c980953 100644 --- a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -26,9 +26,13 @@ * 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. + * + * Inside a page the list draws in full as well: the page region's posture + * (compact or capped) is cleared for the drill (`PageRegionPostureReset`). */ 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 { FILTER_DATE_LIKE_TYPES } from '@object-ui/types'; @@ -146,7 +150,10 @@ export const DrillRecordList: React.FC = ({ }; return ( - <> + // The drill is not a part of the page region that holds the block it was + // opened from: its list draws in full there too (chips, pager, no + // 「View all」 link to an unfiltered list), not in the region's posture. + = ({ onClose={() => setOpened(null)} /> )} - + ); }; diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts index 33da8e88427..97801cb4790 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts +++ b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts @@ -70,14 +70,51 @@ describe('drillListConditions', () => { ]); }); + it('lowers an `and` node to chips, and keeps an `or` node and an any-of group as the base filter', () => { + expect(drillListConditions(['and', ['stage', '=', 'closed_won'], ['amount', '>', 5]]).chips.conditions + .map(({ field, operator, value }) => ({ field, operator, value }))) + .toEqual([ + { field: 'stage', operator: 'equals', value: 'closed_won' }, + { field: 'amount', operator: 'greater_than', value: 5 }, + ]); + expect(drillListConditions(['or', ['stage', '=', 'closed_won'], ['stage', '=', 'negotiation']])).toEqual({ + chips: { logic: 'and', conditions: [] }, + rest: { $or: [{ stage: 'closed_won' }, { stage: 'negotiation' }] }, + }); + // A rule array with an any-of group (`{ or: [rule, ...] }`): the rule is a + // chip, the group the base filter's `$or`. + const { chips, rest } = drillListConditions([ + { field: 'stage', operator: 'equals', value: 'closed_won' }, + { or: [ + { field: 'lead_source', operator: 'equals', value: 'web' }, + { field: 'lead_source', operator: 'equals', value: 'referral' }, + ] }, + ]); + expect(chips.conditions.map(({ field, operator, value }) => ({ field, operator, value }))) + .toEqual([{ field: 'stage', operator: 'equals', value: 'closed_won' }]); + expect(rest).toEqual({ $or: [{ lead_source: 'web' }, { lead_source: 'referral' }] }); + }); + it('keeps a filter it cannot lower as the base filter, exactly as it arrived', () => { // A scalar on a list operator: the spec's lowering refuses it. const refused = [['stage', 'in', 'won']]; expect(drillListConditions(refused)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: refused }); }); - it('answers no rows and no rest for no filter', () => { - expect(drillListConditions(undefined)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: undefined }); + it.each([ + ['an array that is neither rules nor AST', [{ stage: 'closed_won' }]], + ['a rule with a blank field', [{ field: '', operator: 'equals', value: 'closed_won' }]], + ['a rule with no field', [{ operator: 'equals', value: 'closed_won' }]], + ['a valid rule beside a malformed one', [{ field: 'stage', operator: 'equals', value: 'closed_won' }, { stage: 'x' }]], + ['a string', 'stage = closed_won'], + ['a number', 7], + ])('keeps a filter the conversion answers nothing for as the base filter, exactly as it arrived: %s', (_, filter) => { + // Not empty, so never read as no filter: that would list every record. + expect(drillListConditions(filter)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: filter }); + }); + + it.each([undefined, null, [], {}])('answers no rows and no rest for no filter: %j', (filter) => { + expect(drillListConditions(filter)).toEqual({ chips: { logic: 'and', conditions: [] }, rest: undefined }); }); }); diff --git a/ui/packages/plugin-dashboard/src/drillConditions.ts b/ui/packages/plugin-dashboard/src/drillConditions.ts index e7153634354..c1191d87767 100644 --- a/ui/packages/plugin-dashboard/src/drillConditions.ts +++ b/ui/packages/plugin-dashboard/src/drillConditions.ts @@ -25,7 +25,14 @@ * `[{ field, operator, value }]`, an AST node) is lowered to it first, through * the drill's own composition (`composeDrillFilter`: `mergeFilterNodes`, then * the spec's `parseFilterAST`). A shape that cannot be lowered stays the base - * `filter` exactly as it arrived. No condition is ever dropped. + * `filter` exactly as it arrived: one the conversion refuses (a + * `FilterOperatorError`), and one it answers with nothing although it is not + * empty (an array that is neither rules nor AST, a rule with no field beside a + * valid one, a string or a number; the drill drawer lists nothing for the + * last two, since no list reads them). The spec's `parseFilterAST` answers + * `undefined` for such an array, the hazard `ObjectMetricWidget`'s + * `specShapeWhere` guards its own read against, and reading that as "no + * filter" would list every record. No condition is ever dropped. * * Values must already be resolved (`resolveFilterPlaceholders`): a chip shows * what the query compares, never a `{token}`. @@ -76,16 +83,22 @@ function andParts(filter: unknown): unknown[] { const splits = (filter: unknown): filter is Record => isPlainObject(filter) && andParts(filter).every(isPlainObject); +/** No filter: absent, an empty array or an empty object. */ +const isEmptyFilter = (v: unknown): boolean => + v === undefined || v === null || (Array.isArray(v) && v.length === 0) || (isPlainObject(v) && Object.keys(v).length === 0); + /** * The filter in the object form, or `null` when it cannot be lowered (see the * file header). `undefined` is no filter. */ function objectFormOf(filter: unknown): Record | undefined | null { - if (filter === undefined || filter === null) return undefined; + if (isEmptyFilter(filter)) return undefined; if (splits(filter)) return filter; try { const lowered: unknown = composeDrillFilter(filter, undefined); - return lowered === undefined || splits(lowered) ? lowered : null; + // A filter that is not empty never lowers to no filter: kept as it arrived. + if (isEmptyFilter(lowered)) return null; + return splits(lowered) ? lowered : null; } catch (error) { if (error instanceof FilterOperatorError) return null; throw error; From a9d781de2f67688989053fc60f6266b43844056a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 22:14:06 +0000 Subject: [PATCH 15/15] chore(changeset): grade @object-ui/components patch Metadata-protocol is none, so the level is patch (maintainer ruling A in the Check Changeset step); the new export is a widening at patch. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg --- .changeset/36256-drill-dialog-standard-list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/36256-drill-dialog-standard-list.md b/.changeset/36256-drill-dialog-standard-list.md index 5d162ab04cc..d61596e5d75 100644 --- a/.changeset/36256-drill-dialog-standard-list.md +++ b/.changeset/36256-drill-dialog-standard-list.md @@ -3,7 +3,7 @@ '@object-ui/plugin-report': patch '@object-ui/react': patch '@object-ui/app-shell': patch -'@object-ui/components': minor +'@object-ui/components': patch --- feat(plugin-dashboard): a dashboard or report drill opens a centred dialog over the standard list, and a report's chart marks drill