fix(editor): Fix type errors in TriggerPanel.vue (no-changelog) (#9578)

This commit is contained in:
Milorad FIlipović 2024-05-31 17:22:27 +02:00 committed by GitHub
parent 05f50c1926
commit 9419c28ff3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 60 deletions

View file

@ -14,7 +14,7 @@
<n8n-text> <n8n-text>
{{ {{
$locale.baseText('ndv.trigger.webhookNode.requestHint', { $locale.baseText('ndv.trigger.webhookNode.requestHint', {
interpolate: { type: webhookHttpMethod }, interpolate: { type: webhookHttpMethod ?? '' },
}) })
}} }}
</n8n-text> </n8n-text>
@ -130,6 +130,7 @@ import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { createEventBus } from 'n8n-design-system/utils'; import { createEventBus } from 'n8n-design-system/utils';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers'; import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
import { isTriggerPanelObject } from '@/utils/typeGuards';
export default defineComponent({ export default defineComponent({
name: 'TriggerPanel', name: 'TriggerPanel',
@ -141,11 +142,14 @@ export default defineComponent({
props: { props: {
nodeName: { nodeName: {
type: String, type: String,
required: true,
}, },
pushRef: { pushRef: {
type: String, type: String,
default: '',
}, },
}, },
emits: { activate: null, execute: null },
setup() { setup() {
const router = useRouter(); const router = useRouter();
const workflowHelpers = useWorkflowHelpers({ router }); const workflowHelpers = useWorkflowHelpers({ router });
@ -162,7 +166,7 @@ export default defineComponent({
computed: { computed: {
...mapStores(useNodeTypesStore, useNDVStore, useUIStore, useWorkflowsStore), ...mapStores(useNodeTypesStore, useNDVStore, useUIStore, useWorkflowsStore),
node(): INodeUi | null { node(): INodeUi | null {
return this.workflowsStore.getNodeByName(this.nodeName as string); return this.workflowsStore.getNodeByName(this.nodeName);
}, },
nodeType(): INodeTypeDescription | null { nodeType(): INodeTypeDescription | null {
if (this.node) { if (this.node) {
@ -171,28 +175,26 @@ export default defineComponent({
return null; return null;
}, },
triggerPanel() {
const panel = this.nodeType?.triggerPanel;
if (isTriggerPanelObject(panel)) {
return panel;
}
return undefined;
},
hideContent(): boolean { hideContent(): boolean {
if (!this.nodeType?.triggerPanel) { const hideContent = this.triggerPanel?.hideContent;
return false; if (typeof hideContent === 'boolean') {
return hideContent;
} }
if ( if (this.node) {
this.nodeType?.triggerPanel && const hideContentValue = this.workflowHelpers
this.nodeType?.triggerPanel.hasOwnProperty('hideContent') .getCurrentWorkflow()
) { .expression.getSimpleParameterValue(this.node, hideContent, 'internal', {});
const hideContent = this.nodeType?.triggerPanel.hideContent;
if (typeof hideContent === 'boolean') {
return hideContent;
}
if (this.node) { if (typeof hideContentValue === 'boolean') {
const hideContentValue = this.workflowHelpers return hideContentValue;
.getCurrentWorkflow()
.expression.getSimpleParameterValue(this.node, hideContent, 'internal', {});
if (typeof hideContentValue === 'boolean') {
return hideContentValue;
}
} }
} }
@ -200,7 +202,7 @@ export default defineComponent({
}, },
hasIssues(): boolean { hasIssues(): boolean {
return Boolean( return Boolean(
this.node?.issues && (this.node.issues.parameters || this.node.issues.credentials), this.node?.issues && (this.node.issues.parameters ?? this.node.issues.credentials),
); );
}, },
serviceName(): string { serviceName(): string {
@ -296,8 +298,8 @@ export default defineComponent({
return this.$locale.baseText('ndv.trigger.pollingNode.fetchingEvent'); return this.$locale.baseText('ndv.trigger.pollingNode.fetchingEvent');
} }
if (this.nodeType?.triggerPanel && typeof this.nodeType.triggerPanel.header === 'string') { if (this.triggerPanel?.header) {
return this.nodeType.triggerPanel.header; return this.triggerPanel.header;
} }
if (this.isWebhookBasedNode) { if (this.isWebhookBasedNode) {
@ -319,15 +321,15 @@ export default defineComponent({
return ''; return '';
}, },
executionsHelp(): string { executionsHelp(): string {
if (this.nodeType?.triggerPanel?.executionsHelp !== undefined) { if (this.triggerPanel?.executionsHelp) {
if (typeof this.nodeType.triggerPanel.executionsHelp === 'string') { if (typeof this.triggerPanel.executionsHelp === 'string') {
return this.nodeType.triggerPanel.executionsHelp; return this.triggerPanel.executionsHelp;
} }
if (!this.isWorkflowActive && this.nodeType.triggerPanel.executionsHelp.inactive) { if (!this.isWorkflowActive && this.triggerPanel.executionsHelp.inactive) {
return this.nodeType.triggerPanel.executionsHelp.inactive; return this.triggerPanel.executionsHelp.inactive;
} }
if (this.isWorkflowActive && this.nodeType.triggerPanel.executionsHelp.active) { if (this.isWorkflowActive && this.triggerPanel.executionsHelp.active) {
return this.nodeType.triggerPanel.executionsHelp.active; return this.triggerPanel.executionsHelp.active;
} }
} }
@ -358,25 +360,22 @@ export default defineComponent({
return ''; return '';
}, },
activationHint(): string { activationHint(): string {
if (this.isActivelyPolling) { if (this.isActivelyPolling || !this.triggerPanel) {
return ''; return '';
} }
if (this.nodeType?.triggerPanel?.activationHint) { if (this.triggerPanel.activationHint) {
if (typeof this.nodeType.triggerPanel.activationHint === 'string') { if (typeof this.triggerPanel.activationHint === 'string') {
return this.nodeType.triggerPanel.activationHint; return this.triggerPanel.activationHint;
} }
if ( if (
!this.isWorkflowActive && !this.isWorkflowActive &&
typeof this.nodeType.triggerPanel.activationHint.inactive === 'string' typeof this.triggerPanel.activationHint.inactive === 'string'
) { ) {
return this.nodeType.triggerPanel.activationHint.inactive; return this.triggerPanel.activationHint.inactive;
} }
if ( if (this.isWorkflowActive && typeof this.triggerPanel.activationHint.active === 'string') {
this.isWorkflowActive && return this.triggerPanel.activationHint.active;
typeof this.nodeType.triggerPanel.activationHint.active === 'string'
) {
return this.nodeType.triggerPanel.activationHint.active;
} }
} }

View file

@ -1,4 +1,9 @@
import type { INodeParameterResourceLocator, NodeConnectionType } from 'n8n-workflow'; import type {
INodeParameterResourceLocator,
INodeTypeDescription,
NodeConnectionType,
TriggerPanelDefinition,
} from 'n8n-workflow';
import { nodeConnectionTypes } from 'n8n-workflow'; import { nodeConnectionTypes } from 'n8n-workflow';
import type { ICredentialsResponse, NewCredentialsModal } from '@/Interface'; import type { ICredentialsResponse, NewCredentialsModal } from '@/Interface';
@ -56,3 +61,9 @@ export function isValidNodeConnectionType(
): connectionType is NodeConnectionType { ): connectionType is NodeConnectionType {
return nodeConnectionTypes.includes(connectionType as NodeConnectionType); return nodeConnectionTypes.includes(connectionType as NodeConnectionType);
} }
export function isTriggerPanelObject(
triggerPanel: INodeTypeDescription['triggerPanel'],
): triggerPanel is TriggerPanelDefinition {
return triggerPanel !== undefined && typeof triggerPanel === 'object' && triggerPanel !== null;
}

View file

@ -1766,29 +1766,19 @@ export interface INodeTypeDescription extends INodeTypeBaseDescription {
webhooks?: IWebhookDescription[]; webhooks?: IWebhookDescription[];
translation?: { [key: string]: object }; translation?: { [key: string]: object };
mockManualExecution?: true; mockManualExecution?: true;
triggerPanel?: triggerPanel?: TriggerPanelDefinition | boolean;
| {
hideContent?: boolean | string;
header?: string;
executionsHelp?:
| string
| {
active: string;
inactive: string;
};
activationHint?:
| string
| {
active: string;
inactive: string;
};
}
| boolean;
extendsCredential?: string; extendsCredential?: string;
hints?: NodeHint[]; hints?: NodeHint[];
__loadOptionsMethods?: string[]; // only for validation during build __loadOptionsMethods?: string[]; // only for validation during build
} }
export type TriggerPanelDefinition = {
hideContent?: boolean | string;
header?: string;
executionsHelp?: string | { active: string; inactive: string };
activationHint?: string | { active: string; inactive: string };
};
export type NodeHint = { export type NodeHint = {
message: string; message: string;
type?: 'info' | 'warning' | 'danger'; type?: 'info' | 'warning' | 'danger';