Skip to content

Commit 0004e8d

Browse files
fix(plugin-list): withhold the In a queue toggle on a view whose filter pins owner_id (#34623)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBM4G57dB19BKkNck4JJf8GN)_ Fixes #34580 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:列表工具栏的「在队列中」开关,在当前视图自己的过滤条件已经要求「负责人必须有值」(顶层 AND 里 `owner_id` 为 `equals` 某人、`in` 一组人或 `is_not_empty`)时不再显示;写在 OR 组里的负责人条件不算。开关隐藏期间不再往查询里加条件;若之前处于打开状态会被关掉,切回能显示它的视图时是关闭的。 - 为什么改:开关加的条件是「负责人为空且在某个队列里」,和「负责人 = 我」矛盾,所以在 HotCRM「我的未结商机」这类视图上打开它永远是空列表,用户会误读成「队列里没有东西」。 - 风险与回滚:只改 `@object-ui/plugin-list` 的工具栏判断,不动元数据、契约和服务端;另把文档 `queues-and-assignment-rules.mdx` 里描述开关何时出现的一句改成两个条件都写明。最坏情况是某个视图上开关被多藏了一次(只在负责人确实被钉死时才藏)。回滚即 revert 本 PR。 - 先看:① `ui/packages/plugin-list/src/ListView.tsx` 的 `viewFilterRequiresOwner` 与它下面的 `conjunctsOf` / `requiresOwnerValue`(哪些算「顶层 AND」、哪些运算符算「必须有值」);② 同文件 `queueFilterOffered` 处新加的 `viewPinsOwner` 与重置 effect;③ `ListView.harness.test.tsx` 新增的 `ListView.queueToggleOwnerPin-34580` 块。 - 两分钟验证:在仓根执行 `pnpm --dir ui exec vitest run packages/plugin-list/src/__tests__/ListView.harness.test.tsx -t 34580`,预期 6 个测试全部通过。 - 需要你做的:无,席位落地。 ## What changes `ui/packages/plugin-list/src/ListView.tsx`: - New exported `viewFilterRequiresOwner(viewFilter)`. It lowers the view's own filter through the shared `toFilterNodeSafely` (so a stored rule list, an AST and a MongoDB-style object answer alike), walks the conjuncts of the top-level AND (nested `and` nodes and implicit-AND lists included, `or` nodes skipped), and answers true when one conjunct is on `owner_id` (`SystemFieldName.OWNER_ID`) with an operator that requires a value, folded by the spec's `canonicalAstOperator`: - `=` (any spelling: `equals`, `eq`, `==`) with a non-empty scalar comparand; - `in` with a list whose every member is a non-empty scalar; - `is_not_empty` (any spelling; direction comes from the operator name, as the spec's lowering reads it). A filter the lowering refuses pins nothing here; the list already answers it with its load error. - `queueFilterOffered` adds `&& !viewPinsOwner`, where `viewPinsOwner = viewFilterRequiresOwner(authoredFilter)` (the resolved view filter the fetch, export and empty state already read). Since `appliedQueueSittingConditions` is gated on `queueFilterOffered`, a withheld toggle contributes no condition. - An effect lets go of a pressed state while the view pins the owner, so a view that offers the toggle again shows it off (acceptance 4). It sends no extra query: the applied conditions are already the empty constant while withheld. No new key, no server reading, no contract change. ## Why The toggle AND-s `owner_id is_empty` and `queue is_not_empty` (`QUEUE_SITTING_CONDITIONS`). Beside a view filter `owner_id equals {current_user_id}` (HotCRM's "My Open Deals") the conjunction has no rows whatever the data, and the user reads the empty list as "nothing is waiting in a queue". Same rule as the `hasAnyQueue` gate: offer an affordance only where it can do something. ## Tests Added as a top-level `describe('ListView.queueToggleOwnerPin-34580')` in `ui/packages/plugin-list/src/__tests__/ListView.harness.test.tsx`, opening with `restoreAfterBlock()`, among the blocks that register no stand-in renderer (AGENTS.md: a new pin for a component that already has a shared harness file goes into that file, ruling record 6583487846). The toggle's existing offer rules stay pinned in `ListView.queueSittingFilter-25769.test.tsx`, untouched. - `viewFilterRequiresOwner` pins on equals / in / is_not_empty across a stored rule list, an AST triple, a nested `and`, an implicit-AND list and a MongoDB-style object; it does not pin inside an OR group (stored `{ or: [...] }` and AST `or`), on `not_equals`, `is_empty`, `= null`, or an `in` list holding null. - Acceptance 1: "My Open Deals" (`owner_id equals {current_user_id}` + `stage not_in [...]`, resolved through `FilterScopeProvider`): no toggle, and the query carries no `is_empty`. - Acceptance 2 and 3: "All Opportunities" (no owner condition): the toggle renders off, and pressing it still AND-s both queue conditions beside the view's stage filter. - OR group: an owner condition inside `{ or: [...] }` keeps the toggle. - Acceptance 4: one mount, the view filter changed by `rerender`: pressed on the unpinned view, then the pinned view shows no toggle and its query has no `is_empty`, then back on the unpinned view the toggle is shown with `aria-pressed="false"` and the query has no queue condition. ## Acceptance notes - In the console the host remounts `ListView` per view (`identityKey` in app-shell's `objectViewListRenderer.tsx`), so a view switch there already resets the toggle; the rerender pin covers hosts that hand one instance a new `filter`. - A one-member any-of group `{ or: [rule] }` is lowered by `toFilterNode` to the bare rule, so it pins: it is logically the same condition. Groups of two or more members do not pin. - Docs (round 2, L1-a REWORK 6938675239): `content/docs/automation/queues-and-assignment-rules.mdx`, the sentence on when the **In a queue** toggle shows, now names both shipped conditions: the organization has at least one queue, and the view's own filter does not require `owner_id` to hold a value. The file joined the claim surface by the seat's amendment 6938684810. - Open question (not implemented, per the card): per-object narrowing. Measured in this repository at `144cdc25`: the only client-visible queue signal is the organization-wide boolean `hasAnyQueue` on `GET /auth/me/permissions` (no names, no counts, nothing per object), and the `queue` column is injected on every `ownership: 'user'` object. So no per-object signal exists to read without a new server reading; it stays the maintainer's ruling the card raises. ## Verification Round 1 readings below are against head `fc84516b` (base `144cdc25`). Round 2 (`79f051de`) adds only the docs sentence; its gate run is the last block. <details><summary>Tests</summary> Run from the repository root, `ui/` as vitest root, at `fc84516b`; each under `scripts/pm/os-verify-lock.sh`. - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-list/` → `Test Files 174 passed (174)`, `Tests 1863 passed (1863)`, lock `VERDICT command-exit 0`. - `pnpm --dir ui exec vitest run --reporter=verbose packages/plugin-list/src/__tests__/ListView.harness.test.tsx -t 34580` → the six `ListView.queueToggleOwnerPin-34580` tests listed ✓, `VERDICT command-exit 0`. - `pnpm --filter @object-ui/plugin-list type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`) → `VERDICT command-exit 0`. - `npx eslint src/ListView.tsx src/__tests__/ListView.harness.test.tsx` (from the package, as Lint UI runs it) → 0 errors (warnings only, all `no-explicit-any`, the harness's existing style). - `pnpm --dir ui run check:new-line-citations` → `0 new citation(s)`. - Closure built first: `npx turbo run build --filter='@object-ui/plugin-list^...' --concurrency=2` → `VERDICT command-exit 0`. </details> <details><summary>Ablation</summary> Two mutations through `node scripts/ablation-replace.mjs` (anchor hit 1 → 0, blob moved, restore proved by blob == HEAD and an empty `git diff HEAD`), each running `pnpm --dir ui exec vitest run packages/plugin-list/src/__tests__/ListView.harness.test.tsx -t 34580`. The subject is imported from source (`../ListView`), so no build sits between the mutation and the run. 1. `queueFilterOffered` without `&& !viewPinsOwner` → `Tests 2 failed | 4 passed`: "My Open Deals": no toggle… and switching views… went red. 2. The reset effect's `setSittingInQueueOnly(false)` replaced by `void 0` → `Tests 1 failed | 5 passed`: only switching views… went red (the toggle came back `aria-pressed="true"`). Both restored; `git diff HEAD` empty after each. </details> <details><summary>Derived gates</summary> `node scripts/pm/dispatch-gates.mjs --commands` (change set of 3 paths vs merge base `144cdc254`), each run at `fc84516b`, then `--ran` → `38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED`. ```text node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-sdui-manifest.mjs :: exit 0 node scripts/check-sdui-manifest.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --dir ui exec vitest run scripts/ :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm check:adr-anchors :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ``` `node scripts/pm/check-governed-merges.mjs --branch HEAD` → `0 of 3 path(s) hit the register`, NOT governed; size +218 / −4. </details> <details><summary>Round 2 derived gates (79f051d)</summary> After the docs commit the change set is 4 paths and `--commands` derives 70 families; all 70 were run at `79f051de`, each `:: exit 0`, and `--ran` reports 70 run, 0 NOT-MEASURED. The tree was 24 commits behind `origin/main` at derivation; per AGENTS.md section 10, `main` was not merged in (no conflict, no main-caused red). ```text node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-adr-links.mjs :: exit 0 node scripts/check-adr-links.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-doc-route-spelling.mjs --advisory :: exit 0 node scripts/check-doc-route-spelling.mjs --self-test :: exit 0 node scripts/check-docs-section-name.mjs :: exit 0 node scripts/check-docs-section-name.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-sdui-manifest.mjs :: exit 0 node scripts/check-sdui-manifest.mjs --self-test :: exit 0 node scripts/check-section-landing-index.mjs :: exit 0 node scripts/check-section-landing-index.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --dir ui exec vitest run scripts/ :: exit 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 pnpm --filter @objectstack/lint run check:doc-security-posture :: exit 0 pnpm --filter @objectstack/spec run check:docs :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:empty-state :: exit 0 pnpm --filter @objectstack/spec run check:liveness :: exit 0 pnpm --filter @objectstack/spec run check:skill-examples :: exit 0 pnpm --filter @objectstack/spec run check:strictness-ledger :: exit 0 pnpm --filter @objectstack/spec run check:variant-docs :: exit 0 pnpm --filter @objectstack/spec run check:yaml-examples :: exit 0 pnpm check:adr-anchors :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:corpus-claim-drift :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:doc-anchors :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:doc-frontmatter :: exit 0 pnpm check:docs-audit-scope :: exit 0 pnpm check:docs-redirects :: exit 0 pnpm check:docs-single-h1 :: exit 0 pnpm check:docs-spec-enumerations :: exit 0 pnpm check:docs-transcript-drift :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:published-files :: exit 0 pnpm check:published-readme-links :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:react-page-adapter-contract :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:role-word :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:vendor-version-stamps :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ``` </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (`packages/spec` untouched.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the two changed files: 0 errors.) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzgSfnXy1nRQDKzcsXw)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgSfnXy1nRQDKzcsXw --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent b86331d commit 0004e8d

4 files changed

Lines changed: 219 additions & 5 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/plugin-list': patch
3+
---
4+
5+
fix(plugin-list): the list toolbar no longer offers the "In a queue" toggle on a view whose own filter pins `owner_id`
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The "In a queue" toggle adds `owner_id is_empty` and `queue is_not_empty` to the list's query. On a view whose own filter already requires an owner, such as a "My records" view filtered by `owner_id equals {current_user_id}`, the two conditions contradict each other, so turning the toggle on always showed an empty list. The toggle is now withheld when the view's filter has a top-level AND condition on `owner_id` with `equals` (a non-empty value), `in` (a list of non-empty values) or `is_not_empty`. A condition inside an OR group does not count, because the other members of the group can still match unowned records.
11+
12+
While the toggle is withheld it adds nothing to the query. If it was on when the user switched to such a view, it is turned off, so switching back to a view that offers it shows it off.
13+
14+
Nothing changes on views without an owner condition, and no metadata or server behaviour changes.

‎content/docs/automation/queues-and-assignment-rules.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ A record **sits in** queue Q when its `owner_id` is empty and its `queue` column
117117

118118
The moment someone claims it, the queue path stops applying: the other members lose access unless another basis grants it. Ask the explain endpoint (`POST /api/v1/security/explain`) why a user sees a record and it reports the queue basis as its own reason (`queue_membership`) — see [Explaining a decision](/docs/permissions/explain).
119119

120-
In the Console, a list of an object that carries the `queue` column has an **In a queue** toggle in its toolbar. It narrows the list to parked records (`owner_id` empty and `queue` set); which of them you see is still the server's read filter, so a member sees what sits in their own queues.
120+
In the Console, a list of an object that carries the `queue` column has an **In a queue** toggle in its toolbar when your organization has at least one queue and the view's own filter does not require `owner_id` to hold a value (a top-level `equals`, `in` or `is_not_empty` condition on it, such as a "my records" view; one inside an OR group does not count), since a parked record has no owner. It narrows the list to parked records (`owner_id` empty and `queue` set); which of them you see is still the server's read filter, so a member sees what sits in their own queues.
121121

122122
## How a claim is spelled
123123

‎ui/packages/plugin-list/src/ListView.tsx‎

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { useDensityMode, resolveInlineAriaProps } from '@object-ui/react';
5151
import type { DataTableSchema, DependsOnInput, ListViewSchema, ObjectMapConfig } from '@object-ui/types';
5252
import { detectStatusField, isSystemManagedField } from '@object-ui/types';
5353
import { usePullToRefresh } from '@object-ui/mobile';
54-
import { type ListViewVisualization, resolveConditionalFormatting, buildExpandFields, buildExportFileName, resolveAffordance, type SchemaLike, partitionRowsByPredicate, normalizeListViewSchema, isListViewVisualization, rowHeightToDensityMode, mergeFilterNodes, FilterOperatorError, columnIdentity, collectPredicateFieldRefs, collectGroupingFieldRefs, listViewPredicates, PLATFORM_RECORD_COLUMNS, EXPANDABLE_FIELD_TYPES, UNMATERIALIZED_FIELD_TYPES, readObjectSortability, isPlatformSortableField, leadWithNameField, filterPlatformSortableSort, applyNonGridRowCeiling, type NonGridCeilingResult, resolveNameField, declaredNameField, resolveDependsOnFields, GANTT_CONFIG_SPELLING, kanbanDeclaredLanes, csvBlob } from '@object-ui/core';
54+
import { type ListViewVisualization, resolveConditionalFormatting, buildExpandFields, buildExportFileName, resolveAffordance, type SchemaLike, partitionRowsByPredicate, normalizeListViewSchema, isListViewVisualization, rowHeightToDensityMode, mergeFilterNodes, toFilterNodeSafely, FilterOperatorError, columnIdentity, collectPredicateFieldRefs, collectGroupingFieldRefs, listViewPredicates, PLATFORM_RECORD_COLUMNS, EXPANDABLE_FIELD_TYPES, UNMATERIALIZED_FIELD_TYPES, readObjectSortability, isPlatformSortableField, leadWithNameField, filterPlatformSortableSort, applyNonGridRowCeiling, type NonGridCeilingResult, resolveNameField, declaredNameField, resolveDependsOnFields, GANTT_CONFIG_SPELLING, kanbanDeclaredLanes, csvBlob } from '@object-ui/core';
5555
import { useObjectLabel, useSafeFieldLabel, createSafeTranslation, useDisplayLocale, pickLocalized, recordCurrencyField, recordCurrencyReadField } from '@object-ui/i18n';
5656
// Two resolvers, two vocabularies — the repo spells the distinction into the
5757
// NAMES (objectui#4167). `resolveInlineI18nLabel` is the spec's own
@@ -63,7 +63,7 @@ import { useObjectLabel, useSafeFieldLabel, createSafeTranslation, useDisplayLoc
6363
// (objectui#5134).
6464
import { resolveI18nLabel as resolveInlineI18nLabel, normalizeFilterOperator, PaginationConfigSchema } from '@objectstack/spec/ui';
6565
import type { GroupingConfig } from '@objectstack/spec/ui';
66-
import { isVirtualSearchField, platformProvisionsStorage, resolveInjectedSystemColumns, resolveSearchFieldResolution, type SearchFieldMeta } from '@objectstack/spec/data';
66+
import { canonicalAstOperator, isVirtualSearchField, platformProvisionsStorage, resolveInjectedSystemColumns, resolveSearchFieldResolution, type SearchFieldMeta } from '@objectstack/spec/data';
6767
import { SystemFieldName } from '@objectstack/spec/system';
6868
import { usePermissions } from '@object-ui/permissions';
6969
import { RecordDetailPanel } from '@object-ui/plugin-detail';
@@ -1072,6 +1072,51 @@ export function objectHasOwnershipQueue(objectDef: unknown): boolean {
10721072
return !!queue && typeof queue === 'object' && (queue as { system?: unknown }).system === true;
10731073
}
10741074

1075+
/**
1076+
* Does the view's own filter require `owner_id` to hold a value? Then no row it
1077+
* returns can sit in a queue, whose rows have no owner, and the "In a queue"
1078+
* toggle could only ever empty the list (objectstack#34580). An affordance is
1079+
* offered only where it can do something.
1080+
*
1081+
* Read on the filter as it goes to the wire: lowered by the shared
1082+
* `toFilterNode`, so a stored rule list, an AST and a MongoDB-style object all
1083+
* answer alike, and the operator folded by the spec's `canonicalAstOperator`.
1084+
* A condition counts only as a conjunct of the top-level AND (nested ANDs
1085+
* included): one inside an OR group leaves the other members free to return
1086+
* unowned rows. Three operators require a value: equality to a non-empty
1087+
* scalar, membership in a list of such, and `is_not_empty`. A filter the
1088+
* lowering refuses pins nothing here; the list answers it with its load error.
1089+
*/
1090+
export function viewFilterRequiresOwner(viewFilter: unknown): boolean {
1091+
const lowered = toFilterNodeSafely(viewFilter);
1092+
return lowered.ok && conjunctsOf(lowered.node).some(requiresOwnerValue);
1093+
}
1094+
1095+
const isAstGroup = (node: unknown[], logic: 'and' | 'or') =>
1096+
typeof node[0] === 'string' && node[0].toLowerCase() === logic && node.slice(1).every(Array.isArray);
1097+
1098+
/** The top-level AND's conjuncts: an `and` node's children, or an implicit-AND list's elements, flattened. */
1099+
function conjunctsOf(node: unknown): unknown[][] {
1100+
if (!Array.isArray(node) || node.length === 0) return [];
1101+
if (isAstGroup(node, 'and')) return node.slice(1).flatMap(conjunctsOf);
1102+
if (isAstGroup(node, 'or')) return [];
1103+
if (Array.isArray(node[0])) return node.flatMap(conjunctsOf);
1104+
return [node];
1105+
}
1106+
1107+
const isOwnerValue = (value: unknown) =>
1108+
value !== null && value !== undefined && value !== '' && typeof value !== 'object';
1109+
1110+
function requiresOwnerValue([field, operator, value]: unknown[]): boolean {
1111+
if (field !== SystemFieldName.OWNER_ID || typeof operator !== 'string') return false;
1112+
switch (canonicalAstOperator(operator)) {
1113+
case '=': return isOwnerValue(value);
1114+
case 'in': return Array.isArray(value) && value.every(isOwnerValue);
1115+
case 'is_not_empty': return true;
1116+
default: return false;
1117+
}
1118+
}
1119+
10751120
/**
10761121
* What `ListView` applies in place of a held user filter it withholds
10771122
* (`appliedFilters` / `appliedUserFilterConditions`, objectui#10512). Module
@@ -2578,11 +2623,19 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
25782623
// could only ever return an empty list. The flag rides the permissions
25792624
// answer the console already holds, so a list mount reads no queue list.
25802625
// An unknown answer (no provider, the role-based one, anonymous) hides it.
2626+
// Not offered on a view whose own filter pins `owner_id` to a value
2627+
// (`viewFilterRequiresOwner`, objectstack#34580): no row of it can sit in a
2628+
// queue. Withheld that way it contributes nothing and a pressed state is let
2629+
// go, so a view that offers it again shows it off rather than re-applying it.
25812630
// Withheld with the user filters on a dataset-bound chart. Ephemeral like
25822631
// the toolbar's other unpersisted toggles: it narrows what is on screen.
25832632
const [sittingInQueueOnly, setSittingInQueueOnly] = React.useState(false);
25842633
const { hasAnyQueue } = usePermissions();
2585-
const queueFilterOffered = hasAnyQueue === true && objectHasOwnershipQueue(objectDef);
2634+
const viewPinsOwner = React.useMemo(() => viewFilterRequiresOwner(authoredFilter), [authoredFilter]);
2635+
const queueFilterOffered = hasAnyQueue === true && objectHasOwnershipQueue(objectDef) && !viewPinsOwner;
2636+
React.useEffect(() => {
2637+
if (viewPinsOwner) setSittingInQueueOnly(false);
2638+
}, [viewPinsOwner]);
25862639
const appliedQueueSittingConditions =
25872640
queueFilterOffered && sittingInQueueOnly && !datasetChartOnScreen
25882641
? QUEUE_SITTING_CONDITIONS

‎ui/packages/plugin-list/src/__tests__/ListView.harness.test.tsx‎

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
} from '@object-ui/core';
6161
import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '@object-ui/permissions';
6262
import type { ListViewSchema } from '@object-ui/types';
63-
import { ListView, LIST_DEFAULT_TRANSLATIONS } from '../ListView';
63+
import { ListView, LIST_DEFAULT_TRANSLATIONS, viewFilterRequiresOwner } from '../ListView';
6464
import { filterNamesCurrentUser } from '../ListEmptyState';
6565

6666
/**
@@ -1420,6 +1420,153 @@ describe('ListView.printButtonSemantics', () => {
14201420
});
14211421
});
14221422

1423+
// ── ListView.queueToggleOwnerPin-34580 ──────────────────────────────────────
1424+
1425+
/**
1426+
* objectstack#34580 — the "In a queue" toggle (ADR-0142 D3) is withheld on a
1427+
* view whose own filter requires `owner_id` to hold a value. The toggle AND-s
1428+
* `owner_id is_empty`, so beside `owner_id equals {current_user_id}` (HotCRM's
1429+
* "My Open Deals") it could only ever empty the list. A condition inside an OR
1430+
* group does not pin. Withheld, the toggle adds nothing to the query, and a
1431+
* view that offers it again shows it off.
1432+
*
1433+
* The toggle's own offer rules (the injected column, `hasAnyQueue`, storage)
1434+
* are pinned in `ListView.queueSittingFilter-25769.test.tsx`.
1435+
*/
1436+
describe('ListView.queueToggleOwnerPin-34580', () => {
1437+
restoreAfterBlock();
1438+
1439+
const OBJECT = 'opportunity_34580';
1440+
const USER = 'u_34580';
1441+
const OWNER_IS_ME = { field: 'owner_id', operator: 'equals', value: '{current_user_id}' };
1442+
const STAGE_OPEN = { field: 'stage', operator: 'not_in', value: ['closed_won', 'closed_lost'] };
1443+
/** HotCRM's "My Open Deals" filter, as the view stores it. */
1444+
const MY_OPEN_DEALS = [OWNER_IS_ME, STAGE_OPEN];
1445+
/** "All Opportunities": no owner condition. */
1446+
const ALL_OPEN = [STAGE_OPEN];
1447+
1448+
const makeDataSource = () =>
1449+
({
1450+
find: vi.fn(async () => []),
1451+
findOne: vi.fn(),
1452+
create: vi.fn(),
1453+
update: vi.fn(),
1454+
delete: vi.fn(),
1455+
getObjectSchema: vi.fn(async () => ({
1456+
name: OBJECT,
1457+
fields: {
1458+
name: { name: 'name', type: 'text' },
1459+
stage: { name: 'stage', type: 'select' },
1460+
owner_id: { name: 'owner_id', type: 'lookup' },
1461+
queue: { name: 'queue', type: 'text', system: true, hidden: true },
1462+
},
1463+
})),
1464+
}) as any;
1465+
1466+
const session: MePermissionsAuthenticatedResponse = {
1467+
authenticated: true,
1468+
userId: USER,
1469+
tenantId: 'org_34580',
1470+
hasAnyQueue: true,
1471+
positions: [],
1472+
permissionSets: ['member_default'],
1473+
objects: { [OBJECT]: { allowRead: true, allowCreate: true, allowEdit: true, allowDelete: true } },
1474+
fields: {},
1475+
};
1476+
1477+
const tree = (dataSource: any, filter: unknown) => {
1478+
const schema = { type: 'list-view', objectName: OBJECT, columns: ['name', 'stage'], filter } as unknown as ListViewSchema;
1479+
return (
1480+
<SchemaRendererProvider dataSource={dataSource}>
1481+
<FilterScopeProvider currentUserId={USER}>
1482+
<MePermissionsProvider initialPermissions={session}>
1483+
<ListView schema={schema} dataSource={dataSource} />
1484+
</MePermissionsProvider>
1485+
</FilterScopeProvider>
1486+
</SchemaRendererProvider>
1487+
);
1488+
};
1489+
1490+
const lastFilter = (dataSource: any) => JSON.stringify(dataSource.find.mock.calls.at(-1)?.[1]?.$filter ?? null);
1491+
const QUEUE_SITTING = '["owner_id","is_empty",true],["queue","is_not_empty",true]';
1492+
1493+
/** A mount that renders no toggle: wait for the definition and a query built after it. */
1494+
async function settled(dataSource: any) {
1495+
await waitFor(() => expect(dataSource.getObjectSchema).toHaveBeenCalled());
1496+
await waitFor(() => expect(dataSource.find).toHaveBeenCalled());
1497+
}
1498+
1499+
afterEach(() => cleanup());
1500+
1501+
describe('viewFilterRequiresOwner — a top-level AND condition that needs a value', () => {
1502+
it('pins on equals, in and is_not_empty, in every filter shape the list lowers', () => {
1503+
expect(viewFilterRequiresOwner([{ field: 'owner_id', operator: 'equals', value: USER }, STAGE_OPEN])).toBe(true);
1504+
expect(viewFilterRequiresOwner([{ field: 'owner_id', operator: 'in', value: [USER, 'u2'] }])).toBe(true);
1505+
expect(viewFilterRequiresOwner([{ field: 'owner_id', operator: 'is_not_empty' }])).toBe(true);
1506+
expect(viewFilterRequiresOwner(['owner_id', '=', USER])).toBe(true);
1507+
expect(viewFilterRequiresOwner(['and', ['stage', '=', 'open'], ['and', ['owner_id', 'eq', USER]]])).toBe(true);
1508+
expect(viewFilterRequiresOwner([['stage', '=', 'open'], ['owner_id', 'isNotEmpty', true]])).toBe(true);
1509+
expect(viewFilterRequiresOwner({ owner_id: USER, stage: 'open' })).toBe(true);
1510+
});
1511+
1512+
it('does not pin inside an OR group, nor on a condition an unowned row can meet', () => {
1513+
expect(viewFilterRequiresOwner([{ or: [OWNER_IS_ME, { field: 'stage', operator: 'equals', value: 'new' }] }])).toBe(false);
1514+
expect(viewFilterRequiresOwner(['or', ['owner_id', '=', USER], ['stage', '=', 'new']])).toBe(false);
1515+
expect(viewFilterRequiresOwner([{ field: 'owner_id', operator: 'not_equals', value: USER }])).toBe(false);
1516+
expect(viewFilterRequiresOwner([{ field: 'owner_id', operator: 'is_empty' }])).toBe(false);
1517+
expect(viewFilterRequiresOwner(['owner_id', '=', null])).toBe(false);
1518+
expect(viewFilterRequiresOwner(['owner_id', 'in', [USER, null]])).toBe(false);
1519+
expect(viewFilterRequiresOwner(ALL_OPEN)).toBe(false);
1520+
expect(viewFilterRequiresOwner(undefined)).toBe(false);
1521+
});
1522+
});
1523+
1524+
describe('ListView — the toggle on a view that pins the owner (objectstack#34580)', () => {
1525+
it('"My Open Deals": no toggle, and the query carries no queue condition', async () => {
1526+
const dataSource = makeDataSource();
1527+
render(tree(dataSource, MY_OPEN_DEALS));
1528+
await settled(dataSource);
1529+
await waitFor(() => expect(lastFilter(dataSource)).toContain(USER));
1530+
expect(screen.queryByTestId('queue-sitting-filter')).toBeNull();
1531+
expect(lastFilter(dataSource)).not.toContain('is_empty');
1532+
});
1533+
1534+
it('"All Opportunities": the toggle, and pressing it still narrows to the rows sitting in a queue', async () => {
1535+
const dataSource = makeDataSource();
1536+
render(tree(dataSource, ALL_OPEN));
1537+
const toggle = await screen.findByTestId('queue-sitting-filter');
1538+
expect(toggle.getAttribute('aria-pressed')).toBe('false');
1539+
fireEvent.click(toggle);
1540+
await waitFor(() => expect(lastFilter(dataSource)).toContain(QUEUE_SITTING));
1541+
expect(lastFilter(dataSource)).toContain('closed_won');
1542+
});
1543+
1544+
it('an owner condition inside an OR group keeps the toggle', async () => {
1545+
const dataSource = makeDataSource();
1546+
render(tree(dataSource, [{ or: [OWNER_IS_ME, { field: 'stage', operator: 'equals', value: 'new' }] }]));
1547+
expect(await screen.findByTestId('queue-sitting-filter')).toBeTruthy();
1548+
});
1549+
1550+
it('switching views: a pressed toggle leaves no hidden filter on the pinned view, and comes back off', async () => {
1551+
const dataSource = makeDataSource();
1552+
const { rerender } = render(tree(dataSource, ALL_OPEN));
1553+
fireEvent.click(await screen.findByTestId('queue-sitting-filter'));
1554+
await waitFor(() => expect(lastFilter(dataSource)).toContain(QUEUE_SITTING));
1555+
1556+
rerender(tree(dataSource, MY_OPEN_DEALS));
1557+
await waitFor(() => expect(lastFilter(dataSource)).toContain(USER));
1558+
expect(screen.queryByTestId('queue-sitting-filter')).toBeNull();
1559+
expect(lastFilter(dataSource)).not.toContain('is_empty');
1560+
1561+
rerender(tree(dataSource, ALL_OPEN));
1562+
await waitFor(() => expect(lastFilter(dataSource)).not.toContain(USER));
1563+
const toggle = await screen.findByTestId('queue-sitting-filter');
1564+
expect(toggle.getAttribute('aria-pressed')).toBe('false');
1565+
expect(lastFilter(dataSource)).not.toContain('is_empty');
1566+
});
1567+
});
1568+
});
1569+
14231570
// ── ListView.refreshIndicatorLocale-10580 ───────────────────────────────────────
14241571

14251572
/**

0 commit comments

Comments
 (0)