fix: Fix mapping paths when appending to empty expression (#5591)

* fix: Fix mapping when appending to empty expression

* fix: refactor logic out

* test: add tests

* test: add tests

* fix: fix bug where value does not get updated when mapping

* test: add test for bug

* test: add test for bug
This commit is contained in:
Mutasem Aldmour
2023-03-02 15:02:29 +03:00
committed by GitHub
parent 31cc8de829
commit 1f7b478920
9 changed files with 294 additions and 33 deletions

View File

@@ -90,6 +90,7 @@ import { mapStores } from 'pinia';
import { useNDVStore } from '@/stores/ndv';
import { useSegment } from '@/stores/segment';
import { externalHooks } from '@/mixins/externalHooks';
import { getMappedResult } from '../utils/mappingUtils';
export default mixins(showMessage, externalHooks).extend({
name: 'parameter-input-full',
@@ -146,6 +147,7 @@ export default mixins(showMessage, externalHooks).extend({
{
attrs: {
label: this.$locale.baseText('_reusableBaseText.dismiss' as BaseTextKey),
'data-test-id': 'dismiss-mapping-tooltip',
},
listeners: {
click: mappingTooltipDismissHandler,
@@ -228,39 +230,15 @@ export default mixins(showMessage, externalHooks).extend({
param?.$emit('optionSelected', 'addExpression');
}
},
onDrop(data: string) {
const useDataPath = !!this.parameter.requiresDataPath && data.startsWith('{{ $json');
if (!useDataPath) {
onDrop(newParamValue: string) {
const updatedValue = getMappedResult(this.parameter, newParamValue, this.value);
const prevValue = this.isResourceLocator ? this.value.value : this.value;
if (updatedValue.startsWith('=')) {
this.forceShowExpression = true;
}
setTimeout(() => {
if (this.node) {
const prevValue = this.isResourceLocator ? this.value.value : this.value;
let updatedValue: string;
if (useDataPath) {
const newValue = data
.replace('{{ $json', '')
.replace(new RegExp('^\\.'), '')
.replace(new RegExp('}}$'), '')
.trim();
if (prevValue && this.parameter.requiresDataPath === 'multiple') {
updatedValue = `${prevValue}, ${newValue}`;
} else {
updatedValue = newValue;
}
} else if (
typeof prevValue === 'string' &&
prevValue.startsWith('=') &&
prevValue.length > 1
) {
updatedValue = `${prevValue} ${data}`;
} else if (prevValue && ['string', 'json'].includes(this.parameter.type)) {
updatedValue = prevValue === '=' ? `=${data}` : `=${prevValue} ${data}`;
} else {
updatedValue = `=${data}`;
}
let parameterData;
if (this.isResourceLocator) {
if (!isResourceLocatorValue(this.value)) {
@@ -334,7 +312,7 @@ export default mixins(showMessage, externalHooks).extend({
}, 200);
},
onMappingTooltipDismissed() {
this.localStorageMappingFlag = true;
this.ndvStore.disableMappingHint(false);
},
},
watch: {