Skip to content

Commit

Permalink
fix(editor): Update assignment hint when user hovers table row (#8782)
Browse files Browse the repository at this point in the history
  • Loading branch information
elsmr authored and netroy committed Mar 5, 2024
1 parent ffd1039 commit a2f4d95
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
11 changes: 7 additions & 4 deletions cypress/e2e/14-mapping.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ describe('Data mapping', () => {
ndv.actions.clearParameterInput('value');
cy.get('body').type('{esc}');

ndv.getters.parameterInput('keepOnlySet').find('input[type="checkbox"]').should('exist');
ndv.getters.parameterInput('keepOnlySet').find('input[type="text"]').should('not.exist');
ndv.getters.parameterInput('includeOtherFields').find('input[type="checkbox"]').should('exist');
ndv.getters.parameterInput('includeOtherFields').find('input[type="text"]').should('not.exist');
ndv.getters
.inputDataContainer()
.should('exist')
Expand All @@ -302,9 +302,12 @@ describe('Data mapping', () => {
.realMouseMove(100, 100);
cy.wait(50);

ndv.getters.parameterInput('keepOnlySet').find('input[type="checkbox"]').should('not.exist');
ndv.getters
.parameterInput('keepOnlySet')
.parameterInput('includeOtherFields')
.find('input[type="checkbox"]')
.should('not.exist');
ndv.getters
.parameterInput('includeOtherFields')
.find('input[type="text"]')
.should('exist')
.invoke('css', 'border')
Expand Down
40 changes: 21 additions & 19 deletions cypress/fixtures/Test_workflow_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
},
{
"parameters": {
"values": {
"string": [
{
"name": "other",
"value": ""
}
"assignments": {
"assignments": [
{
"id": "2b0f25a2-9483-4579-9f6d-91b7ac2fcb71",
"name": "other",
"value": "",
"type": "string"
}
]
},
"options": {}
}
},
"id": "2dfc690a-95cf-48c2-85a6-2b3bb8cd1d1d",
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"typeVersion": 3.3,
"position": [
920,
300
Expand All @@ -43,21 +44,22 @@
"id": "9bee04af-1bfc-4be2-a704-e975cb887ced",
"name": "Set1",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"typeVersion": 3.3,
"position": [
1120,
300
],
"parameters": {
"values": {
"string": [
{
"name": "other",
"value": ""
}
"assignments": {
"assignments": [
{
"id": "2b0f25a2-9483-4579-9f6d-91b7ac2fcb71",
"name": "other",
"value": "",
"type": "string"
}
]
},
"options": {}
}
}
}
],
Expand Down Expand Up @@ -118,4 +120,4 @@
"instanceId": "fe45a93dd232270eb40d3ba1f7907ad3935bbd72ad5e4ee09ff61e96674f9aef"
},
"tags": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { isObject } from '@jsplumb/util';
import type { AssignmentValue, INodeProperties } from 'n8n-workflow';
import { computed, ref } from 'vue';
import TypeSelect from './TypeSelect.vue';
import { useNDVStore } from '@/stores/ndv.store';
import { useI18n } from '@/composables/useI18n';
interface Props {
path: string;
Expand All @@ -29,6 +31,9 @@ const emit = defineEmits<{
(event: 'remove'): void;
}>();
const ndvStore = useNDVStore();
const i18n = useI18n();
const assignmentTypeToNodeProperty = (
type: string,
): Partial<INodeProperties> & Pick<INodeProperties, 'type'> => {
Expand All @@ -52,7 +57,7 @@ const assignmentTypeToNodeProperty = (
};
const nameParameter = computed<INodeProperties>(() => ({
name: '',
name: 'name',
displayName: '',
default: '',
requiresDataPath: 'single',
Expand All @@ -62,7 +67,7 @@ const nameParameter = computed<INodeProperties>(() => ({
const valueParameter = computed<INodeProperties>(() => {
return {
name: '',
name: 'value',
displayName: '',
default: '',
placeholder: 'value',
Expand All @@ -77,7 +82,12 @@ const hint = computed(() => {
}
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)) {
return JSON.stringify(resolvedValue);
Expand All @@ -86,12 +96,20 @@ const hint = computed(() => {
return resolvedValue.toString();
}
if (resolvedValue === '') {
return i18n.baseText('parameterInput.emptyString');
}
return resolvedValue as string;
} catch (error) {
return '';
}
});
const highlightHint = computed(() =>
Boolean(hint.value && ndvStore.hoveringItem && ndvStore.isInputParentOfActiveNode),
);
const valueIsExpression = computed(() => {
const { value } = assignment.value;
Expand Down Expand Up @@ -189,7 +207,13 @@ const onBlur = (): void => {
@update="onAssignmentValueChange"
@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>
</template>
</InputTriple>
Expand Down

0 comments on commit a2f4d95

Please sign in to comment.