Repository navigation
Read visibility rule text through the shared expression parser - #32379
FelixMalfait wants to merge 4 commits into
Conversation
Visibility rules on page layout tabs and widgets were read from text by a separate parser that kept field names as written and could not print a field back. They now go through the parser that formula fields and validation rules use: `currentRecord.stage` resolves to the field's identifier, the same node the filter builder writes, so a rename keeps the rule and the builder can open it. A path naming no field is refused. - resolveExpressionFieldReferences takes the variables that hold a record, so fields are only read through them, never by bare name. - printExpressionNode writes a field's record variable before its name, and printConditionalEvaluationNode takes the fields to name them. - The strict parser and its own length limit are removed from twenty-shared. - The 2.63 upgrade command keeps the old parser in its version folder, through a new parseExpressionNodeWithParser. Claude-Session: https://claude.ai/code/session_01BC19MSAJVo6nHzxVuvKd9y
28f93a4 to
14bb41d
Compare
|
This is intended. The visibility-rule parser leaves The guard clears with the Generated by Claude Code |
| "dotenv": "16.4.5", | ||
| "email-reply-parser": "^2.3.5", | ||
| "entities": "^4.5.0", | ||
| "esbuild": "^0.28.1", | ||
| "expr-eval-fork": "3.0.3", |
There was a problem hiding this comment.
why would we need this now?
There was a problem hiding this comment.
We didn't need it. It was only there because the frozen 2.63 parser built an expr-eval-fork Parser itself. Fixed in aa8759f: parseExpressionNodeWithParser in twenty-shared now takes plain parser options (plus consts and functions) and builds the Parser itself. The 2-63 folder only keeps an options object, so twenty-server no longer imports the library, and its dependency and lockfile line are gone.
Generated by Claude Code
🤖 PR Review
🛡️ Security Review✅ No high-severity vulnerabilities detected. 🚦 Auto-approve🙋 Manual review recommended for the following reason(s):
Automated pre-review — human approval still required. |
🟡 Quality review · 5 findings
High-level — Resolving currentRecord fields in the shared rule parser fits the existing FIELD-node evaluator, and its one production caller is updated; the open points are that the frozen 2.63 copy still depends on live shared helpers, and a public twenty-shared export exists only for that copy. 💬 5 inline comments on the diff. Reviewed against the |
| import { | ||
| type ConditionalEvaluationNode, | ||
| validateConditionalEvaluationNode, | ||
| } from 'twenty-shared/conditional-evaluation'; |
There was a problem hiding this comment.
🟡 Nit · High-level · upgrade commands
The 'frozen' 2.63 legacy parser still runs on live twenty-shared code (validateConditionalEvaluationNode, parseExpressionNodeWithParser → toExpressionNodeParseResult, CONDITIONAL_EVALUATION_FUNCTIONS)
A later change to those shared helpers silently changes how the 2.63 command reads legacy rules, so the copy does not freeze what it claims to freeze. Either copy the tree conversion and validation it needs into the version folder too, or state in the PR which parts are frozen and which are not.
| import { toExpressionNodeParseResult } from '@/expression/utils/internal/toExpressionNodeParseResult'; | ||
| import { getExpressionSyntaxError } from '@/utils/expression/getExpressionSyntaxError'; | ||
|
|
||
| // For a format the shared parser no longer reads, such as an upgrade command's legacy rules |
There was a problem hiding this comment.
🟡 Nit · High-level · right altitude
twenty-shared gains a new public export, parseExpressionNodeWithParser, whose only consumer is the 2-63 upgrade command
Its comment ties a long-lived shared API to one version folder's legacy format, and it keeps that command coupled to twenty-shared internals. Keep the helper inside the 2-63 utils folder with the frozen parser instead of exporting it from twenty-shared/utils.
|
|
||
| export type ConditionalEvaluationConfiguration = { | ||
| variables: Record<string, true>; | ||
| // Variables holding a record, whose fields text names as currentRecord.stage |
There was a problem hiding this comment.
🟡 Nit · Low-level · Every added comment passes the deletion test
The added comment restates what the field is for, and a name like recordVariables with the type already conveys that, so removing it loses nothing.
There was a problem hiding this comment.
| import { getExpressionNodeChildren } from '@/expression/utils/internal/getExpressionNodeChildren'; | ||
| import { isDefined } from '@/utils/validation/isDefined'; | ||
|
|
||
| // Names the first computation a rule cannot hold, as the shared parser accepts formulas |
There was a problem hiding this comment.
🟡 Nit · Low-level · Every added comment passes the deletion test
The added comment paraphrases what the function name and return type already state (it names the first unsupported computation), so deleting it loses nothing the code cannot say.
| }: { | ||
| expression: string | null | undefined; | ||
| metadataName: ConditionalEvaluationMetadataName; | ||
| // Fields of the object the rule reads through its record variables |
There was a problem hiding this comment.
🟡 Nit · Low-level · Every added comment passes the deletion test
The added comment on the fields parameter only restates what the name and type already convey, so deleting it loses nothing.
| : undefined; | ||
| }; | ||
|
|
||
| // A path naming no field is kept as written, so the expression still reports it as unknown. |
There was a problem hiding this comment.
🟡 Nit · Low-level · A kept comment is one line
The added comment is split across two consecutive // lines, but the rule allows multi-line comments only when a single line cannot state the reason.
Also on line 96.
There was a problem hiding this comment.
Confidence Score: 4/5
[Medium impact] The changes reach page-layout visibility rules and the 2.63 upgrade path. The PR appears safe to merge, with a non-blocking issue in how invalid record-field paths are accepted. Findings
SummaryVisibility-rule text now uses the shared expression parser and stores record fields by stable identifiers.
Tests were not run during this review. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Visibility rule text] --> B[Shared expression parser]
B --> C[Resolve record fields to stable identifiers]
C --> D[Check allowed nodes and names]
D --> E[Stored rule tree]
E --> F[Print current field names]
G[2.63 legacy rule text] --> H[Frozen legacy parser]
H --> D
Reviews (1) · Last reviewed commit: "Read visibility rule text through the sh..." · Reviewed by Greptile |
| const fieldNode = toFieldNode({ path: fieldSegments.join('.'), fields }); | ||
|
|
||
| return isDefined(fieldNode) | ||
| ? { ...fieldNode, record: recordVariableName } |
There was a problem hiding this comment.
toRecordVariableFieldNode accepts partial field matches. With an amount currency field, currentRecord.amount.amountMicros.extra > 0 becomes a rule for amount.amountMicros; .extra silently disappears. A misspelled subfield such as currentRecord.amount.amuntMicros also passes validation.
The later unknown-field check only checks remaining VARIABLE nodes, so neither error is caught. Check the full path, including subfield names and depth, before converting it to a field node.
Knowledge Base Used: Shared domain contracts and utilities
There was a problem hiding this comment.
Fixed in 8ddbc02: before resolving, each currentRecord.… path now goes through resolveExpressionIdentifierPath, the same check formulas use. Unknown or too-deep subfields, unknown relation targets, to-many relations and previous/now all fail now, and each case has a test.
Generated by Claude Code
| }; | ||
| } | ||
|
|
||
| return isDefined(resolution.toManyRelationName) |
There was a problem hiding this comment.
🟡 Nit · Low-level · Return early
The function ends in a multi-line ternary that returns a seven-line error object literal, which should be an early return instead.
Also on lines 60–66.
There was a problem hiding this comment.
|
Generated by Claude Code |
🔍 Visual Regression Review —
|
| Story | Verdict | Confidence | Explained by | |
|---|---|---|---|---|
| 🟡 | modules-gettingstarted-gettingstartedpagecontent--optimistic-app-install |
uncertain | 60% | none |
| 🟡 | modules-ai-aichattab--open-original-from-reply |
uncertain | 65% | none |
| 🟡 | modules-settings-applications-settingsapplicationiframemediapermissionssection--… |
uncertain | 65% | none |
| 🟡 | modules-onboarding-onboardingactivationsteps--default |
uncertain | 50% | none |
| 🟡 | modules-pagelayout-widgets-recordpagenotewidget--align-text |
uncertain | 50% | none |
| 🟡 | modules-sidepanel-recordcreationflow--retry-after-failed-creation |
uncertain | 50% | none |
| 🟡 | modules-sidepanel-recordcreationflow--submit-with-button |
uncertain | 50% | none |
| 🟡 | modules-sidepanel-recordcreationflow--submit-with-command-enter |
uncertain | 50% | none |
| 🟡 | modules-sidepanel-recordcreationflow--submit-with-control-enter |
uncertain | 50% | none |
| 🟡 | modules-sidepanel-snoozeaichat--day-and-time-picker |
uncertain | 50% | none |
| 🟡 | modules-sidepanel-composerpages--calendar-event-without-account-permission |
uncertain | 50% | none |
| 🟡 | modules-sidepanel-composerpages--calendar-event-without-accounts |
uncertain | 50% | none |
| 🟡 | modules-sidepanel-composerpages--calendar-event |
uncertain | 50% | none |
Changed stories
| Story | Diff % |
|---|---|
| modules-gettingstarted-gettingstartedpagecontent--optimistic-app-install | 9% |
| modules-ai-aichattab--open-original-from-reply | 3% |
| modules-settings-applications-settingsapplicationiframemediapermissionssection--does-not-apply-rejected-approval | 2% |
| modules-onboarding-onboardingactivationsteps--default | 1% |
| modules-pagelayout-widgets-recordpagenotewidget--align-text | 1% |
| pages-settings-mcpservers-settingsaimcpserverdetail--default | 0% |
| pages-settings-mcpservers-settingsaimcpserverdetail--member-without-connection-starts-the-sign-in | 0% |
| pages-settings-mcpservers-settingsaimcpserverdetail--shared-sign-in-shows-no-member-section | 0% |
| pages-settings-mcpservers-settingsaimcpserverdetail--signed-in-member-sees-only-their-connection-to-this-server | 0% |
| pages-settings-mcpservers-settingsaimcpserverdetail--sign-in-load-error-offers-retry | 0% |
| pages-settings-mcpservers-settingsaimcpserverdetail--sign-in-shows-when-the-cached-providers-predate-the-server | 0% |
| modules-sidepanel-recordcreationflow--submit-with-button | 0% |
| modules-sidepanel-recordcreationflow--submit-with-command-enter | 0% |
| modules-sidepanel-composerpages--calendar-event-without-account-permission | 0% |
| modules-sidepanel-composerpages--calendar-event-without-accounts | 0% |
| modules-sidepanel-recordcreationflow--retry-after-failed-creation | 0% |
| modules-sidepanel-recordcreationflow--submit-with-control-enter | 0% |
| modules-sidepanel-snoozeaichat--day-and-time-picker | 0% |
| modules-sidepanel-composerpages--calendar-event | 0% |
| modules-activities-emails-chatthreadmessagegroup--voice-note | 0% |
| pages-settings-mcpservers-settingsaimcpserverdetail--sync-keeps-unsaved-edits | 0% |
| modules-activity-taskgroups--empty | 0% |
| modules-activities-files-videopreview--player | 0% |
| modules-ai-aichattab--reply-to-teammate | 0% |
| modules-pagelayout-widgets-callrecordingtranscriptbody--audio-seek-interactions | 0% |
View run details · advisory mode
🔍 Visual Regression Review —
|
| Story | Verdict | Confidence | Explained by | |
|---|---|---|---|---|
| 🟡 | ui-components-codeeditor--display |
uncertain | 50% | — |
| 🟡 | ui-components-codeeditor--auto-height |
uncertain | 60% | — |
| 🟡 | ui-components-codeeditor--model-lifecycle |
uncertain | 55% | — |
| 🟡 | ui-components-codeeditor--default |
uncertain | 60% | — |
| 🟡 | ui-components-codeeditor--editing |
uncertain | 55% | — |
| 🟡 | ui-components-codeeditor--theme-precedence |
uncertain | 55% | — |
| 🟡 | ui-components-codeeditor--dark |
uncertain | 55% | — |
| 🟡 | ui-components-codeeditor--bounded-resizable |
uncertain | 55% | — |
| 🟡 | ui-components-codeeditor--css-height-resizable |
uncertain | 55% | — |
| 🟡 | ui-components-codeeditor--resizable |
uncertain | 55% | — |
Changed stories
| Story | Diff % |
|---|---|
| ui-components-codeeditor--display | 5% |
| ui-components-codeeditor--default | 1% |
| ui-components-codeeditor--auto-height | 1% |
| ui-components-codeeditor--model-lifecycle | 1% |
| ui-components-codeeditor--dark | 0% |
| ui-components-codeeditor--bounded-resizable | 0% |
| ui-components-codeeditor--css-height-resizable | 0% |
| ui-components-codeeditor--editing | 0% |
| ui-components-codeeditor--theme-precedence | 0% |
| ui-components-codeeditor--resizable | 0% |
| ui-components-codeeditor--controlled-value | 0% |
View run details · advisory mode
|
Auto-closed: this PR is draft and has had no update in over 24 hours. Please reopen it once you have the bandwidth to take it forward. |
Visibility rules on page layout tabs and widgets were read from text by their own parser. That parser kept field names as written and could not print a field back, so a rule written as text referenced fields by name: a rename broke it silently, the server never checked the field existed, and the filter builder could not open it.
Text rules now go through the parser that formula fields and validation rules already use.
currentRecord.stage == "PROPOSAL"becomes the same field node the filter builder writes, keyed by the field's universal identifier. So a rename keeps the rule, the builder can open it, and printing shows the current name.This is the groundwork for letting app manifests write visibility rules as text and having
twenty app pullprint them as text. Today apps must write the raw tree.Changes
resolveExpressionFieldReferencestakesrecordVariableNames. With it, fields are only read through those variables (currentRecord.stage), never by bare name, so a custom field nameddevicecannot shadow thedevicevariable. Visibility rules declare their record variables inConditionalEvaluationConfiguration.recordVariables. Formulas, validation rules and the 2.65 command do not pass it and behave as before.printExpressionNodewrites a field's record variable before its name.printConditionalEvaluationNodetakes the fields to name them; it threw on any field node before.parseConditionalEvaluationExpressiontakes the fields of the object the rule reads, and refuses:currentRecord.stag;stage.Operators a rule cannot hold still report
Unexpected "+".Removed
conditionalEvaluationStrictParser,toConditionalEvaluationNodeandCONDITIONAL_EVALUATION_EXPRESSION_MAX_LENGTH; rules use the sharedEXPRESSION_MAX_LENGTH, also 2000.Built-in widget rules are read with no fields. None names a field today, so one that does fails at build time.
The 2.63 upgrade command
The shared parser reads
length,round,abs,ceil,floorandtruncas operators, soselectedRecords.length > 0no longer parses. The old parser read them as names. Self-hosters can still upgrade through 2.63, so its command keeps the old parser in its version folder, with its settings copied unchanged. Supporting changes:twenty-serverdeclaresexpr-eval-forkdirectly (same 3.0.3, one lockfile line).twenty-sharedgains a genericparseExpressionNodeWithParser; the tokens-to-tree converter stays internal.A temporary test, not committed, compared the old parser with the frozen copy on 64 rules, including the members above. Every rule was accepted or refused the same way and built the same tree. A spec in
2-63/utils/__tests__covers the main cases.Testing
devicecollision, and printing after a rename.tsgo --noEmitclean in both packages, apart from server imports oftwenty-emails,twenty-client-sdkandtwenty-sdk, which were not built in the environment.twenty-frontcalls the changed functions.https://claude.ai/code/session_01BC19MSAJVo6nHzxVuvKd9y
Generated by Claude Code