fix: Expressions display actual result of evaluating expression inside string (#11257)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions

Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
This commit is contained in:
Michael Kret 2024-10-16 13:27:00 +03:00 committed by GitHub
parent e7a4b0da01
commit 7f5f0a9df3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -352,6 +352,12 @@ export const useExpressionEditor = ({
* - `This is a {{ [] }} test` displays as `This is a test`.
* - `{{ [] }}` displays as `[Array: []]`.
*
* - `This is a {{ {} }} test` displays as `This is a [object Object] test`.
* - `{{ {} }}` displays as `[Object: {}]`.
*
* - `This is a {{ [{}] }} test` displays as `This is a [object Object] test`.
* - `{{ [] }}` displays as `[Array: []]`.
*
* Some segments display differently based on context:
*
* Date displays as
@ -366,13 +372,29 @@ export const useExpressionEditor = ({
.map((s) => {
if (cachedSegments.length <= 1 || s.kind !== 'resolvable') return s;
if (typeof s.resolved === 'string' && /\[Object: "\d{4}-\d{2}-\d{2}T/.test(s.resolved)) {
const utcDateString = s.resolved.replace(/(\[Object: "|\"\])/g, '');
s.resolved = new Date(utcDateString).toString();
}
if (typeof s.resolved === 'string') {
let resolved = s.resolved;
if (typeof s.resolved === 'string' && /\[Array:\s\[.+\]\]/.test(s.resolved)) {
s.resolved = s.resolved.replace(/(\[Array: \[|\])/g, '');
if (/\[Object: "\d{4}-\d{2}-\d{2}T/.test(resolved)) {
const utcDateString = resolved.replace(/(\[Object: "|\"\])/g, '');
resolved = new Date(utcDateString).toString();
}
if (/\[Object:\s(\{.+\}|\{\})\]/.test(resolved)) {
resolved = resolved.replace(/(\[Object: |\]$)/g, '');
try {
resolved = String(JSON.parse(resolved));
} catch (error) {}
}
if (/\[Array:\s\[.+\]\]/.test(resolved)) {
resolved = resolved.replace(/(\[Array: |\]$)/g, '');
try {
resolved = String(JSON.parse(resolved));
} catch (error) {}
}
s.resolved = resolved;
}
return s;