Skip to content

Commit

Permalink
fix: Expressions display actual result of evaluating expression insid…
Browse files Browse the repository at this point in the history
…e string (#11257)

Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
  • Loading branch information
michael-radency and ShireenMissi authored Oct 16, 2024
1 parent e7a4b0d commit 7f5f0a9
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions packages/editor-ui/src/composables/useExpressionEditor.ts
Original file line number Diff line number Diff line change
@@ -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 (/\[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) {}
}

if (typeof s.resolved === 'string' && /\[Array:\s\[.+\]\]/.test(s.resolved)) {
s.resolved = s.resolved.replace(/(\[Array: \[|\])/g, '');
s.resolved = resolved;
}

return s;

0 comments on commit 7f5f0a9

Please sign in to comment.