fix(editor): Update assignment hint when user hovers table row (#8782)

This commit is contained in:
Elias Meire 2024-03-05 12:42:06 +01:00 committed by GitHub
parent 5d5466343e
commit 8c993aa59d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 56 additions and 27 deletions

View file

@ -285,8 +285,8 @@ describe('Data mapping', () => {
ndv.actions.clearParameterInput('value'); ndv.actions.clearParameterInput('value');
cy.get('body').type('{esc}'); cy.get('body').type('{esc}');
ndv.getters.parameterInput('keepOnlySet').find('input[type="checkbox"]').should('exist'); ndv.getters.parameterInput('includeOtherFields').find('input[type="checkbox"]').should('exist');
ndv.getters.parameterInput('keepOnlySet').find('input[type="text"]').should('not.exist'); ndv.getters.parameterInput('includeOtherFields').find('input[type="text"]').should('not.exist');
ndv.getters ndv.getters
.inputDataContainer() .inputDataContainer()
.should('exist') .should('exist')
@ -296,9 +296,12 @@ describe('Data mapping', () => {
.realMouseMove(100, 100); .realMouseMove(100, 100);
cy.wait(50); cy.wait(50);
ndv.getters.parameterInput('keepOnlySet').find('input[type="checkbox"]').should('not.exist');
ndv.getters ndv.getters
.parameterInput('keepOnlySet') .parameterInput('includeOtherFields')
.find('input[type="checkbox"]')
.should('not.exist');
ndv.getters
.parameterInput('includeOtherFields')
.find('input[type="text"]') .find('input[type="text"]')
.should('exist') .should('exist')
.invoke('css', 'border') .invoke('css', 'border')

View file

@ -20,20 +20,21 @@
}, },
{ {
"parameters": { "parameters": {
"values": { "assignments": {
"string": [ "assignments": [
{ {
"id": "2b0f25a2-9483-4579-9f6d-91b7ac2fcb71",
"name": "other", "name": "other",
"value": "" "value": "",
"type": "string"
} }
] ]
}, }
"options": {}
}, },
"id": "2dfc690a-95cf-48c2-85a6-2b3bb8cd1d1d", "id": "2dfc690a-95cf-48c2-85a6-2b3bb8cd1d1d",
"name": "Set", "name": "Set",
"type": "n8n-nodes-base.set", "type": "n8n-nodes-base.set",
"typeVersion": 1, "typeVersion": 3.3,
"position": [ "position": [
920, 920,
300 300
@ -43,21 +44,22 @@
"id": "9bee04af-1bfc-4be2-a704-e975cb887ced", "id": "9bee04af-1bfc-4be2-a704-e975cb887ced",
"name": "Set1", "name": "Set1",
"type": "n8n-nodes-base.set", "type": "n8n-nodes-base.set",
"typeVersion": 1, "typeVersion": 3.3,
"position": [ "position": [
1120, 1120,
300 300
], ],
"parameters": { "parameters": {
"values": { "assignments": {
"string": [ "assignments": [
{ {
"id": "2b0f25a2-9483-4579-9f6d-91b7ac2fcb71",
"name": "other", "name": "other",
"value": "" "value": "",
"type": "string"
} }
] ]
}, }
"options": {}
} }
} }
], ],

View file

@ -10,6 +10,8 @@ import { isObject } from '@jsplumb/util';
import type { AssignmentValue, INodeProperties } from 'n8n-workflow'; import type { AssignmentValue, INodeProperties } from 'n8n-workflow';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import TypeSelect from './TypeSelect.vue'; import TypeSelect from './TypeSelect.vue';
import { useNDVStore } from '@/stores/ndv.store';
import { useI18n } from '@/composables/useI18n';
interface Props { interface Props {
path: string; path: string;
@ -29,6 +31,9 @@ const emit = defineEmits<{
(event: 'remove'): void; (event: 'remove'): void;
}>(); }>();
const ndvStore = useNDVStore();
const i18n = useI18n();
const assignmentTypeToNodeProperty = ( const assignmentTypeToNodeProperty = (
type: string, type: string,
): Partial<INodeProperties> & Pick<INodeProperties, 'type'> => { ): Partial<INodeProperties> & Pick<INodeProperties, 'type'> => {
@ -52,7 +57,7 @@ const assignmentTypeToNodeProperty = (
}; };
const nameParameter = computed<INodeProperties>(() => ({ const nameParameter = computed<INodeProperties>(() => ({
name: '', name: 'name',
displayName: '', displayName: '',
default: '', default: '',
requiresDataPath: 'single', requiresDataPath: 'single',
@ -62,7 +67,7 @@ const nameParameter = computed<INodeProperties>(() => ({
const valueParameter = computed<INodeProperties>(() => { const valueParameter = computed<INodeProperties>(() => {
return { return {
name: '', name: 'value',
displayName: '', displayName: '',
default: '', default: '',
placeholder: 'value', placeholder: 'value',
@ -77,7 +82,12 @@ const hint = computed(() => {
} }
try { try {
const resolvedValue = resolveParameter(value) as unknown; const resolvedValue = resolveParameter(value, {
targetItem: ndvStore.hoveringItem ?? undefined,
inputNodeName: ndvStore.ndvInputNodeName,
inputRunIndex: ndvStore.ndvInputRunIndex,
inputBranchIndex: ndvStore.ndvInputBranchIndex,
}) as unknown;
if (isObject(resolvedValue)) { if (isObject(resolvedValue)) {
return JSON.stringify(resolvedValue); return JSON.stringify(resolvedValue);
@ -86,12 +96,20 @@ const hint = computed(() => {
return resolvedValue.toString(); return resolvedValue.toString();
} }
if (resolvedValue === '') {
return i18n.baseText('parameterInput.emptyString');
}
return resolvedValue as string; return resolvedValue as string;
} catch (error) { } catch (error) {
return ''; return '';
} }
}); });
const highlightHint = computed(() =>
Boolean(hint.value && ndvStore.hoveringItem && ndvStore.isInputParentOfActiveNode),
);
const valueIsExpression = computed(() => { const valueIsExpression = computed(() => {
const { value } = assignment.value; const { value } = assignment.value;
@ -189,7 +207,13 @@ const onBlur = (): void => {
@update="onAssignmentValueChange" @update="onAssignmentValueChange"
@blur="onBlur" @blur="onBlur"
/> />
<ParameterInputHint :class="$style.hint" :hint="hint" single-line /> <ParameterInputHint
data-test-id="parameter-expression-preview-value"
:class="$style.hint"
:highlight="highlightHint"
:hint="hint"
single-line
/>
</div> </div>
</template> </template>
</InputTriple> </InputTriple>