fix(editor): Fix Remove all fields not removing values in resource mapper (#6940)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
committed by
GitHub
parent
b312f2ee54
commit
e6cff3fce4
@@ -10,8 +10,8 @@ import type {
|
||||
ResourceMapperValue,
|
||||
} from 'n8n-workflow';
|
||||
import ParameterInputFull from '@/components/ParameterInputFull.vue';
|
||||
import ParameterIssues from '../ParameterIssues.vue';
|
||||
import ParameterOptions from '../ParameterOptions.vue';
|
||||
import ParameterIssues from '@/components//ParameterIssues.vue';
|
||||
import ParameterOptions from '@/components//ParameterOptions.vue';
|
||||
import { computed } from 'vue';
|
||||
import { i18n as locale } from '@/plugins/i18n';
|
||||
import { useNDVStore } from '@/stores';
|
||||
@@ -276,6 +276,7 @@ defineExpose({
|
||||
:size="labelSize"
|
||||
:showOptions="true"
|
||||
:showExpressionSelector="false"
|
||||
inputName="columns"
|
||||
color="text-dark"
|
||||
>
|
||||
<template #options>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import type {
|
||||
INodeProperties,
|
||||
INodePropertyTypeOptions,
|
||||
ResourceMapperField,
|
||||
ResourceMapperFields,
|
||||
@@ -7,8 +8,10 @@ import type {
|
||||
import { computed, reactive, watch } from 'vue';
|
||||
import { i18n as locale } from '@/plugins/i18n';
|
||||
import { useNodeSpecificationValues } from '@/composables';
|
||||
import ParameterOptions from '@/components/ParameterOptions.vue';
|
||||
|
||||
interface Props {
|
||||
parameter: INodeProperties;
|
||||
initialValue: string[];
|
||||
fieldsToMap: ResourceMapperFields['fields'];
|
||||
typeOptions: INodePropertyTypeOptions | undefined;
|
||||
@@ -17,6 +20,7 @@ interface Props {
|
||||
loading: boolean;
|
||||
serviceName: string;
|
||||
teleported?: boolean;
|
||||
refreshInProgress: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -47,6 +51,7 @@ watch(
|
||||
|
||||
const emit = defineEmits<{
|
||||
(event: 'matchingColumnsChanged', value: string[]): void;
|
||||
(event: 'refreshFieldList'): void;
|
||||
}>();
|
||||
|
||||
const availableMatchingFields = computed<ResourceMapperField[]>(() => {
|
||||
@@ -103,6 +108,27 @@ const fieldTooltip = computed<string>(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const parameterActions = computed<Array<{ label: string; value: string; disabled?: boolean }>>(
|
||||
() => {
|
||||
return [
|
||||
{
|
||||
label: locale.baseText('resourceMapper.refreshFieldList', {
|
||||
interpolate: { fieldWord: singularFieldWordCapitalized.value },
|
||||
}),
|
||||
value: 'refreshFieldList',
|
||||
},
|
||||
];
|
||||
},
|
||||
);
|
||||
|
||||
const fetchingFieldsLabel = computed<string>(() => {
|
||||
return locale.baseText('resourceMapper.fetchingFields.message', {
|
||||
interpolate: {
|
||||
fieldWord: pluralFieldWord.value,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
function onSelectionChange(value: string | string[]) {
|
||||
if (resourceMapperTypeOptions.value?.multiKeyMatch === true) {
|
||||
state.selected = value as string[];
|
||||
@@ -121,6 +147,16 @@ function emitValueChanged() {
|
||||
}
|
||||
}
|
||||
|
||||
function onParameterActionSelected(action: string): void {
|
||||
switch (action) {
|
||||
case 'refreshFieldList':
|
||||
emit('refreshFieldList');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
state,
|
||||
});
|
||||
@@ -137,6 +173,15 @@ defineExpose({
|
||||
:size="labelSize"
|
||||
color="text-dark"
|
||||
>
|
||||
<template #options>
|
||||
<parameter-options
|
||||
:parameter="parameter"
|
||||
:customActions="parameterActions"
|
||||
:loading="props.refreshInProgress"
|
||||
:loadingMessage="fetchingFieldsLabel"
|
||||
@update:modelValue="onParameterActionSelected"
|
||||
/>
|
||||
</template>
|
||||
<n8n-select
|
||||
:multiple="resourceMapperTypeOptions?.multiKeyMatch === true"
|
||||
:modelValue="state.selected"
|
||||
|
||||
@@ -348,18 +348,40 @@ function removeField(name: string): void {
|
||||
}
|
||||
const fieldName = parseResourceMapperFieldName(name);
|
||||
if (fieldName) {
|
||||
if (state.paramValue.value) {
|
||||
delete state.paramValue.value[fieldName];
|
||||
const field = state.paramValue.schema.find((f) => f.id === fieldName);
|
||||
if (field) {
|
||||
field.removed = true;
|
||||
state.paramValue.schema.splice(state.paramValue.schema.indexOf(field), 1, field);
|
||||
}
|
||||
const field = state.paramValue.schema.find((f) => f.id === fieldName);
|
||||
if (field) {
|
||||
deleteField(field);
|
||||
emitValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeAllFields(): void {
|
||||
state.paramValue.schema.forEach((field) => {
|
||||
if (
|
||||
!fieldCannotBeDeleted(
|
||||
field,
|
||||
showMatchingColumnsSelector.value,
|
||||
resourceMapperMode.value,
|
||||
matchingColumns.value,
|
||||
)
|
||||
) {
|
||||
deleteField(field);
|
||||
}
|
||||
});
|
||||
emitValueChanged();
|
||||
}
|
||||
|
||||
// Delete a single field from the mapping (set removed flag to true and delete from value)
|
||||
// Used when removing one or all fields
|
||||
function deleteField(field: ResourceMapperField): void {
|
||||
if (state.paramValue.value) {
|
||||
delete state.paramValue.value[field.id];
|
||||
field.removed = true;
|
||||
state.paramValue.schema.splice(state.paramValue.schema.indexOf(field), 1, field);
|
||||
}
|
||||
}
|
||||
|
||||
function addField(name: string): void {
|
||||
if (name === 'addAllFields') {
|
||||
return addAllFields();
|
||||
@@ -395,23 +417,6 @@ function addAllFields(): void {
|
||||
emitValueChanged();
|
||||
}
|
||||
|
||||
function removeAllFields(): void {
|
||||
state.paramValue.schema.forEach((field) => {
|
||||
if (
|
||||
!fieldCannotBeDeleted(
|
||||
field,
|
||||
showMatchingColumnsSelector.value,
|
||||
resourceMapperMode.value,
|
||||
matchingColumns.value,
|
||||
)
|
||||
) {
|
||||
field.removed = true;
|
||||
state.paramValue.schema.splice(state.paramValue.schema.indexOf(field), 1, field);
|
||||
}
|
||||
});
|
||||
emitValueChanged();
|
||||
}
|
||||
|
||||
function emitValueChanged(): void {
|
||||
pruneParamValues();
|
||||
emit('valueChanged', {
|
||||
@@ -457,6 +462,7 @@ defineExpose({
|
||||
/>
|
||||
<matching-columns-select
|
||||
v-if="showMatchingColumnsSelector"
|
||||
:parameter="props.parameter"
|
||||
:label-size="labelSize"
|
||||
:fieldsToMap="state.paramValue.schema"
|
||||
:typeOptions="props.parameter.typeOptions"
|
||||
@@ -465,7 +471,9 @@ defineExpose({
|
||||
:initialValue="matchingColumns"
|
||||
:serviceName="nodeType?.displayName || locale.baseText('generic.service')"
|
||||
:teleported="teleported"
|
||||
:refreshInProgress="state.refreshInProgress"
|
||||
@matchingColumnsChanged="onMatchingColumnsChanged"
|
||||
@refreshFieldList="initFetching(true)"
|
||||
/>
|
||||
<n8n-text v-if="!showMappingModeSelect && state.loading" size="small">
|
||||
<n8n-icon icon="sync-alt" size="xsmall" :spin="true" />
|
||||
|
||||
Reference in New Issue
Block a user