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

Add AshAdmin.Layouts and Phoenix.VerifiedRoutes #68

Closed
wants to merge 1 commit into from

Conversation

esdrasedu
Copy link
Contributor

This PR contains couple changes, but everything is related to Phoenix 1.7 migration:

  • Update AshAdmin.Layouts, using heex engine and changing they way assets are provided (using Plug.Static)
  • Adding Phoenix.VerifiedRoutes support, my idea here is replace @prefix for ash_admin_path, that way we can have a friendly URL pattern match

I haven't replace all @prefix yet because I want to change the routes too, maybe try something like :api/:resource/:action but I still have to check the others components to know if we should have more params

@esdrasedu esdrasedu force-pushed the add_layouts branch 2 times, most recently from 573eb6d to 47cb2a1 Compare August 7, 2023 12:07
Copy link
Contributor

@zachdaniel zachdaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some questions 😀


def asset_hash("/statics/" <> path) do
file =
Application.app_dir(:ash_admin, ["priv", "static", path])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. I've not seen something like this in a phoenix application before, how is it normally done for static assets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exacly it is stange? the way I am reading the asset or reading the assets to get the md5 hash to append to the url?

Let me give you more context, phoenix application normally manages the asset and cache running the task mix phx.digest, the result for that is an asset minified and zipped with this pattern name asset-#{hash}.#{ext}.gz
But because ash admin is not an application, its assets are not handle for mix phx.digest, we have to do it runtime or manual (digest each asset before release any version)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what feels strange to me is that we're reading a file to hash it to figure out where its minified version is, but we're doing it every time a page load happens. I think it would be better to make this a macro or use a module attribute to store the hash of it at compile time. You can use @external_dependency to cause external files to trigger recompiles.

@@ -0,0 +1,41 @@
<.live_component
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I prefer having the html just live in the component's render/1, I don't like having to jump back and forth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, moved back to ex file

)
opts =
if Macro.quoted_literal?(opts) do
Macro.prewalk(opts, &expand_alias(&1, __CALLER__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is Macro.expand_literal IIRC. Why are we doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this anymore, I was using the options to be able to forward the endpoint together, but this is no longer necessary, removed

@@ -16,7 +16,7 @@ defmodule AshAdmin.Test.PageLiveTest do
assert html =~ "body"
assert html =~ "String"

{:ok, _view, html} = live(conn, "/api/admin/test")
{:ok, _view, html} = live(conn, "/api/admin?&resource=test")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did the routes change? Also, this should probably be ?resource=test not ?&resource=test right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, it is a typo, fixed

@esdrasedu esdrasedu force-pushed the add_layouts branch 5 times, most recently from da600e1 to 5dc536e Compare August 9, 2023 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants