From 0cf45bc4c862c7544e69af4981d4607bf0b530e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milorad=20FIlipovi=C4=87?= Date: Wed, 15 Feb 2023 10:50:16 +0100 Subject: [PATCH] fix(core): Fix data transformation function that are reported not to work properly (#5338) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :fire: Remove test extensions * :construction: Add test description * :blue_book: Expand types * :zap: Export extensions * :zap: Export collection * :zap: Mark all proxies * :pencil2: Rename for clarity * :zap: Export from barrel * :sparkles: Create datatype completions * :zap: Mount datatype completions * :test_tube: Adjust tests * :zap: Add `path` prop * :fire: Remove `()` from completion labels * :zap: Filter out completions for pseudo-proxies * :bug: Fix method error * :zap: Add metrics * :pencil2: Improve naming * :sparkles: Start completion on empty resolvable * :sparkles: Implement completion previews * :zap: Break out completion manager * :zap: Implement in expression editor modal * :pencil2: Improve naming * :zap: Filter out irrelevant completions * :sparkles: Add preview hint * :pencil2: Improve comments * :art: Style preview hint * :zap: Expand `hasNoParams` * :zap: Add spacing for readability * :zap: Add error codes * :pencil2: Add comment * :bug: Fix Esc behavior * :zap: Parse Unicode * :zap: Throw on invalid `DateTime` * :zap: Fix second root completion detection * :zap: Switch message at completable prefix position * :bug: Fix function names for non-dev build * :bug: Fix `json` handling * :fire: Comment out previews * :recycle: Apply feedback * :fire: Remove extensions * :truck: Rename extensions * :zap: Adjust some implementations * :fire: Remove dummy extensions * :bug: Fix object regex * :recycle: Apply feedback * :pencil2: Fix typos * :pencil2: Add `fn is not a function` message * :fire: Remove check * :sparkles: Add `isNotEmpty` for objects * :truck: Rename `global` to `alpha` * :fire: Remove `encrypt` * :zap: Restore `is not a function` error * :zap: Support `week` on `extract()` * :test_tube: Fix tests * :zap: Add validation to some string extensions * :zap: Validate number arrays in some extensions * :test_tube: Fix tests * :pencil2: Improve error message * :rewind: Revert extensions framework changes * :broom: Previews cleanup * :zap: Condense blank completions * :zap: Refactor dollar completions * :zap: Refactor non-dollar completions * :zap: Refactor Luxon completions * :zap: Refactor datatype completions * :zap: Use `DATETIMEUNIT_MAP` * :pencil2: Update test description * :rewind: Revert "Use `DATETIMEUNIT_MAP`" This reverts commit 472a77df5cd789905d162f3c3db02ac767b89b4e. * :test_tube: Add tests * :recycle: Restore generic extensions * :fire: Remove logs * :test_tube: Expand tests * :sparkles: Add `Math` completions * :pencil2: List breaking change * :zap: Add doc tooltips * :bug: Fix node selector regex * :bug: Fix `context` resolution * :bug: Allow dollar completions in args * :zap: Make numeric array methods context-dependent * :pencil: Adjust docs * :bug: Fix selector ref * :zap: Surface error for valid URL * :bug: Disallow whitespace in `isEmail` check * :test_tube: Fix test for `isUrl` * :zap: Add comma validator in `toFloat` * :zap: Add validation to `$jmespath()` * :rewind: Revert valid URL error * :zap: Adjust `$jmespath()` validation * :test_tube: Adjust `isUrl` test * :zap: Remove `{}` and `[]` from compact * :pencil2: Update docs * :truck: Rename `stripTags` to `removeTags` * :zap: Do not inject whitespace inside resolvable * :zap: Make completions aware of `()` * :pencil2: Add note * :zap: Update sorting * :zap: Hide active node name from node selector * :fire: Remove `length()` and its aliases * :zap: Validate non-zero for `chunk` * :pencil2: Reword all error messages * :bug: Fix `$now` and `$today` * :zap: Simplify with `stripExcessParens` * :zap: Fold luxon into datatype * :test_tube: Clean up tests * :fire: Remove tests for removed methods * :shirt: Fix type * :arrow_up: Upgrade lang pack * :rewind: Undo change to `vitest` command * :fire: Remove unused method * :zap: Separate `return` line * :pencil2: Improve description * :test_tube: Expand tests for initial-only completions * :test_tube: Add bracket-aware completions * :zap: Make check for `all()` stricter * :pencil2: Adjust explanatory comments * :fire: Remove unneded copy * :fire: Remove outdated comment * :zap: Make naming consistent * :pencil2: Update comments * :zap: Improve URL scheme check * :pencil2: Add comment * :truck: Move extension * :pencil2: Update `BREAKING-CHANGES.md` * :pencil2: Update upcoming version * :pencil2: Fix grammar * :pencil2: Shorten message * :bug: Fix `Esc` behavior * :bug: Fix `isNumeric` * ✨ Using UTC to handle-dates on back-end * ✅ Added more unit tests for date extensions * ⚡ Not using `JSON.stringify` to render dates * ⚡ Using `deep-equal` library instead of our `deepCompare` function * ✅ Adding more tests to array extensions * ⚡ Fixing `inBetween` extension function * ✅ Added tests for `.inBetween()` * ⚡ Updating `isEven` and `isOdd` to throw for floats * ⚡ Updating `Array.merge()` so it works without arguments * 🔀 Fixing leftover merge confilct * ⚡ Updating `removeFieldsContaining` and `keepFieldsContaining` to throw on empty strings * ⚡ Fixing `pluck()` so it returns only plucked values * ⬆️ Updating pnpm lockfile * 👕 Fixing lint errors * ⚡ Using workflow timezone to display dates * ✔️ Updating tests with workflow timezone * ⚡ Not using system timezone when creating Luxon dates * ⚡ Updating `merge()` and `pluck()` array functions * 🔀 Sync with `master`: Removing code that was preserved during merge * ⚡ Updating `.pluck()` to return full array if no arguments are passed * ⚡ Updating `keepFieldsContaining` and `merge` object functions * ⚡ Using week as default for `date.extract()` * ✅ Adding more test cases for DT functions * ⚡ Removing `Object.merge` extension function. Adding missing `deep-equal` dependency * ⚡ Handling `toDate` case when time component is not specified * ⚡ Using workflow's timezone to render dates in output panel, updated unit tests after removing `Object.merge` function * ⚡ Not parsing numbers as dates * 👕 Fixing lint errors * ⚡ Fixing a typo * ⚡ Making date detection more strict so only stringified dates are getting converted * 👌 Addressing PR feedback * 🔥 Removing leftover comment --------- Co-authored-by: Iván Ovejero --- .../editor-ui/src/components/RunDataJson.vue | 11 +- .../editor-ui/src/components/RunDataTable.vue | 7 +- packages/editor-ui/src/utils/typesUtils.ts | 16 ++ packages/workflow/package.json | 2 + packages/workflow/src/Expression.ts | 14 +- .../src/Extensions/ArrayExtensions.ts | 183 +++++++----------- .../workflow/src/Extensions/DateExtensions.ts | 31 ++- .../src/Extensions/NumberExtensions.ts | 8 +- .../src/Extensions/ObjectExtensions.ts | 34 +--- .../src/Extensions/StringExtensions.ts | 7 +- packages/workflow/src/Extensions/utils.ts | 19 ++ .../ArrayExtensions.test.ts | 101 ++++++++-- .../DateExtensions.test.ts | 56 ++++++ .../test/ExpressionExtensions/Helpers.ts | 3 + .../NumberExtensions.test.ts | 12 +- .../ObjectExtensions.test.ts | 34 +++- pnpm-lock.yaml | 58 +----- 17 files changed, 372 insertions(+), 224 deletions(-) create mode 100644 packages/workflow/src/Extensions/utils.ts diff --git a/packages/editor-ui/src/components/RunDataJson.vue b/packages/editor-ui/src/components/RunDataJson.vue index 15a6c0289c..149c2fa063 100644 --- a/packages/editor-ui/src/components/RunDataJson.vue +++ b/packages/editor-ui/src/components/RunDataJson.vue @@ -73,13 +73,14 @@ import VueJsonPretty from 'vue-json-pretty'; import { LOCAL_STORAGE_MAPPING_FLAG } from '@/constants'; import { IDataObject, INodeExecutionData } from 'n8n-workflow'; import Draggable from '@/components/Draggable.vue'; -import { convertPath, executionDataToJson, isString, shorten } from '@/utils'; +import { parseDate, executionDataToJson, isString, shorten } from '@/utils'; import { INodeUi } from '@/Interface'; import { externalHooks } from '@/mixins/externalHooks'; import { mapStores } from 'pinia'; import { useNDVStore } from '@/stores/ndv'; import MappingPill from './MappingPill.vue'; import { getMappedExpression } from '@/utils/mappingUtils'; +import { useWorkflowsStore } from '@/stores/workflows'; const runDataJsonActions = () => import('@/components/RunDataJsonActions.vue'); @@ -149,7 +150,7 @@ export default mixins(externalHooks).extend({ } }, computed: { - ...mapStores(useNDVStore), + ...mapStores(useNDVStore, useWorkflowsStore), jsonData(): IDataObject[] { return executionDataToJson(this.inputData); }, @@ -209,7 +210,11 @@ export default mixins(externalHooks).extend({ }, 1000); // ensure dest data gets set if drop }, getContent(value: unknown): string { - return isString(value) ? `"${value}"` : JSON.stringify(value); + if (isString(value)) { + const parsedDate = parseDate(value, this.workflowsStore.workflow.settings?.timezone); + return parsedDate ? parsedDate.toString() : `"${value}"`; + } + return JSON.stringify(value); }, getListItemName(path: string): string { return path.replace(/^(\["?\d"?]\.?)/g, ''); diff --git a/packages/editor-ui/src/components/RunDataTable.vue b/packages/editor-ui/src/components/RunDataTable.vue index 3f2c1e5b7c..383e905e19 100644 --- a/packages/editor-ui/src/components/RunDataTable.vue +++ b/packages/editor-ui/src/components/RunDataTable.vue @@ -159,7 +159,7 @@