feat: convert value when toggling between expression and raw mode #4087#4094
feat: convert value when toggling between expression and raw mode #4087#4094Julusian wants to merge 5 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds two expression helpers for literal conversion and static extraction, a modal to preview/confirm converting expressions to values using a live subscription, and integrates extraction + modal into field components so toggling from expression to value preserves plain literals when possible. Changes
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
shared-lib/lib/Expression/ExpressionParse.ts (1)
50-54: Consider handlingundefinedexplicitly since it's not a validJsonValue.The comment on line 52 mentions that
undefinedis patched in byfixupExpression. Sinceundefinedis technically not part of theJsonValuetype fromtype-fest, you might want to handle it explicitly to make the type assertion cleaner. That said, the current approach will work in practice since the consuming code inFieldOrExpressionhandlesJsonValue | undefined.Just a thought — if you'd prefer to keep it as-is for simplicity, that's totally fine too! 🙂
💡 Optional: Explicit undefined handling
export function tryExtractExpressionPlainValue(node: SomeExpressionNode): { value: JsonValue } | null { if (node.type === 'Literal') { - // jsep Literal values are string | number | boolean | null (undefined is patched in by fixupExpression) - return { value: node.value as JsonValue } + // jsep Literal values are string | number | boolean | null | undefined + // undefined is patched in by fixupExpression for the `undefined` identifier + const literalValue = node.value + if (literalValue === undefined) return { value: null } + return { value: literalValue as JsonValue } }shared-lib/lib/__tests__/expressions-parse.test.ts (1)
1137-1202: Excellent test coverage for the plain value extraction! 🎉The tests thoroughly cover the happy path scenarios including edge cases like zero, empty arrays/objects, and nested structures. Really nice work here!
One small suggestion — you might consider adding a test case for the
undefinedliteral sincefixupExpressionpatches that in as a special case:it('undefined', () => { expect(tryExtractExpressionPlainValue(ParseExpression('undefined'))).toEqual({ value: undefined }) })This would help document the expected behavior and catch any regressions if the
undefinedhandling changes.webui/src/Components/ExpressionConversionModal.tsx (2)
52-56: Consider disabling the confirm button while evaluation is in progress.If the user clicks "Use computed value" before the subscription has emitted any data,
latestDataRef.currentwill beundefined, and the confirm will set the value toundefined. This might be unexpected behavior — the user might think they're getting the computed result.You could either disable the button until data arrives, or show a more explicit warning. Just a thought to improve the UX! 🙂
💡 Suggested improvement
<CButton color="secondary" onClick={onCancel}> Cancel </CButton> - <CButton color="primary" onClick={doConfirm}> + <CButton color="primary" onClick={doConfirm} disabled={!displayData}> Use computed value </CButton>
96-103: Small observation about button styling.The PR description image shows a red "Use computed value" button, but the code uses
color="primary"(typically blue in CoreUI). If the red styling was intentional (perhaps to emphasize that this is a destructive action), you might want to usecolor="danger"instead. But if the screenshot is just outdated mockup, no worries!
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1b9f5244-a4e0-468d-ad56-7030d4e95665
📒 Files selected for processing (5)
shared-lib/lib/Expression/ExpressionParse.tsshared-lib/lib/__tests__/expressions-parse.test.tswebui/src/Components/ExpressionConversionModal.tsxwebui/src/Components/FieldOrExpression.tsxwebui/src/Controls/OptionsInputField.tsx
|
Should the modal have 3rd option beyond cancel and use computed value? I feel like there should be; like a select / enter alternate value. But I don't know of the top of my head when one might want to use this. |
Wouldn't that just be cancelling and the user entering a different value? |
|
I think this needs some more thought, and trial and error and I dont want to delay 4.3.0 for it. hopefully it can be done for 4.3.1 After looking into this more, there is some ambiguity on how it should behave:
And I am not entirely happy with how this modal is looking, I am not sure how to present the bits of data in a friendly way. it should contain some amount of:
So I am thinking that a first iteration of this could skip touching textinput fields, but there is still some unknowns and testing that needs to be tackled for the rest and I don't want to delay 4.3.0 any longer than it already is If anyone feels like doing some sketches/patches for the layout of this modal, I welcome the input; that is the part that I will feel blocked on shortly. |
00ed65d to
afe0f6f
Compare
|
A note for me to return to; this was on develop for some graphics field and should be used for inspiration on transforms here |
closes #4087
When toggling a field between expression and value mode, this will now explicitly convert it between the expression string and the value.
If it encounters a plain value, the field will be switched quietly, but if it contains an expression doing anything more than just a literal value/object, then it will show a modal to require confirmation before replacing the expression the user has written
Not 100% happy with the styling of the modal, but its better than nothing:
Summary by CodeRabbit
New Features
Tests