Skip to content

Commit e0a745c

Browse files
2
1 parent 52e97f2 commit e0a745c

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

assets/js/hooks/KeyHandlers.ts

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ function createKeyCombinationHook(
126126
): PhoenixHook {
127127
return {
128128
mounted() {
129-
// Debug logging for OpenRunPanelViaCtrlEnter hook
130-
if (action === openRunPanelAction) {
131-
console.log('🔧 OpenRunPanelViaCtrlEnter hook mounted successfully!');
132-
}
133-
134129
const handler = { hook: this, keyCheck, action, priority, bindingScope };
135130
keyHandlers.add(handler);
136131

@@ -139,11 +134,6 @@ function createKeyCombinationHook(
139134
this.callback = (e: KeyboardEvent) => {
140135
if (!keyCheck(e)) return;
141136

142-
// Debug logging for Ctrl+Enter
143-
if (action === openRunPanelAction && keyCheck === isCtrlOrMetaEnter) {
144-
console.log('⌨️ Ctrl+Enter detected by OpenRunPanelViaCtrlEnter hook');
145-
}
146-
147137
e.preventDefault();
148138

149139
const target = e.target as HTMLElement;
@@ -378,26 +368,52 @@ export const CloseNodePanelViaEscape = createKeyCombinationHook(
378368
);
379369

380370
/**
381-
* Navigates to the run panel by clicking the existing run button.
371+
* Handles Ctrl+Enter to either open run panel or execute workflow.
382372
*
383373
* @param e - The keyboard event that triggered the action.
384374
* @param el - The DOM element associated with the hook.
385375
*/
386376
const openRunPanelAction = (_e: KeyboardEvent, _el: HTMLElement) => {
387-
console.log('🚀 OpenRunPanelViaCtrlEnter action triggered!');
377+
// Check if run panel is already open by looking at the URL
378+
const isRunPanelOpen = window.location.href.includes('m=workflow_input');
388379

389-
// Find the existing run button and click it
390-
const runButton = document.querySelector('a[href*="m=workflow_input"]') as HTMLAnchorElement;
391-
console.log('🔍 Found run button:', runButton);
392-
393-
if (runButton) {
394-
console.log('✅ Clicking run button with href:', runButton.href);
395-
runButton.click();
380+
if (isRunPanelOpen) {
381+
// Panel is open, try to click the "Run Workflow Now" button
382+
// Look for various possible selectors for the run button
383+
const selectors = [
384+
'button[type="submit"][form*="manual_run"]',
385+
'button[id*="save-and-run"]',
386+
'button[phx-click*="manual_run"]',
387+
'input[type="submit"][form*="manual"]'
388+
];
389+
390+
let foundButton: HTMLElement | null = null;
391+
392+
// Try CSS selectors first
393+
for (const selector of selectors) {
394+
const element = document.querySelector(selector) as HTMLElement;
395+
if (element && !element.hasAttribute('disabled')) {
396+
foundButton = element;
397+
break;
398+
}
399+
}
400+
401+
// If no specific selector worked, search for buttons containing "Run"
402+
if (!foundButton) {
403+
const buttons = document.querySelectorAll('button, input[type="submit"]');
404+
foundButton = Array.from(buttons).find(btn => {
405+
const text = btn.textContent?.toLowerCase() || '';
406+
return text.includes('run') && !btn.hasAttribute('disabled');
407+
}) as HTMLElement | undefined || null;
408+
}
409+
410+
if (foundButton) {
411+
foundButton.click();
412+
}
396413
} else {
397-
console.log('❌ No run button found');
398-
// Let's also check for other run-related buttons
399-
const allRunButtons = document.querySelectorAll('a[href*="workflow_input"], button[type="button"]');
400-
console.log('📋 All potential run buttons:', allRunButtons);
414+
// Panel is not open, open it by clicking the run link
415+
const runButton = document.querySelector('a[href*="m=workflow_input"]') as HTMLAnchorElement;
416+
runButton?.click();
401417
}
402418
};
403419

0 commit comments

Comments
 (0)