Files
Automata/packages/editor-ui/src/components/TriggerPanel.vue
Alex Grozav 15693b0056 feat(editor): Add data pinning functionality (#3511)
* feat: Design system color improvements and button component redesign.

* feat: Added button focus state and unit tests.

* refactor: Aligned n8n-button usage inside of editor-ui.

* test: Updated snapshots.

* refactor: Extracted focus outline width into scss variable.

* fix: Fixed select input border-radius.

* refactor: Removed element-ui references in button.

* fix: Fixed scss variable imports.

* feat: Added color-neutral variable story.

* fix: Fixed color-secondary variable definition.

* feat: Added color-white story.

* test: Updated button snapshot.

* feat: Replaced zoom buttons with new n8n-icon-button.

* feat: Added stories for float utilities.

* chore: Updated color shades generation code for later use.

* chore: Removed color-white code.

* chore: Updated story properties for button components.

* fix: Added el-button fallback for places where el-button is not replaceable (messagebox).

* feat: Reverted to css modules. Replaced el-button with n8n-button at application level.

* test: Updated button snapshot.

* fix: Fixed element-ui locally referenced buttons (via components: {}).

* fix: Updated colors. Removed irrelevant validation. Added ElButton override component.

* test: Updated button override snapshot.

* fix: Various button adjustments and fixes.

* fix: Updated button disabled state.

* test: Updated snapshots.

* fix: Consolidated css variables changes.

* Data pinning (#3512)

* refactor: Aligned n8n-button usage inside of editor-ui.

* feat: Added edit data button on json hover.

* feat: Extracted code editor into separate form component.

* feat: Added edit data button on json hover.

* feat: Added pinData and edit mode methods.

* 🔥 Remove conflict markers

* ✏️ Update i18n keys

*  Add JSON validation

* 🗃️ Add `pinData` column to `workflow_entity`

* 📘 Tighten type

*  Make `pinData` column nullable

*  Adjust workflow endpoints for pin data

* 📘 Improve types

* ✏️ Improve wording

* Inject pindata into items flow (#3420)

*  Inject pin data - Second approach

* 🔥 Remove unneeded lint exception

* feat: Added edit data button on json hover.

* feat: Extracted code editor into separate form component.

* feat: Added edit data button on json hover.

* fix: Fixed rebase conflicts.

*  Undo button change

* 🐛 Fix runNode call

Adjust per update in bdb84130d6

* 🧪 Fix workflow tests

* 🐛 More merge conflict fixes

* feat: Added pin/unpin button and store mutations.

* feat: Size check. Various design and ux improvements.

*  Add transformer

*  Hoist pin data

*  Adjust endpoints for hoisted pin data

* 📘 Expand interface

* 🐛 Fix stray array

* 👕 Fix build

* 👕 Add lint exception

* 👕 Fix header

* 🎨 Add color secondary tints

*  Create `HeaderMessage` component

*  Adjust `InfoTip` component

*  Add `HeaderMessage` to `RunData`

* 🐛 Fix console error

* 👕 Fix lint

*  Consolidate `HeaderMessage` and `Callout`

*  Undo `InfoTip` changes

* 🔥 Remove duplicate icons

*  Simplify template

* 🎨 Change cursor for action text

* 👕 Fix lint

*  Add URL

* 🐛 Fix handler name

*  Use constant

* ♻️ Refactor per feedback

* fix: Various fixes after data pinning relocation.

* fix: Added store mutation for setting pinned data.

* feat: Added pinned state for workflow canvas node.

* fix: Fixed workflow saving.

* fix: Removed pinData hoisting (no longer necessary).

* feat: Added canPinData flag to hide for input pane and binary data. Fixed unpin and execute flow.

*  Fixes for canvas pin data (#3587)

*  Fixes for canvas pin data

* 📘 Rename type

* 🧪 Fix unrelated Public API test

* 🔥 Remove logging

* feat: Updated pinData mixin to no longer include extra fields.

*  Output same pindata for every run

* 🎨 Fix cropping

* 🔥 Remove unrelated logging

* feat: Moved edit button next to pin button.

* feat: Changed data to be inserted for empty state.

* chore: Changed invalid editor output translation.

* feat: Added error line reporting on JSON Validation.

* feat: Migrated pinData edit mode to store.

* chore: Merged duplicate node border color condition.

* feat: Moved pin data validation to mixin. Added check before closing ndv modal.

* fix: Changed pinned data size calculation to discard active node pin data.

* feat: Added support for rename and delete node with pin data.

* feat: Simplified editing state. Fixed edit mode in input panel after store migration.

* feat: Various data pinning improvements.

* fix: Fixed callout link underline.

* refactor: Added support for both string and objects for data size check.

* feat: Added disabled node check for input panel. Fixed monaco editor resizing.

* fix: Fixed edit mode footer size.

*  Fix pindata items per run

* 👕 Remove unneeded exception

* refactor: Added isValidPinData() helper method.

* refactor: Changed how string size in bytes in calculated.g

* refactor: Updated pinData mixin interface.

* refactor: Merged filter and reduce in pinDataSize calculation.

* fix: Changed code-editor to correct type.

* fix: Added insert test data message to trigger nodes.

* feat: Disabled data pinning for multiple output nodes.

* refactor: Updated ndv.input.disabled translation to include node name.

* refactor: Aligned n8n-button usage inside of editor-ui.

* feat: Added edit data button on json hover.

* feat: Extracted code editor into separate form component.

* feat: Added edit data button on json hover.

* feat: Added pinData and edit mode methods.

* 🔥 Remove conflict markers

* ✏️ Update i18n keys

*  Add JSON validation

* 🗃️ Add `pinData` column to `workflow_entity`

* 📘 Tighten type

*  Make `pinData` column nullable

*  Adjust workflow endpoints for pin data

* 📘 Improve types

* ✏️ Improve wording

* Inject pindata into items flow (#3420)

*  Inject pin data - Second approach

* 🔥 Remove unneeded lint exception

* feat: Added edit data button on json hover.

* feat: Extracted code editor into separate form component.

* feat: Added edit data button on json hover.

* fix: Fixed rebase conflicts.

*  Undo button change

* 🐛 Fix runNode call

Adjust per update in bdb84130d6

* 🧪 Fix workflow tests

* 🐛 More merge conflict fixes

* feat: Added pin/unpin button and store mutations.

* feat: Size check. Various design and ux improvements.

*  Add transformer

*  Hoist pin data

*  Adjust endpoints for hoisted pin data

* 📘 Expand interface

* 🐛 Fix stray array

* 👕 Fix build

* 🎨 Add color secondary tints

*  Create `HeaderMessage` component

*  Adjust `InfoTip` component

*  Add `HeaderMessage` to `RunData`

* 🐛 Fix console error

* 👕 Fix lint

*  Consolidate `HeaderMessage` and `Callout`

*  Undo `InfoTip` changes

* 🔥 Remove duplicate icons

*  Simplify template

* 🎨 Change cursor for action text

* 👕 Fix lint

*  Add URL

* 🐛 Fix handler name

*  Use constant

* ♻️ Refactor per feedback

* fix: Various fixes after data pinning relocation.

* fix: Added store mutation for setting pinned data.

* feat: Added pinned state for workflow canvas node.

*  Fixes for canvas pin data (#3587)

*  Fixes for canvas pin data

* 📘 Rename type

* 🧪 Fix unrelated Public API test

* 🔥 Remove logging

* feat: Updated pinData mixin to no longer include extra fields.

* fix: Removed pinData hoisting (no longer necessary).

* chore: Merged duplicate node border color condition.

*  Output same pindata for every run

* 🎨 Fix cropping

* 🐛 Fix excess closing template tag

* fix: Removed rogue template tag after merge.

* fix: Fixed code-editor resizing when moving ndv panel.

* feat: Added node duplication pin data.

*  Implement telemetry

* ♻️ Add clarifications from call

* fix: Fixed run data header height.

* feat: Removed border from pin data callout.

* feat: Added line-break before 'or insert pin data'.

* feat: Changed enterEditMode to always insert test data if there's no execution data.

* feat: Removed copy output tooltip.

* feat: Removed unpin tooltip.

* fix: Removed thumbtack icon rotation.

* fix: Removed run info from Edit Output title.

* feat: Hid edit and pin buttons when editing.

* feat: Updated monaco code-editor padding and borders.

* feat: Progress on pinData error message format

* feat: Updated copy feature to work without any selected value.

* feat: Moved save and cancel buttons. Cleared notifications on save.

* feat: Changed pin data beforeClosing confirm text.

* feat: Closing ndv when discarding or saving pindata on close.

* feat: Added split in batches node to pin data denylist.

* fix: Added missing margin-bottom to webhook node.

* feat: Moved thumbtack icon to the right, replacing the checkmark.

* fix: Hid pagination while editing.

* feat: Added pin data discovery flow.

* feat: Changed pin data discovery flow to avoid tooltip glitching.

* fix: Changed copy selection to copy all input data.

* feat: Updated pin data validation error message for unexpected single quotes.

* fix: Replaced :manual='true' prop with manual shorthand.

* fix: Removed unused variable.

* chore: Renamed translation key to node.discovery.pinData.

* refactor: Extracted isPinDataNodeType to pinData mixin.

* fix: Updated watch condition to improve performance.

* refactor: Renamed some pin data variables and methods as per review.

* fix: Added partial translation for JSON.parse pin data error messages.

* chore: Temporarily disabled failing unit test.

* 🧪 Fix data pinning workflow retrieval test

* 🔥 Remove unused imports

* 🔥 Remove leftover line

*  Skip pindata node issues on BE

*  Skip pindata node issues on FE

*  Hide `RunInfo` for pindata node

*  Hide purple banner in edit output mode

* feat: Updated data pinning discoverability flow.

* fix: Fixed paginated data pinning.

* fix: Disabled pin data in read only mode.

* 🐛 Fix runtime error with non-array

* fix: Loading pin data when opening execution.

*  Adjust stale data warning for pinned data

*  Skip auth in endpoint

*  Mark start node for pinned trigger

* ✏️ Comment on passthrough

* 🔥 Remove comment

* Final pindata metrics changes (#3673)

* 🐛 Fix `pinData` tracked as `0`

*  Add `is_pinned` to `nodesGraph`

* 📘 Extend `IWorkflowBase`

*  Handle `pinData` being `undefined`

*  Add `data_pinning_tooltip_presented`

* ♻️ Refactor to remove circular dependency

* fix: Added pin data handling when importing workflow. (#3698)

* 🔥 Remove helper from WorkflowExecute

*  Add logic for single pinned trigger

* 👕 Remove lint exception

* fix: Added pin data handling in importWorkflowExact.

* N8N-4077 data pinning discoverability part 2 (#3701)

* fix: Fixed pin data discovery tooltip position when moving canvas.

* feat: Updated data pinning discovery tooltip copy.

* Fix data pinning build (#3702)

*  Disable edit button for disabled node

*  Ensure disabled pinned nodes are passthrough

* 🐛 Fix JSON key unfurling in edit mode

*  Improve implementation

* 🐛 Fix console error

* fix: Fixed copying pinned output data. (#3715)

* Fix pinning for webhook responding with output from last node (#3719)

* fix: Fixed entering edit mode after refresh.

* fix: Fixed type error during build.

* fix: RunData import formatting.

* chore: Updated pin data types.

* fix: Added missing type to stringSizeInBytes.

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>

* fix: Showing pin data without executing the node only in output pane.

* fix: Updated no data message when previous node not executed.

* feat: Added expression input and evaluation for pin data nodes without execution.

* chore: Fixed linting issues and removed remnant console.log().

* chore: Undone package-lock changes.

* fix: Removed pin data store changes.

* fix: Created a new object using vuex runExecutionData.

* fix: Fixed bug appearing when adding a new node after executing.

* fix: Fix editor-ui build

* feat: Added green node connectors when having pin data output.

* chore: Fixed linting errors.

* fix: Added pin data eventBus unsubscribe.

* fix: Added pin data color check after adding a connection.

* 🎨 Add pindata styles

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
2022-07-20 17:50:39 +02:00

464 lines
12 KiB
Vue

<template>
<div :class="$style.container">
<transition name="fade" mode="out-in">
<div key="empty" v-if="hasIssues"></div>
<div key="listening" v-else-if="isListeningForEvents">
<n8n-pulse>
<NodeIcon :nodeType="nodeType" :size="40"></NodeIcon>
</n8n-pulse>
<div v-if="isWebhookNode">
<n8n-text tag="div" size="large" color="text-dark" class="mb-2xs" bold>{{
$locale.baseText('ndv.trigger.webhookNode.listening')
}}</n8n-text>
<div :class="[$style.shake, 'mb-xs']">
<n8n-text>
{{
$locale.baseText('ndv.trigger.webhookNode.requestHint', {
interpolate: { type: this.webhookHttpMethod },
})
}}
</n8n-text>
</div>
<CopyInput
:value="webhookTestUrl"
:toastTitle="$locale.baseText('ndv.trigger.copiedTestUrl')"
class="mb-2xl"
size="medium"
:collapse="true"
:copy-button-text="$locale.baseText('generic.clickToCopy')"
@copy="onTestLinkCopied"
></CopyInput>
</div>
<div v-else>
<n8n-text tag="div" size="large" color="text-dark" class="mb-2xs" bold>{{
$locale.baseText('ndv.trigger.webhookBasedNode.listening')
}}</n8n-text>
<div :class="[$style.shake, 'mb-xs']">
<n8n-text tag="div">
{{
$locale.baseText('ndv.trigger.webhookBasedNode.serviceHint', {
interpolate: { service: serviceName },
})
}}
</n8n-text>
</div>
</div>
</div>
<div key="default" v-else>
<div class="mb-xl" v-if="isActivelyPolling">
<n8n-spinner type="ring" />
</div>
<div :class="$style.action">
<div :class="$style.header">
<n8n-heading v-if="header" tag="h1" bold>
{{ header }}
</n8n-heading>
<n8n-text v-if="subheader">
<span v-html="subheader"></span>
</n8n-text>
</div>
<NodeExecuteButton
v-if="!isActivelyPolling"
:nodeName="nodeName"
@execute="onNodeExecute"
size="medium"
telemetrySource="inputs"
/>
</div>
<n8n-text size="small" @click="onLinkClick" v-if="activationHint">
<span v-html="activationHint"></span>&nbsp;
</n8n-text>
<n8n-link
size="small"
v-if="activationHint && executionsHelp"
@click="expandExecutionHelp"
>{{ $locale.baseText('ndv.trigger.moreInfo') }}</n8n-link
>
<n8n-info-accordion
ref="help"
v-if="executionsHelp"
:class="$style.accordion"
:title="$locale.baseText('ndv.trigger.executionsHint.question')"
:description="executionsHelp"
@click="onLinkClick"
></n8n-info-accordion>
</div>
</transition>
</div>
</template>
<script lang="ts">
import { EXECUTIONS_MODAL_KEY, WEBHOOK_NODE_TYPE, WORKFLOW_SETTINGS_MODAL_KEY } from '@/constants';
import { INodeUi } from '@/Interface';
import { INodeTypeDescription } from 'n8n-workflow';
import { getTriggerNodeServiceName } from './helpers';
import NodeExecuteButton from './NodeExecuteButton.vue';
import { workflowHelpers } from './mixins/workflowHelpers';
import mixins from 'vue-typed-mixins';
import CopyInput from './CopyInput.vue';
import NodeIcon from './NodeIcon.vue';
import { copyPaste } from './mixins/copyPaste';
import { showMessage } from '@/components/mixins/showMessage';
import Vue from 'vue';
export default mixins(workflowHelpers, copyPaste, showMessage).extend({
name: 'TriggerPanel',
components: {
NodeExecuteButton,
CopyInput,
NodeIcon,
},
props: {
nodeName: {
type: String,
},
sessionId: {
type: String,
},
},
computed: {
node(): INodeUi | null {
return this.$store.getters.getNodeByName(this.nodeName);
},
nodeType(): INodeTypeDescription | null {
if (this.node) {
return this.$store.getters.nodeType(this.node.type, this.node.typeVersion);
}
return null;
},
hasIssues(): boolean {
return Boolean(
this.node &&
this.node.issues &&
(this.node.issues.parameters || this.node.issues.credentials),
);
},
serviceName(): string {
if (this.nodeType) {
return getTriggerNodeServiceName(this.nodeType);
}
return '';
},
isWebhookNode(): boolean {
return Boolean(this.node && this.node.type === WEBHOOK_NODE_TYPE);
},
webhookHttpMethod(): string | undefined {
if (
!this.node ||
!this.nodeType ||
!this.nodeType.webhooks ||
!this.nodeType.webhooks.length
) {
return undefined;
}
return this.getWebhookExpressionValue(this.nodeType.webhooks[0], 'httpMethod');
},
webhookTestUrl(): string | undefined {
if (
!this.node ||
!this.nodeType ||
!this.nodeType.webhooks ||
!this.nodeType.webhooks.length
) {
return undefined;
}
return this.getWebhookUrl(this.nodeType.webhooks[0], this.node, 'test');
},
webhookProdUrl(): string | undefined {
if (
!this.node ||
!this.nodeType ||
!this.nodeType.webhooks ||
!this.nodeType.webhooks.length
) {
return undefined;
}
return this.getWebhookUrl(this.nodeType.webhooks[0], this.node, 'prod');
},
isWebhookBasedNode(): boolean {
return Boolean(this.nodeType && this.nodeType.webhooks && this.nodeType.webhooks.length);
},
isPollingNode(): boolean {
return Boolean(this.nodeType && this.nodeType.polling);
},
isListeningForEvents(): boolean {
const waitingOnWebhook = this.$store.getters.executionWaitingForWebhook as boolean;
const executedNode = this.$store.getters.executedNode as string | undefined;
return (
!!this.node &&
!this.node.disabled &&
this.isWebhookBasedNode &&
waitingOnWebhook &&
(!executedNode || executedNode === this.nodeName)
);
},
workflowRunning(): boolean {
return this.$store.getters.isActionActive('workflowRunning');
},
isActivelyPolling(): boolean {
const triggeredNode = this.$store.getters.executedNode;
return this.workflowRunning && this.isPollingNode && this.nodeName === triggeredNode;
},
isWorkflowActive(): boolean {
return this.$store.getters.isActive;
},
header(): string {
const serviceName = this.nodeType ? getTriggerNodeServiceName(this.nodeType) : '';
if (this.isActivelyPolling) {
return this.$locale.baseText('ndv.trigger.pollingNode.fetchingEvent');
}
if (
this.nodeType &&
this.nodeType.triggerPanel &&
typeof this.nodeType.triggerPanel.header === 'string'
) {
return this.nodeType.triggerPanel.header;
}
if (this.isWebhookBasedNode) {
return this.$locale.baseText('ndv.trigger.webhookBasedNode.action', {
interpolate: { name: serviceName },
});
}
return '';
},
subheader(): string {
const serviceName = this.nodeType ? getTriggerNodeServiceName(this.nodeType) : '';
if (this.isActivelyPolling) {
return this.$locale.baseText('ndv.trigger.pollingNode.fetchingHint', {
interpolate: { name: serviceName },
});
}
return '';
},
executionsHelp(): string {
if (
this.nodeType &&
this.nodeType.triggerPanel &&
this.nodeType.triggerPanel.executionsHelp !== undefined
) {
if (typeof this.nodeType.triggerPanel.executionsHelp === 'string') {
return this.nodeType.triggerPanel.executionsHelp;
}
if (!this.isWorkflowActive && this.nodeType.triggerPanel.executionsHelp.inactive) {
return this.nodeType.triggerPanel.executionsHelp.inactive;
}
if (this.isWorkflowActive && this.nodeType.triggerPanel.executionsHelp.active) {
return this.nodeType.triggerPanel.executionsHelp.active;
}
}
if (this.isWebhookBasedNode) {
if (this.isWorkflowActive) {
return this.$locale.baseText('ndv.trigger.webhookBasedNode.executionsHelp.active', {
interpolate: { service: this.serviceName },
});
} else {
return this.$locale.baseText('ndv.trigger.webhookBasedNode.executionsHelp.inactive', {
interpolate: { service: this.serviceName },
});
}
}
if (this.isPollingNode) {
if (this.isWorkflowActive) {
return this.$locale.baseText('ndv.trigger.pollingNode.executionsHelp.active', {
interpolate: { service: this.serviceName },
});
} else {
return this.$locale.baseText('ndv.trigger.pollingNode.executionsHelp.inactive', {
interpolate: { service: this.serviceName },
});
}
}
return '';
},
activationHint(): string {
if (this.isActivelyPolling) {
return '';
}
if (
this.nodeType &&
this.nodeType.triggerPanel &&
this.nodeType.triggerPanel.activationHint
) {
if (typeof this.nodeType.triggerPanel.activationHint === 'string') {
return this.nodeType.triggerPanel.activationHint;
}
if (
!this.isWorkflowActive &&
typeof this.nodeType.triggerPanel.activationHint.inactive === 'string'
) {
return this.nodeType.triggerPanel.activationHint.inactive;
}
if (
this.isWorkflowActive &&
typeof this.nodeType.triggerPanel.activationHint.active === 'string'
) {
return this.nodeType.triggerPanel.activationHint.active;
}
}
if (this.isWebhookBasedNode) {
if (this.isWorkflowActive) {
return this.$locale.baseText('ndv.trigger.webhookBasedNode.activationHint.active', {
interpolate: { service: this.serviceName },
});
}
else {
return this.$locale.baseText('ndv.trigger.webhookBasedNode.activationHint.inactive', {
interpolate: { service: this.serviceName },
});
}
}
if (this.isPollingNode) {
if (this.isWorkflowActive) {
return this.$locale.baseText('ndv.trigger.pollingNode.activationHint.active', {
interpolate: { service: this.serviceName },
});
}
else {
return this.$locale.baseText('ndv.trigger.pollingNode.activationHint.inactive', {
interpolate: { service: this.serviceName },
});
}
}
return '';
},
},
methods: {
expandExecutionHelp() {
if (this.$refs.help) {
(this.$refs.help as Vue).$emit('expand');
}
},
onLinkClick(e: MouseEvent) {
if (!e.target) {
return;
}
const target = e.target as HTMLElement;
if (target.localName !== 'a') return;
if (target.dataset && target.dataset.key) {
e.stopPropagation();
e.preventDefault();
if (target.dataset.key === 'activate') {
this.$emit('activate');
} else if (target.dataset.key === 'executions') {
this.$telemetry.track('User clicked ndv link', {
workflow_id: this.$store.getters.workflowId,
session_id: this.sessionId,
pane: 'input',
type: 'open-executions-log',
});
this.$store.commit('setActiveNode', null);
this.$store.dispatch('ui/openModal', EXECUTIONS_MODAL_KEY);
} else if (target.dataset.key === 'settings') {
this.$store.dispatch('ui/openModal', WORKFLOW_SETTINGS_MODAL_KEY);
}
}
},
onTestLinkCopied() {
this.$telemetry.track('User copied webhook URL', {
pane: 'inputs',
type: 'test url',
});
},
onNodeExecute() {
this.$emit('execute');
},
},
});
</script>
<style lang="scss" module>
.container {
position: relative;
width: 100%;
height: 100%;
background-color: var(--color-background-base);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: var(--spacing-s) var(--spacing-s) var(--spacing-xl) var(--spacing-s);
text-align: center;
overflow: hidden;
> * {
width: 100%;
}
}
.header {
margin-bottom: var(--spacing-s);
> * {
margin-bottom: var(--spacing-2xs);
}
}
.action {
margin-bottom: var(--spacing-2xl);
}
.shake {
animation: shake 8s infinite;
}
@keyframes shake {
90% {
transform: translateX(0);
}
92.5% {
transform: translateX(6px);
}
95% {
transform: translateX(-6px);
}
97.5% {
transform: translateX(6px);
}
100% {
transform: translateX(0);
}
}
.accordion {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
</style>
<style lang="scss" scoped>
.fade-enter-active,
.fade-leave-active {
transition: opacity 200ms;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
}
</style>