Skip to content

Commit

Permalink
refactor(editor): Add types to global link actions event bus (no-chan…
Browse files Browse the repository at this point in the history
…gelog) (n8n-io#10452)

Co-authored-by: Alex Grozav <[email protected]>
  • Loading branch information
tomi and alexgrozav authored Aug 20, 2024
1 parent 61ac0c7 commit 51f3e84
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/editor-ui/src/composables/useGlobalLinkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
* unsafe onclick attribute
*/
import { reactive, computed, onMounted, onUnmounted } from 'vue';
import type { LinkActionFn, RegisterCustomActionOpts } from '@/event-bus';
import { globalLinkActionsEventBus } from '@/event-bus';

const state = reactive({
customActions: {} as Record<string, Function>,
customActions: {} as Record<string, LinkActionFn>,
delegatedClickHandler: null as null | ((e: MouseEvent) => void),
});

export function useGlobalLinkActions() {
function registerCustomAction({ key, action }: { key: string; action: Function }) {
function registerCustomAction({ key, action }: RegisterCustomActionOpts) {
state.customActions[key] = action;
}
function unregisterCustomAction(key: string) {
Expand Down Expand Up @@ -51,7 +52,7 @@ export function useGlobalLinkActions() {
}
}

const availableActions = computed<{ [key: string]: Function }>(() => ({
const availableActions = computed<{ [key: string]: LinkActionFn }>(() => ({
reload,
...state.customActions,
}));
Expand Down
16 changes: 16 additions & 0 deletions packages/editor-ui/src/event-bus/global-link-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createEventBus } from 'n8n-design-system/utils';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type LinkActionFn = (...args: any[]) => void;

export type RegisterCustomActionOpts = {
key: string;
action: LinkActionFn;
};

export interface GlobalLinkActionsEventBusEvents {
/** See useGlobalLinkActions.ts */
registerGlobalLinkAction: RegisterCustomActionOpts;
}

export const globalLinkActionsEventBus = createEventBus<GlobalLinkActionsEventBusEvents>();
2 changes: 1 addition & 1 deletion packages/editor-ui/src/event-bus/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './code-node-editor';
export * from './data-pinning';
export * from './link-actions';
export * from './global-link-actions';
export * from './html-editor';
export * from './import-curl';
export * from './node-view';
Expand Down
3 changes: 0 additions & 3 deletions packages/editor-ui/src/event-bus/link-actions.ts

This file was deleted.

0 comments on commit 51f3e84

Please sign in to comment.