Skip to content

Commit 72b998e

Browse files
limit scope to preserve previous command-enter keystroke for Inspector
1 parent d4a9cac commit 72b998e

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed

assets/js/hooks/KeyHandlers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,15 @@ const openRunPanelAction = (_e: KeyboardEvent, _el: HTMLElement) => {
429429
/**
430430
* Hook to open the Run panel when "Ctrl+Enter" (or "Cmd+Enter" on macOS) is pressed.
431431
*
432-
* This hook listens globally and navigates to the run panel URL, which opens the
432+
* This hook is scoped to the workflow editor and navigates to the run panel URL, which opens the
433433
* workflow input interface for running the workflow.
434434
*
435-
* Priority: `PRIORITY.HIGH`, ensuring it takes precedence over the default run handlers.
435+
* Priority: `PRIORITY.HIGH` within its scope, ensuring it takes precedence over other handlers in the workflow editor.
436+
* Scope: `"workflow-editor"`, meaning this hook only applies within the workflow editor context.
436437
*/
437438
export const OpenRunPanelViaCtrlEnter = createKeyCombinationHook(
438439
isCtrlOrMetaEnter,
439440
openRunPanelAction,
440-
PRIORITY.HIGH
441+
PRIORITY.HIGH,
442+
'workflow-editor'
441443
);

lib/lightning_web/live/workflow_live/edit.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,11 @@ defmodule LightningWeb.WorkflowLive.Edit do
213213
class="transition-all duration-300 ease-in-out"
214214
/>
215215
<div
216-
class={"relative h-full flex grow transition-all duration-300 ease-in-out #{if @show_new_workflow_panel, do: "w-2/3", else: ""}"}
216+
class={"relative h-full flex grow transition-all duration-300 ease-in-out #{if @show_new_workflow_panel, do: "w-2/3", else: ""} focus:outline-none"}
217217
id={"workflow-edit-#{@workflow.id}"}
218218
phx-hook="OpenRunPanelViaCtrlEnter"
219+
data-keybinding-scope="workflow-editor"
220+
tabindex="0"
219221
>
220222
<.selected_template_label
221223
:if={@selected_template && @show_new_workflow_panel}

test/lightning_web/live/workflow_live/edit_test.exs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,6 +3580,82 @@ defmodule LightningWeb.WorkflowLive.EditTest do
35803580
end
35813581
end
35823582

3583+
describe "keyboard shortcuts" do
3584+
setup %{project: project} do
3585+
workflow =
3586+
insert(:simple_workflow, project: project)
3587+
|> with_snapshot()
3588+
{:ok, workflow: workflow}
3589+
end
3590+
3591+
test "OpenRunPanelViaCtrlEnter hook is attached to workflow editor", %{
3592+
conn: conn,
3593+
project: project,
3594+
workflow: workflow
3595+
} do
3596+
{:ok, view, _html} =
3597+
live(
3598+
conn,
3599+
~p"/projects/#{project.id}/w/#{workflow.id}",
3600+
on_error: :raise
3601+
)
3602+
3603+
# Check that the OpenRunPanelViaCtrlEnter hook is present on the workflow container
3604+
workflow_container = view |> element("#workflow-edit-#{workflow.id}")
3605+
assert has_element?(workflow_container)
3606+
assert render(workflow_container) =~ "phx-hook=\"OpenRunPanelViaCtrlEnter\""
3607+
assert render(workflow_container) =~ "data-keybinding-scope=\"workflow-editor\""
3608+
end
3609+
3610+
test "OpenRunPanelViaCtrlEnter hook is present with job selected", %{
3611+
conn: conn,
3612+
project: project,
3613+
workflow: workflow
3614+
} do
3615+
# Use the first job from the workflow that was created with snapshot
3616+
job = workflow.jobs |> List.first()
3617+
3618+
{:ok, view, _html} =
3619+
live(
3620+
conn,
3621+
~p"/projects/#{project.id}/w/#{workflow.id}?s=#{job.id}",
3622+
on_error: :raise
3623+
)
3624+
3625+
# Hook should still be present when a job is selected
3626+
workflow_container = view |> element("#workflow-edit-#{workflow.id}")
3627+
assert has_element?(workflow_container)
3628+
assert render(workflow_container) =~ "phx-hook=\"OpenRunPanelViaCtrlEnter\""
3629+
assert render(workflow_container) =~ "data-keybinding-scope=\"workflow-editor\""
3630+
3631+
# Run button should be present for step-aware behavior
3632+
run_button = view |> element("#run-from-step-#{job.id}")
3633+
assert has_element?(run_button)
3634+
end
3635+
3636+
test "OpenRunPanelViaCtrlEnter hook is present in expand mode", %{
3637+
conn: conn,
3638+
project: project,
3639+
workflow: workflow
3640+
} do
3641+
# Use the first job from the workflow that was created with snapshot
3642+
job = workflow.jobs |> List.first()
3643+
3644+
{:ok, view, _html} =
3645+
live(
3646+
conn,
3647+
~p"/projects/#{project.id}/w/#{workflow.id}?s=#{job.id}&m=expand",
3648+
on_error: :raise
3649+
)
3650+
3651+
# Hook should be present even in expand mode
3652+
workflow_container = view |> element("#workflow-edit-#{workflow.id}")
3653+
assert has_element?(workflow_container)
3654+
assert render(workflow_container) =~ "phx-hook=\"OpenRunPanelViaCtrlEnter\""
3655+
assert render(workflow_container) =~ "data-keybinding-scope=\"workflow-editor\""
3656+
end
3657+
end
3658+
35833659
defp log_viewer_selected_level(log_viewer) do
35843660
log_viewer
35853661
|> render()

0 commit comments

Comments
 (0)