refactor(editor): Move nodeTypes into store module (#3799)

*  Refactor `nodeTypes` into store module

*  Fix condition

* 🔥 Remove leftovers

*  Move `getNodeTranslationHeaders`, `getNodesInformation`, `getNodeParameterOptions`

*  Move leftover call

*  Correct excess prefix

* 🚚 Rename `nodeType` to `getNodeType`

* 🚚 Move logic to `getFullNodesProperties`

*  Simplify `getNodeType`

*  Refactor `nodeTypes` mutations

*  Refactor `Vue.set` call

*  Simplify check

* 🚚 Move export to bottom

* 📘 Simplify typing

* 🔥 Remove unused interface

* 👕 Add `void`

* 🚚 Fix naming

* 🔥 Remove logging

*  Simplify `updateNodeTypes`

* 🚚 Move `omit` to utils

* 🐛 Update `rootGetters` call

* 🐛 Fix `allNodeTypes` call in `nativelyNumberSuffixedDefaults`

* 🔥 Remove unused method

* 🔥 Remove excess namespace

Co-authored-by: Mutasem <mutdmour@gmail.com>
This commit is contained in:
Iván Ovejero
2022-08-01 22:43:50 +02:00
committed by GitHub
parent 231cfaa24d
commit 2c17e6f3ca
29 changed files with 244 additions and 140 deletions

View File

@@ -1480,7 +1480,7 @@ export default mixins(
});
},
async injectNode (nodeTypeName: string, options: AddNodeOptions = {}) {
const nodeTypeData: INodeTypeDescription | null = this.$store.getters.nodeType(nodeTypeName);
const nodeTypeData: INodeTypeDescription | null = this.$store.getters['nodeTypes/getNodeType'](nodeTypeName);
if (nodeTypeData === null) {
this.$showMessage({
@@ -1534,7 +1534,7 @@ export default mixins(
let yOffset = 0;
if (lastSelectedConnection) {
const sourceNodeType = this.$store.getters.nodeType(lastSelectedNode.type, lastSelectedNode.typeVersion) as INodeTypeDescription | null;
const sourceNodeType = this.$store.getters['nodeTypes/getNodeType'](lastSelectedNode.type, lastSelectedNode.typeVersion) as INodeTypeDescription | null;
const offsets = [[-100, 100], [-140, 0, 140], [-240, -100, 100, 240]];
if (sourceNodeType && sourceNodeType.outputs.length > 1) {
const offset = offsets[sourceNodeType.outputs.length - 2];
@@ -1937,7 +1937,7 @@ export default mixins(
const nodeName = (element as HTMLElement).dataset['name'] as string;
const node = this.$store.getters.getNodeByName(nodeName) as INodeUi | null;
if (node) {
const nodeType = this.$store.getters.nodeType(node.type, node.typeVersion) as INodeTypeDescription | null;
const nodeType = this.$store.getters['nodeTypes/getNodeType'](node.type, node.typeVersion) as INodeTypeDescription | null;
if (nodeType && nodeType.inputs && nodeType.inputs.length === 1) {
this.pullConnActiveNodeName = node.name;
const endpoint = this.instance.getEndpoint(this.getInputEndpointUUID(nodeName, 0));
@@ -2199,7 +2199,7 @@ export default mixins(
const node = this.$store.getters.getNodeByName(nodeName);
const nodeTypeData: INodeTypeDescription | null= this.$store.getters.nodeType(node.type, node.typeVersion);
const nodeTypeData: INodeTypeDescription | null= this.$store.getters['nodeTypes/getNodeType'](node.type, node.typeVersion);
if (nodeTypeData && nodeTypeData.maxNodes !== undefined && this.getNodeTypeCount(node.type) >= nodeTypeData.maxNodes) {
this.showMaxNodeTypeError(nodeTypeData);
return;
@@ -2411,7 +2411,7 @@ export default mixins(
let waitForNewConnection = false;
// connect nodes before/after deleted node
const nodeType: INodeTypeDescription | null = this.$store.getters.nodeType(node.type, node.typeVersion);
const nodeType: INodeTypeDescription | null = this.$store.getters['nodeTypes/getNodeType'](node.type, node.typeVersion);
if (nodeType && nodeType.outputs.length === 1
&& nodeType.inputs.length === 1) {
const {incoming, outgoing} = this.getIncomingOutgoingConnections(node.name);
@@ -2621,7 +2621,7 @@ export default mixins(
let nodeType: INodeTypeDescription | null;
let foundNodeIssues: INodeIssues | null;
nodes.forEach((node) => {
nodeType = this.$store.getters.nodeType(node.type, node.typeVersion) as INodeTypeDescription | null;
nodeType = this.$store.getters['nodeTypes/getNodeType'](node.type, node.typeVersion) as INodeTypeDescription | null;
// Make sure that some properties always exist
if (!node.hasOwnProperty('disabled')) {
@@ -2931,8 +2931,7 @@ export default mixins(
this.$store.commit('setActiveWorkflows', activeWorkflows);
},
async loadNodeTypes (): Promise<void> {
const nodeTypes = await this.restApi().getNodeTypes();
this.$store.commit('setNodeTypes', nodeTypes);
this.$store.dispatch('nodeTypes/getNodeTypes');
},
async loadCredentialTypes (): Promise<void> {
await this.$store.dispatch('credentials/fetchCredentialTypes', true);
@@ -2941,7 +2940,7 @@ export default mixins(
await this.$store.dispatch('credentials/fetchAllCredentials');
},
async loadNodesProperties(nodeInfos: INodeTypeNameVersion[]): Promise<void> {
const allNodes:INodeTypeDescription[] = this.$store.getters.allNodeTypes;
const allNodes:INodeTypeDescription[] = this.$store.getters['nodeTypes/allNodeTypes'];
const nodesToBeFetched:INodeTypeNameVersion[] = [];
allNodes.forEach(node => {
@@ -2959,21 +2958,7 @@ export default mixins(
if (nodesToBeFetched.length > 0) {
// Only call API if node information is actually missing
this.startLoading();
const nodesInfo = await this.restApi().getNodesInformation(nodesToBeFetched);
nodesInfo.forEach(nodeInfo => {
if (nodeInfo.translation) {
const nodeType = this.$locale.shortNodeType(nodeInfo.name);
addNodeTranslation(
{ [nodeType]: nodeInfo.translation },
this.$store.getters.defaultLocale,
);
}
});
this.$store.commit('updateNodeTypes', nodesInfo);
await this.$store.dispatch('nodeTypes/getNodesInformation', nodesToBeFetched);
this.stopLoading();
}
},