Add more FE hooks (#1772)

*  add FE hook for expressionEdit dialogVisibleChanged

*  update FE hook for expressionEdit dialogVisibleChanged

*  add FE hook for expressionEdit itemSelected

*  add FE hook for nodeSettings valueChanged

*  add FE hook for nodeSettings credentialSelected

* cleanup
This commit is contained in:
Ahsan Virani 2021-05-12 05:12:53 +02:00 committed by GitHub
parent b47de284f5
commit caa55a022b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -30,7 +30,7 @@
<div class="editor-description"> <div class="editor-description">
Result Result
</div> </div>
<expression-input :parameter="parameter" resolvedValue="true" rows="8" :value="value" :path="path"></expression-input> <expression-input :parameter="parameter" resolvedValue="true" ref="expressionResult" rows="8" :value="value" :path="path"></expression-input>
</div> </div>
</el-col> </el-col>
@ -52,7 +52,11 @@ import {
Workflow, Workflow,
} from 'n8n-workflow'; } from 'n8n-workflow';
export default Vue.extend({ import { externalHooks } from '@/components/mixins/externalHooks';
import mixins from 'vue-typed-mixins';
export default mixins(externalHooks).extend({
name: 'ExpressionEdit', name: 'ExpressionEdit',
props: [ props: [
'dialogVisible', 'dialogVisible',
@ -81,7 +85,16 @@ export default Vue.extend({
}, },
itemSelected (eventData: IVariableItemSelected) { itemSelected (eventData: IVariableItemSelected) {
// User inserted item from Expression Editor variable selector
(this.$refs.inputFieldExpression as any).itemSelected(eventData); // tslint:disable-line:no-any (this.$refs.inputFieldExpression as any).itemSelected(eventData); // tslint:disable-line:no-any
this.$externalHooks().run('expressionEdit.itemSelected', { parameter: this.parameter, value: this.value, selectedItem: eventData });
},
},
watch: {
dialogVisible (newValue) {
const resolvedExpressionValue = this.$refs.expressionResult && (this.$refs.expressionResult as any).getValue() || undefined; // tslint:disable-line:no-any
this.$externalHooks().run('expressionEdit.dialogVisibleChanged', { dialogVisible: newValue, parameter: this.parameter, value: this.value, resolvedExpressionValue });
}, },
}, },
}); });

View file

@ -59,12 +59,14 @@ import NodeCredentials from '@/components/NodeCredentials.vue';
import NodeWebhooks from '@/components/NodeWebhooks.vue'; import NodeWebhooks from '@/components/NodeWebhooks.vue';
import { get, set, unset } from 'lodash'; import { get, set, unset } from 'lodash';
import { externalHooks } from '@/components/mixins/externalHooks';
import { genericHelpers } from '@/components/mixins/genericHelpers'; import { genericHelpers } from '@/components/mixins/genericHelpers';
import { nodeHelpers } from '@/components/mixins/nodeHelpers'; import { nodeHelpers } from '@/components/mixins/nodeHelpers';
import mixins from 'vue-typed-mixins'; import mixins from 'vue-typed-mixins';
export default mixins( export default mixins(
externalHooks,
genericHelpers, genericHelpers,
nodeHelpers, nodeHelpers,
) )
@ -323,6 +325,8 @@ export default mixins(
// Update the issues // Update the issues
this.updateNodeCredentialIssues(node); this.updateNodeCredentialIssues(node);
this.$externalHooks().run('nodeSettings.credentialSelected', { updateInformation });
}, },
valueChanged (parameterData: IUpdateInformation) { valueChanged (parameterData: IUpdateInformation) {
let newValue: NodeParameterValue; let newValue: NodeParameterValue;
@ -357,6 +361,7 @@ export default mixins(
// Get only the parameters which are different to the defaults // Get only the parameters which are different to the defaults
let nodeParameters = NodeHelpers.getNodeParameters(nodeType.properties, node.parameters, false, false); let nodeParameters = NodeHelpers.getNodeParameters(nodeType.properties, node.parameters, false, false);
const oldNodeParameters = Object.assign({}, nodeParameters);
// Copy the data because it is the data of vuex so make sure that // Copy the data because it is the data of vuex so make sure that
// we do not edit it directly // we do not edit it directly
@ -404,8 +409,11 @@ export default mixins(
name: node.name, name: node.name,
value: nodeParameters, value: nodeParameters,
}; };
this.$store.commit('setNodeParameters', updateInformation); this.$store.commit('setNodeParameters', updateInformation);
this.$externalHooks().run('nodeSettings.valueChanged', { parameterPath, newValue, parameters: this.parameters, oldNodeParameters });
this.updateNodeParameterIssues(node, nodeType); this.updateNodeParameterIssues(node, nodeType);
this.updateNodeCredentialIssues(node); this.updateNodeCredentialIssues(node);
} else { } else {