Skip to content

Commit 5cfab00

Browse files
committed
Merge branch 'main' into apb/auth
2 parents f5fe1ea + 24032b5 commit 5cfab00

File tree

25 files changed

+685
-158
lines changed

25 files changed

+685
-158
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ jobs:
8282

8383
- run: mix tailwind.install --no-assets
8484

85+
- run: mix esbuild.install
86+
8587
- name: Run tests
8688
env:
8789
DATABASE_URL: postgresql://postgres:postgres@localhost:${{job.services.postgres.ports[5432]}}/beacon_live_admin_test

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
### Enhancements
6+
- Adds page to define custom JS Hooks
67
- Updated UI styling with StationUI
78
- Unsaved changes will now be saved when publishing, instead of discarded
89
- Adds Unpublish button to Page editor
@@ -11,6 +12,7 @@
1112
### Fixes
1213

1314
- Fixed a bug where MediaLibrary could check for file contents on the wrong node in multi-node deployments
15+
- Fixed a bug where using the code editor could reset other form fields on the page
1416

1517
## 0.3.1 (2024-12-12)
1618

assets/package-lock.json

Lines changed: 66 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"phoenix_live_view": "file:../deps/phoenix_live_view"
1818
},
1919
"devDependencies": {
20+
"tailwindcss": "^3.4",
2021
"@tailwindcss/container-queries": "^0.1",
2122
"esbuild": "^0.20",
2223
"esbuild-plugin-import-glob": "^0.1",

lib/beacon/live_admin/application.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ defmodule Beacon.LiveAdmin.Application do
88
children = [
99
Beacon.LiveAdmin.Registry,
1010
{Phoenix.PubSub, name: Beacon.LiveAdmin.PubSub},
11+
%{id: :pg, start: {:pg, :start_link, [Beacon.LiveAdmin.Cluster.scope()]}},
1112
Beacon.LiveAdmin.Cluster,
1213
Turboprop.Cache
1314
]

lib/beacon/live_admin/client/content.ex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,32 @@ defmodule Beacon.LiveAdmin.Client.Content do
290290
def delete_info_handler(site, actor, info_handler) do
291291
call(site, Beacon.Content, :delete_info_handler, [info_handler, [actor: actor]])
292292
end
293+
294+
def change_js_hook(site, js_hook, attrs \\ %{}) do
295+
call(site, Beacon.Content, :change_js_hook, [js_hook, attrs])
296+
end
297+
298+
def list_js_hooks(site) do
299+
call(site, Beacon.Content, :list_js_hooks, [site])
300+
end
301+
302+
def create_js_hook(site, attrs) do
303+
call(site, Beacon.Content, :create_js_hook, [attrs])
304+
end
305+
306+
def create_js_hook!(site, attrs) do
307+
call(site, Beacon.Content, :create_js_hook!, [attrs])
308+
end
309+
310+
def default_hook_code(site, hook_name) do
311+
call(site, Beacon.Content, :default_hook_code, [hook_name])
312+
end
313+
314+
def update_js_hook(site, js_hook, attrs) do
315+
call(site, Beacon.Content, :update_js_hook, [js_hook, attrs])
316+
end
317+
318+
def delete_js_hook(site, js_hook) do
319+
call(site, Beacon.Content, :delete_js_hook, [js_hook])
320+
end
293321
end

lib/beacon/live_admin/client/media_library.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ defmodule Beacon.LiveAdmin.Client.MediaLibrary do
3535
call(site, Beacon.MediaLibrary, :is_image?, [asset])
3636
end
3737

38-
def new_upload_metadata(site, path, node, opts) do
39-
call(site, Beacon.MediaLibrary.UploadMetadata, :new, [site, path, node, opts])
38+
def new_upload_metadata(site, path, opts) do
39+
call(site, Beacon.MediaLibrary.UploadMetadata, :new, [site, path, opts])
4040
end
4141

4242
def upload(site, upload_metadata) do

lib/beacon/live_admin/cluster.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ defmodule Beacon.LiveAdmin.Cluster do
1010

1111
@scope :beacon_cluster
1212

13+
@doc false
14+
def scope, do: @scope
15+
1316
@doc false
1417
def start_link(opts) do
1518
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
@@ -18,7 +21,6 @@ defmodule Beacon.LiveAdmin.Cluster do
1821
@doc false
1922
@impl true
2023
def init(opts) do
21-
{:ok, _} = :pg.start_link(@scope)
2224
:pg.monitor_scope(@scope)
2325
:ok = :net_kernel.monitor_nodes(true, node_type: :all)
2426
{:ok, opts}

lib/beacon/live_admin/live/event_handler_editor_live/index.ex

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ defmodule Beacon.LiveAdmin.EventHandlerEditorLive.Index do
4040
%{selected: selected, beacon_page: %{site: site}, form: form} = socket.assigns
4141

4242
params = Map.merge(form.params, %{"code" => code})
43-
changeset = Content.change_event_handler(site, selected, params)
43+
44+
changeset =
45+
site
46+
|> Content.change_event_handler(selected, params)
47+
|> Map.put(:action, :validate)
4448

4549
socket =
4650
socket
@@ -50,6 +54,17 @@ defmodule Beacon.LiveAdmin.EventHandlerEditorLive.Index do
5054
{:noreply, socket}
5155
end
5256

57+
def handle_event("validate", params, socket) do
58+
%{beacon_page: %{site: site}, form: form} = socket.assigns
59+
60+
changeset =
61+
site
62+
|> Content.change_event_handler(form.source.data, params["event_handler"])
63+
|> Map.put(:action, :validate)
64+
65+
{:noreply, assign_form(socket, changeset)}
66+
end
67+
5368
def handle_event("create_new", _, socket) do
5469
{:noreply, assign(socket, show_create_modal: true)}
5570
end
@@ -231,7 +246,7 @@ defmodule Beacon.LiveAdmin.EventHandlerEditorLive.Index do
231246
</div>
232247
233248
<div :if={@form} class="w-full col-span-2">
234-
<.form :let={f} for={@form} id="event-handler-form" class="flex items-end gap-4" phx-submit="save_changes">
249+
<.form :let={f} for={@form} id="event-handler-form" class="flex items-end gap-4" phx-change="validate" phx-submit="save_changes">
235250
<.input label="Name" field={f[:name]} type="text" />
236251
<input type="hidden" name="event_handler[code]" id="event_handler-form_code" value={Phoenix.HTML.Form.input_value(f, :code)} />
237252

lib/beacon/live_admin/live/home_live.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ defmodule Beacon.LiveAdmin.HomeLive do
5757
<.link href={Router.beacon_live_admin_path(@socket, site, "/error_pages")} class={nav_class()}>
5858
Error Pages
5959
</.link>
60+
<.link href={Router.beacon_live_admin_path(@socket, site, "/hooks")} class={nav_class()}>
61+
JS Hooks
62+
</.link>
6063
</div>
6164
</div>
6265
<% end %>

0 commit comments

Comments
 (0)