mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
refactor(editor): Migrate NodeWebhooks to Composition API (no-changelog) (#10710)
Some checks failed
Test Master / install-and-build (push) Has been cancelled
Benchmark Docker Image CI / build (push) Has been cancelled
Test Master / Unit tests (18.x) (push) Has been cancelled
Test Master / Unit tests (20.x) (push) Has been cancelled
Test Master / Unit tests (22.4) (push) Has been cancelled
Test Master / Lint (push) Has been cancelled
Test Master / Notify Slack on failure (push) Has been cancelled
Some checks failed
Test Master / install-and-build (push) Has been cancelled
Benchmark Docker Image CI / build (push) Has been cancelled
Test Master / Unit tests (18.x) (push) Has been cancelled
Test Master / Unit tests (20.x) (push) Has been cancelled
Test Master / Unit tests (22.4) (push) Has been cancelled
Test Master / Lint (push) Has been cancelled
Test Master / Notify Slack on failure (push) Has been cancelled
This commit is contained in:
parent
e4c9035915
commit
6ea0856085
|
@ -1025,7 +1025,7 @@ onBeforeUnmount(() => {
|
|||
"
|
||||
/>
|
||||
<div v-show="openPanel === 'params'">
|
||||
<NodeWebhooks :node="node" :node-type="nodeType" />
|
||||
<NodeWebhooks :node="node" :node-type-description="nodeType" />
|
||||
|
||||
<ParameterInputList
|
||||
v-if="nodeValuesInitialized"
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import type { INodeTypeDescription, IWebhookDescription } from 'n8n-workflow';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
import { useToast } from '@/composables/useToast';
|
||||
import {
|
||||
CHAT_TRIGGER_NODE_TYPE,
|
||||
|
@ -12,159 +10,163 @@ import {
|
|||
import { useClipboard } from '@/composables/useClipboard';
|
||||
import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
|
||||
import { useRouter } from 'vue-router';
|
||||
import type { INodeUi } from '@/Interface';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from '@/composables/useI18n';
|
||||
import { useTelemetry } from '@/composables/useTelemetry';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'NodeWebhooks',
|
||||
props: [
|
||||
'node', // NodeUi
|
||||
'nodeType', // INodeTypeDescription
|
||||
],
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
const clipboard = useClipboard();
|
||||
const workflowHelpers = useWorkflowHelpers({ router });
|
||||
return {
|
||||
clipboard,
|
||||
workflowHelpers,
|
||||
...useToast(),
|
||||
};
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isMinimized: this.nodeType && !OPEN_URL_PANEL_TRIGGER_NODE_TYPES.includes(this.nodeType.name),
|
||||
showUrlFor: 'test',
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isProductionOnly(): boolean {
|
||||
return this.nodeType && PRODUCTION_ONLY_TRIGGER_NODE_TYPES.includes(this.nodeType.name);
|
||||
},
|
||||
urlOptions(): Array<{ label: string; value: string }> {
|
||||
return [
|
||||
...(this.isProductionOnly ? [] : [{ label: this.baseText.testUrl, value: 'test' }]),
|
||||
const props = defineProps<{
|
||||
node: INodeUi;
|
||||
nodeTypeDescription: INodeTypeDescription | null;
|
||||
}>();
|
||||
|
||||
const router = useRouter();
|
||||
const clipboard = useClipboard();
|
||||
const workflowHelpers = useWorkflowHelpers({ router });
|
||||
const toast = useToast();
|
||||
const i18n = useI18n();
|
||||
const telemetry = useTelemetry();
|
||||
|
||||
const isMinimized = ref(
|
||||
props.nodeTypeDescription &&
|
||||
!OPEN_URL_PANEL_TRIGGER_NODE_TYPES.includes(props.nodeTypeDescription.name),
|
||||
);
|
||||
const showUrlFor = ref('test');
|
||||
|
||||
const isProductionOnly = computed(() => {
|
||||
return (
|
||||
props.nodeTypeDescription &&
|
||||
PRODUCTION_ONLY_TRIGGER_NODE_TYPES.includes(props.nodeTypeDescription.name)
|
||||
);
|
||||
});
|
||||
|
||||
const urlOptions = computed(() => [
|
||||
...(isProductionOnly.value ? [] : [{ label: baseText.value.testUrl, value: 'test' }]),
|
||||
{
|
||||
label: this.baseText.productionUrl,
|
||||
label: baseText.value.productionUrl,
|
||||
value: 'production',
|
||||
},
|
||||
];
|
||||
},
|
||||
visibleWebhookUrls(): IWebhookDescription[] {
|
||||
return this.webhooksNode.filter((webhook) => {
|
||||
]);
|
||||
|
||||
const visibleWebhookUrls = computed(() => {
|
||||
return webhooksNode.value.filter((webhook) => {
|
||||
if (typeof webhook.ndvHideUrl === 'string') {
|
||||
return !this.workflowHelpers.getWebhookExpressionValue(webhook, 'ndvHideUrl');
|
||||
return !workflowHelpers.getWebhookExpressionValue(webhook, 'ndvHideUrl');
|
||||
}
|
||||
|
||||
return !webhook.ndvHideUrl;
|
||||
});
|
||||
},
|
||||
webhooksNode(): IWebhookDescription[] {
|
||||
if (this.nodeType === null || this.nodeType.webhooks === undefined) {
|
||||
});
|
||||
|
||||
const webhooksNode = computed(() => {
|
||||
if (props.nodeTypeDescription?.webhooks === undefined) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return (this.nodeType as INodeTypeDescription).webhooks!.filter(
|
||||
return props.nodeTypeDescription.webhooks.filter(
|
||||
(webhookData) => webhookData.restartWebhook !== true,
|
||||
);
|
||||
},
|
||||
baseText() {
|
||||
const nodeType = this.nodeType.name;
|
||||
});
|
||||
|
||||
const baseText = computed(() => {
|
||||
const nodeType = props.nodeTypeDescription?.name;
|
||||
switch (nodeType) {
|
||||
case CHAT_TRIGGER_NODE_TYPE:
|
||||
return {
|
||||
toggleTitle: this.$locale.baseText('nodeWebhooks.webhookUrls.chatTrigger'),
|
||||
clickToDisplay: this.$locale.baseText(
|
||||
'nodeWebhooks.clickToDisplayWebhookUrls.formTrigger',
|
||||
),
|
||||
clickToHide: this.$locale.baseText('nodeWebhooks.clickToHideWebhookUrls.chatTrigger'),
|
||||
clickToCopy: this.$locale.baseText('nodeWebhooks.clickToCopyWebhookUrls.chatTrigger'),
|
||||
testUrl: this.$locale.baseText('nodeWebhooks.testUrl'),
|
||||
productionUrl: this.$locale.baseText('nodeWebhooks.productionUrl'),
|
||||
copyTitle: this.$locale.baseText('nodeWebhooks.showMessage.title.chatTrigger'),
|
||||
copyMessage: this.$locale.baseText('nodeWebhooks.showMessage.message.chatTrigger'),
|
||||
toggleTitle: i18n.baseText('nodeWebhooks.webhookUrls.chatTrigger'),
|
||||
clickToDisplay: i18n.baseText('nodeWebhooks.clickToDisplayWebhookUrls.formTrigger'),
|
||||
clickToHide: i18n.baseText('nodeWebhooks.clickToHideWebhookUrls.chatTrigger'),
|
||||
clickToCopy: i18n.baseText('nodeWebhooks.clickToCopyWebhookUrls.chatTrigger'),
|
||||
testUrl: i18n.baseText('nodeWebhooks.testUrl'),
|
||||
productionUrl: i18n.baseText('nodeWebhooks.productionUrl'),
|
||||
copyTitle: i18n.baseText('nodeWebhooks.showMessage.title.chatTrigger'),
|
||||
copyMessage: i18n.baseText('nodeWebhooks.showMessage.message.chatTrigger'),
|
||||
};
|
||||
|
||||
case FORM_TRIGGER_NODE_TYPE:
|
||||
return {
|
||||
toggleTitle: this.$locale.baseText('nodeWebhooks.webhookUrls.formTrigger'),
|
||||
clickToDisplay: this.$locale.baseText(
|
||||
'nodeWebhooks.clickToDisplayWebhookUrls.formTrigger',
|
||||
),
|
||||
clickToHide: this.$locale.baseText('nodeWebhooks.clickToHideWebhookUrls.formTrigger'),
|
||||
clickToCopy: this.$locale.baseText('nodeWebhooks.clickToCopyWebhookUrls.formTrigger'),
|
||||
testUrl: this.$locale.baseText('nodeWebhooks.testUrl'),
|
||||
productionUrl: this.$locale.baseText('nodeWebhooks.productionUrl'),
|
||||
copyTitle: this.$locale.baseText('nodeWebhooks.showMessage.title.formTrigger'),
|
||||
copyMessage: this.$locale.baseText('nodeWebhooks.showMessage.message.formTrigger'),
|
||||
toggleTitle: i18n.baseText('nodeWebhooks.webhookUrls.formTrigger'),
|
||||
clickToDisplay: i18n.baseText('nodeWebhooks.clickToDisplayWebhookUrls.formTrigger'),
|
||||
clickToHide: i18n.baseText('nodeWebhooks.clickToHideWebhookUrls.formTrigger'),
|
||||
clickToCopy: i18n.baseText('nodeWebhooks.clickToCopyWebhookUrls.formTrigger'),
|
||||
testUrl: i18n.baseText('nodeWebhooks.testUrl'),
|
||||
productionUrl: i18n.baseText('nodeWebhooks.productionUrl'),
|
||||
copyTitle: i18n.baseText('nodeWebhooks.showMessage.title.formTrigger'),
|
||||
copyMessage: i18n.baseText('nodeWebhooks.showMessage.message.formTrigger'),
|
||||
};
|
||||
|
||||
default:
|
||||
return {
|
||||
toggleTitle: this.$locale.baseText('nodeWebhooks.webhookUrls'),
|
||||
clickToDisplay: this.$locale.baseText('nodeWebhooks.clickToDisplayWebhookUrls'),
|
||||
clickToHide: this.$locale.baseText('nodeWebhooks.clickToHideWebhookUrls'),
|
||||
clickToCopy: this.$locale.baseText('nodeWebhooks.clickToCopyWebhookUrls'),
|
||||
testUrl: this.$locale.baseText('nodeWebhooks.testUrl'),
|
||||
productionUrl: this.$locale.baseText('nodeWebhooks.productionUrl'),
|
||||
copyTitle: this.$locale.baseText('nodeWebhooks.showMessage.title'),
|
||||
toggleTitle: i18n.baseText('nodeWebhooks.webhookUrls'),
|
||||
clickToDisplay: i18n.baseText('nodeWebhooks.clickToDisplayWebhookUrls'),
|
||||
clickToHide: i18n.baseText('nodeWebhooks.clickToHideWebhookUrls'),
|
||||
clickToCopy: i18n.baseText('nodeWebhooks.clickToCopyWebhookUrls'),
|
||||
testUrl: i18n.baseText('nodeWebhooks.testUrl'),
|
||||
productionUrl: i18n.baseText('nodeWebhooks.productionUrl'),
|
||||
copyTitle: i18n.baseText('nodeWebhooks.showMessage.title'),
|
||||
copyMessage: undefined,
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
node() {
|
||||
this.isMinimized = !OPEN_URL_PANEL_TRIGGER_NODE_TYPES.includes(this.nodeType.name);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
copyWebhookUrl(webhookData: IWebhookDescription): void {
|
||||
const webhookUrl = this.getWebhookUrlDisplay(webhookData);
|
||||
void this.clipboard.copy(webhookUrl);
|
||||
});
|
||||
|
||||
this.showMessage({
|
||||
title: this.baseText.copyTitle,
|
||||
message: this.baseText.copyMessage,
|
||||
function copyWebhookUrl(webhookData: IWebhookDescription): void {
|
||||
const webhookUrl = getWebhookUrlDisplay(webhookData);
|
||||
void clipboard.copy(webhookUrl);
|
||||
|
||||
toast.showMessage({
|
||||
title: baseText.value.copyTitle,
|
||||
message: baseText.value.copyMessage,
|
||||
type: 'success',
|
||||
});
|
||||
this.$telemetry.track('User copied webhook URL', {
|
||||
|
||||
telemetry.track('User copied webhook URL', {
|
||||
pane: 'parameters',
|
||||
type: `${this.showUrlFor} url`,
|
||||
type: `${showUrlFor.value} url`,
|
||||
});
|
||||
},
|
||||
getWebhookUrlDisplay(webhookData: IWebhookDescription): string {
|
||||
if (this.node) {
|
||||
return this.workflowHelpers.getWebhookUrl(
|
||||
}
|
||||
|
||||
function getWebhookUrlDisplay(webhookData: IWebhookDescription): string {
|
||||
if (props.node) {
|
||||
return workflowHelpers.getWebhookUrl(
|
||||
webhookData,
|
||||
this.node,
|
||||
this.isProductionOnly ? 'production' : this.showUrlFor,
|
||||
props.node,
|
||||
isProductionOnly.value ? 'production' : showUrlFor.value,
|
||||
);
|
||||
}
|
||||
return '';
|
||||
},
|
||||
isWebhookMethodVisible(webhook: IWebhookDescription): boolean {
|
||||
}
|
||||
|
||||
function isWebhookMethodVisible(webhook: IWebhookDescription): boolean {
|
||||
try {
|
||||
const method = this.workflowHelpers.getWebhookExpressionValue(webhook, 'httpMethod', false);
|
||||
const method = workflowHelpers.getWebhookExpressionValue(webhook, 'httpMethod', false);
|
||||
if (Array.isArray(method) && method.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {}
|
||||
|
||||
if (typeof webhook.ndvHideMethod === 'string') {
|
||||
return !this.workflowHelpers.getWebhookExpressionValue(webhook, 'ndvHideMethod');
|
||||
return !workflowHelpers.getWebhookExpressionValue(webhook, 'ndvHideMethod');
|
||||
}
|
||||
|
||||
return !webhook.ndvHideMethod;
|
||||
},
|
||||
}
|
||||
|
||||
getWebhookHttpMethod(webhook: IWebhookDescription): string {
|
||||
const method = this.workflowHelpers.getWebhookExpressionValue(webhook, 'httpMethod', false);
|
||||
function getWebhookHttpMethod(webhook: IWebhookDescription): string {
|
||||
const method = workflowHelpers.getWebhookExpressionValue(webhook, 'httpMethod', false);
|
||||
if (Array.isArray(method)) {
|
||||
return method[0];
|
||||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.node,
|
||||
() => {
|
||||
isMinimized.value =
|
||||
props.nodeTypeDescription &&
|
||||
!OPEN_URL_PANEL_TRIGGER_NODE_TYPES.includes(props.nodeTypeDescription.name);
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
Loading…
Reference in a new issue