refactor: Migrate externalHooks mixin to composables (no-changelog) (#7930)

## Summary
Provide details about your pull request and what it adds, fixes, or
changes. Photos and videos are recommended.

As part of NodeView refactor, this PR migrates all externalHooks calls
to `useExternalHooks` composable.

#### How to test the change:
1. Run using env `export N8N_DEPLOYMENT_TYPE=cloud` 
2. Hooks should still run as expected


## Issues fixed
Include links to Github issue or Community forum post or **Linear
ticket**:
> Important in order to close automatically and provide context to
reviewers

https://linear.app/n8n/issue/N8N-6349/externalhooks


## Review / Merge checklist
- [x] PR title and summary are descriptive. **Remember, the title
automatically goes into the changelog. Use `(no-changelog)` otherwise.**
([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md))
- [x] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up
ticket created.
- [x] Tests included.
> A bug is not considered fixed, unless a test is added to prevent it
from happening again. A feature is not complete without tests.
  >
> *(internal)* You can use Slack commands to trigger [e2e
tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227)
or [deploy test
instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce)
or [deploy early access version on
Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
This commit is contained in:
Alex Grozav
2023-12-06 17:28:09 +02:00
committed by GitHub
parent c461025f70
commit 885dba6f12
46 changed files with 287 additions and 241 deletions

View File

@@ -235,7 +235,6 @@ import {
TIME,
} from '@/constants';
import { copyPaste } from '@/mixins/copyPaste';
import { externalHooks } from '@/mixins/externalHooks';
import { genericHelpers } from '@/mixins/genericHelpers';
import { moveNodeWorkflow } from '@/mixins/moveNodeWorkflow';
import { nodeHelpers } from '@/mixins/nodeHelpers';
@@ -366,6 +365,7 @@ import {
import { sourceControlEventBus } from '@/event-bus/source-control';
import { getConnectorPaintStyleData, OVERLAY_ENDPOINT_ARROW_ID } from '@/utils/nodeViewUtils';
import { useViewStacks } from '@/components/Node/NodeCreator/composables/useViewStacks';
import { useExternalHooks } from '@/composables/useExternalHooks';
interface AddNodeOptions {
position?: XYPosition;
@@ -380,7 +380,6 @@ export default defineComponent({
name: 'NodeView',
mixins: [
copyPaste,
externalHooks,
genericHelpers,
moveNodeWorkflow,
workflowHelpers,
@@ -399,7 +398,8 @@ export default defineComponent({
CanvasControls,
ContextMenu,
},
setup(props) {
setup(props, ctx) {
const externalHooks = useExternalHooks();
const locale = useI18n();
const contextMenu = useContextMenu();
const dataSchema = useDataSchema();
@@ -408,6 +408,7 @@ export default defineComponent({
locale,
contextMenu,
dataSchema,
externalHooks,
...useCanvasMouseSelect(),
...useGlobalLinkActions(),
...useTitleChange(),
@@ -416,7 +417,7 @@ export default defineComponent({
...useUniqueNodeName(),
...useExecutionDebugging(),
// eslint-disable-next-line @typescript-eslint/no-misused-promises
...workflowRun.setup?.(props),
...workflowRun.setup?.(props, ctx),
};
},
errorCaptured: (err, vm, info) => {
@@ -775,7 +776,7 @@ export default defineComponent({
session_id: this.ndvStore.sessionId,
};
this.$telemetry.track('User clicked execute node button', telemetryPayload);
void this.$externalHooks().run('nodeView.onRunNode', telemetryPayload);
void this.externalHooks.run('nodeView.onRunNode', telemetryPayload);
void this.runWorkflow({ destinationNode: nodeName, source });
},
async onOpenChat() {
@@ -783,7 +784,7 @@ export default defineComponent({
workflow_id: this.workflowsStore.workflowId,
};
this.$telemetry.track('User clicked chat open button', telemetryPayload);
void this.$externalHooks().run('nodeView.onOpenChat', telemetryPayload);
void this.externalHooks.run('nodeView.onOpenChat', telemetryPayload);
this.uiStore.openModal(WORKFLOW_LM_CHAT_MODAL_KEY);
},
async onRunWorkflow() {
@@ -796,7 +797,7 @@ export default defineComponent({
),
};
this.$telemetry.track('User clicked execute workflow button', telemetryPayload);
void this.$externalHooks().run('nodeView.onRunWorkflow', telemetryPayload);
void this.externalHooks.run('nodeView.onRunWorkflow', telemetryPayload);
});
await this.runWorkflow({});
@@ -950,7 +951,7 @@ export default defineComponent({
await this.$nextTick();
this.canvasStore.zoomToFit();
this.uiStore.stateIsDirty = false;
void this.$externalHooks().run('execution.open', {
void this.externalHooks.run('execution.open', {
workflowId: data.workflowData.id,
workflowName: data.workflowData.name,
executionId,
@@ -1030,7 +1031,7 @@ export default defineComponent({
let data: IWorkflowTemplate | undefined;
try {
void this.$externalHooks().run('template.requested', { templateId });
void this.externalHooks.run('template.requested', { templateId });
data = await this.templatesStore.getFixedWorkflowTemplate(templateId);
if (!data) {
@@ -1055,7 +1056,7 @@ export default defineComponent({
this.canvasStore.zoomToFit();
this.uiStore.stateIsDirty = true;
void this.$externalHooks().run('template.open', {
void this.externalHooks.run('template.open', {
templateId,
templateName: data.name,
workflow: data.workflow,
@@ -1106,7 +1107,7 @@ export default defineComponent({
this.uiStore.stateIsDirty = false;
}
this.canvasStore.zoomToFit();
void this.$externalHooks().run('workflow.open', {
void this.externalHooks.run('workflow.open', {
workflowId: workflow.id,
workflowName: workflow.name,
});
@@ -1191,7 +1192,7 @@ export default defineComponent({
if (e.key === 'Escape') {
this.createNodeActive = false;
if (this.activeNode) {
void this.$externalHooks().run('dataDisplay.nodeEditingFinished');
void this.externalHooks.run('dataDisplay.nodeEditingFinished');
this.ndvStore.activeNodeName = null;
}
@@ -2256,7 +2257,7 @@ export default defineComponent({
workflow_id: this.workflowsStore.workflowId,
});
} else {
void this.$externalHooks().run('nodeView.addNodeButton', { nodeTypeName });
void this.externalHooks.run('nodeView.addNodeButton', { nodeTypeName });
useSegment().trackAddedTrigger(nodeTypeName);
const trackProperties: ITelemetryTrackProperties = {
node_type: nodeTypeName,
@@ -3595,7 +3596,7 @@ export default defineComponent({
is_welcome_note: node.name === QUICKSTART_NOTE_NAME,
});
} else {
void this.$externalHooks().run('node.deleteNode', { node });
void this.externalHooks.run('node.deleteNode', { node });
this.$telemetry.track('User deleted node', {
node_type: node.type,
workflow_id: this.workflowsStore.workflowId,
@@ -4395,7 +4396,7 @@ export default defineComponent({
}
if (createNodeActive) this.nodeCreatorStore.setOpenSource(source);
void this.$externalHooks().run('nodeView.createNodeActiveChanged', {
void this.externalHooks.run('nodeView.createNodeActiveChanged', {
source,
mode,
createNodeActive,
@@ -4644,9 +4645,7 @@ export default defineComponent({
});
// TODO: This currently breaks since front-end hooks are still not updated to work with pinia store
void this.$externalHooks()
.run('nodeView.mount')
.catch((e) => {});
void this.externalHooks.run('nodeView.mount').catch((e) => {});
if (
this.currentUser?.personalizationAnswers !== null &&