Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(editor): Add types for dataPinningEventBus (no-changelog) #10499

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/editor-ui/src/components/NodeDetailsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ import {
STICKY_NODE_TYPE,
} from '@/constants';
import { useWorkflowActivate } from '@/composables/useWorkflowActivate';
import type { DataPinningDiscoveryEvent } from '@/event-bus';
import { dataPinningEventBus } from '@/event-bus';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { useNDVStore } from '@/stores/ndv.store';
Expand Down Expand Up @@ -238,7 +239,7 @@ const activeNodeType = computed(() => {
return null;
});

const workflowRunning = computed(() => uiStore.isActionActive['workflowRunning']);
const workflowRunning = computed(() => uiStore.isActionActive.workflowRunning);

const showTriggerWaitingWarning = computed(
() =>
Expand Down Expand Up @@ -428,7 +429,7 @@ const featureRequestUrl = computed(() => {

const outputPanelEditMode = computed(() => ndvStore.outputPanelEditMode);

const isWorkflowRunning = computed(() => uiStore.isActionActive['workflowRunning']);
const isWorkflowRunning = computed(() => uiStore.isActionActive.workflowRunning);

const isExecutionWaitingForWebhook = computed(() => workflowsStore.executionWaitingForWebhook);

Expand Down Expand Up @@ -458,7 +459,7 @@ const hasForeignCredential = computed(() => foreignCredentials.value.length > 0)

//methods

const setIsTooltipVisible = ({ isTooltipVisible }: { isTooltipVisible: boolean }) => {
const setIsTooltipVisible = ({ isTooltipVisible }: DataPinningDiscoveryEvent) => {
pinDataDiscoveryTooltipVisible.value = isTooltipVisible;
};

Expand Down
7 changes: 4 additions & 3 deletions packages/editor-ui/src/composables/useNodeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { useCanvasStore } from '@/stores/canvas.store';
import { getEndpointScope } from '@/utils/nodeViewUtils';
import { useSourceControlStore } from '@/stores/sourceControl.store';
import { getConnectionInfo } from '@/utils/canvasUtils';
import type { UnpinNodeDataEvent } from '@/event-bus/data-pinning';

declare namespace HttpRequestNode {
namespace V2 {
Expand Down Expand Up @@ -992,8 +993,8 @@ export function useNodeHelpers() {
});
}

function removePinDataConnections(pinData: IPinData) {
Object.keys(pinData).forEach((nodeName) => {
function removePinDataConnections(event: UnpinNodeDataEvent) {
for (const nodeName of event.nodeNames) {
const node = workflowsStore.getNodeByName(nodeName);
if (!node) {
return;
Expand All @@ -1015,7 +1016,7 @@ export function useNodeHelpers() {
canvasStore.jsPlumbInstance.setSuspendDrawing(true);
connectionsArray.forEach(NodeViewUtils.resetConnection);
canvasStore.jsPlumbInstance.setSuspendDrawing(false, true);
});
}
}

function getOutputEndpointUUID(
Expand Down
22 changes: 21 additions & 1 deletion packages/editor-ui/src/event-bus/data-pinning.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import { createEventBus } from 'n8n-design-system/utils';
import type { IPinData } from 'n8n-workflow';

export const dataPinningEventBus = createEventBus();
export type DataPinningDiscoveryEvent = {
isTooltipVisible: boolean;
};

export type UnpinNodeDataEvent = {
nodeNames: string[];
};

export interface DataPinningEventBusEvents {
/** Command to show or hide the data pinning discovery tooltip */
'data-pinning-discovery': DataPinningDiscoveryEvent;

/** Event that data has been pinned for workflow */
'pin-data': IPinData;

/** Event that data has been unpinned for specific nodes */
'unpin-data': UnpinNodeDataEvent;
}

export const dataPinningEventBus = createEventBus<DataPinningEventBusEvents>();
10 changes: 6 additions & 4 deletions packages/editor-ui/src/stores/workflows.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,14 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
};
}

function setWorkflowPinData(pinData: IPinData) {
function setWorkflowPinData(pinData?: IPinData) {
workflow.value = {
...workflow.value,
pinData: pinData || {},
pinData: pinData ?? {},
};
updateCachedWorkflow();

dataPinningEventBus.emit('pin-data', pinData || {});
dataPinningEventBus.emit('pin-data', pinData ?? {});
}

function setWorkflowTagIds(tags: string[]) {
Expand Down Expand Up @@ -768,7 +768,9 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
uiStore.stateIsDirty = true;
updateCachedWorkflow();

dataPinningEventBus.emit('unpin-data', { [payload.node.name]: undefined });
dataPinningEventBus.emit('unpin-data', {
nodeNames: [payload.node.name],
});
}

function addConnection(data: { connection: IConnection[] }): void {
Expand Down
Loading