Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N8N-4143 Variables and expressions for pin data nodes without execution #3738

Conversation

alexgrozav
Copy link
Member

@alexgrozav alexgrozav commented Jul 20, 2022

@alexgrozav alexgrozav requested review from mutdmour and ivov July 20, 2022 08:20
@alexgrozav alexgrozav changed the base branch from master to n8n-3750-redesign-button-component-2 July 20, 2022 08:21
@alexgrozav alexgrozav force-pushed the n8n-4143-make-node-parameter-variables-and branch from 62e9b67 to 84c598a Compare July 20, 2022 08:22
@alexgrozav alexgrozav changed the title N8N-4143 make node parameter variables and expressions for pin data nodes work without execution N8N-4143 Variables and expressions for pin data nodes without execution Jul 20, 2022
@n8n-assistant n8n-assistant bot added n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system labels Jul 20, 2022
Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on!

  1. If we pin a node, connect the next, reference from next to previous using expression, the expression works. If then we add a third node standalone (unconnected), run this third node, and go back to inspect the expression, it now says [invalid (workflowRunData[parentNode[0]] is undefined)]

image

  1. If we pin a node, connect the next, run the next, when opening the NDV or the expression edit modal, there are Vue store state mutation warnings and watcher callback error warnings in the console. These fire multiple times when selecting any option (pindata-based or not) from the variable selector.

image

@@ -491,7 +520,7 @@ export default mixins(
}
}

let tempOutputData;
let tempOutputData: IVariableSelectorOption[] | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is undefined here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated types.

* @param {string} nodeName The name of the node to get the data of
* @param {INodeExecutionData} outputData The data of the run to get the data of
* @param {string} filterText Filter text for parameters
* @param {boolean} [useShort=false] Use short notation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would add a small example here. Not immediately obvious what short notation stands for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added description.

}
});

if (pinDataOptions.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope: I find this hard to follow without spending longer, which makes it difficult to properly check the logic. In the future, we should make an effort to refactor this section and ideally this whole 250-line method. Since we are looking to release, now is probably not the time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it very hard to follow as well. The code there is very complicated and requires deep business-logic understanding.

I've been doing a lot of trial-and-error work to get to understand what this does and how it interacts with the data.

@alexgrozav
Copy link
Member Author

Thanks for taking this on!

  1. If we pin a node, connect the next, reference from next to previous using expression, the expression works. If then we add a third node standalone (unconnected), run this third node, and go back to inspect the expression, it now says [invalid (workflowRunData[parentNode[0]] is undefined)]

image

Good catch! Found it as well after more thorough testing. Added a fix for it.

  1. If we pin a node, connect the next, run the next, when opening the NDV or the expression edit modal, there are Vue store state mutation warnings and watcher callback error warnings in the console. These fire multiple times when selecting any option (pindata-based or not) from the variable selector.
image

Updated. Rebuilding workflow run data using spreading to be able to manipulate it.

@alexgrozav
Copy link
Member Author

Further update:

  • Found an issue that appeared after you have an execution and add another node with pin data (also related to Iván's finding). Also fixed.

Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, those cases are fixed. FYI pushed a small build fix.

@alexgrozav
Copy link
Member Author

@ivov Green connector lines changes are ready to be reviewed.

Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to work:

  1. Pin test data to Start, connect to next → connector still grey, no items label
  2. Pin test data to standalone node, connect to next → connector still grey, no items label
  3. Pin test data to standalone node, connect to next, keep building chain with every node pinned → all connectors still grey, no items label in any node

Reviewed: 7feed12

@@ -214,6 +215,8 @@ export const store = new Vuex.Store({
}

state.stateIsDirty = true;

dataPinningEventBus.$emit('pin-data', { [payload.node.name]: payload.data });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand, we only need the node name to create the connection, so why do we need to send the payload? Same for others.

Copy link
Member Author

@alexgrozav alexgrozav Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need the number of items. See total: pinData[nodeName].length. Thought we'll reuse this at some point so made it a general-purpose event.

Comment on lines 2984 to 2986
connections.forEach((connection) => {
CanvasHelpers.resetConnection(connection);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: connections.forEach(CanvasHelpers.resetConnection);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 3043 to 3049
dataPinningEventBus.$on('pin-data', (pinData: PinData) => {
this.addPinDataConnections(pinData);
});

dataPinningEventBus.$on('unpin-data', (pinData: PinData) => {
this.removePinDataConnections(pinData);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Suggestion: dataPinningEventBus.$on('event-bus', this.method);
  2. Why no $off in destroyed()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Done.
  2. Because I forgot. 🥲

@alexgrozav alexgrozav force-pushed the n8n-4143-make-node-parameter-variables-and branch from 43c5670 to 030c9fa Compare July 20, 2022 14:00
Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work!

@alexgrozav alexgrozav merged commit e1c12ba into n8n-3750-redesign-button-component-2 Jul 20, 2022
@alexgrozav alexgrozav deleted the n8n-4143-make-node-parameter-variables-and branch July 20, 2022 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants