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

User-defined function components #84

Closed
leandrocp opened this issue Dec 22, 2022 · 9 comments
Closed

User-defined function components #84

leandrocp opened this issue Dec 22, 2022 · 9 comments
Assignees
Labels
area:component Phoenix components and Page Builder components area:content Related to Content API and Content Management enhancement New feature or improvement help wanted Looking for contributors roadmap Priority issues that will be released in the short term
Milestone

Comments

@leandrocp
Copy link
Contributor

leandrocp commented Dec 22, 2022

We want to allow users to define their own function components. That will deprecate remove the existing my_component feature, see #84 (comment)

The first step is to define such function components:

Similar to the CoreComponents provided by Phoenix, Beacon will provide a UserComponents to hold user-defined components that can be created as:

Beacon.Components.create_component!(%{
  site: "my_site",
  name: "greet",
  attrs: [
    %{name: "name", type: "string", required: true}
  ],
  body: """
  <p>Hello, <%= @name %>!</p>
  """
})

Which internally compiles to:

defmodule BeaconWeb.LiveRenderer.UserComponents{site_hash} do
  use Phoenix.Component
  
  attr :name, :string, required: true
  def greet(assigns) do
    ~H"""
    <p>Hello, <%= @name %>!</p>
    """
  end
end

And then one can use it in layouts and pages:

Beacon.Pages.create_page!(%{
  path: "home",
  site: "my_site",
  layout_id: layout_id,
  template: """
  <main>
    <BeaconWeb.Components.dynamic component={"greet"} name="Jane" />
  </main>
  """
})

Notes:

  • Name collision may happen by sharing the same module to hold all components. We could explore custom namespaces but keeping it simple for now.
@leandrocp leandrocp added enhancement New feature or improvement help wanted Looking for contributors labels Dec 22, 2022
@leandrocp
Copy link
Contributor Author

@TheFirstAvenger thoughts?

@leandrocp
Copy link
Contributor Author

@AZholtkevych this issue is a proposal to support Phoenix.Component, a way to reuse pieces of templates. That would be the building block of layouts and pages.

@AZholtkevych
Copy link

AZholtkevych commented Dec 22, 2022

@leandrocp if you would like to take care of it in the future, you can provide time estimations later on)))

Thanks a lot

@leandrocp leandrocp removed their assignment Dec 22, 2022
@AZholtkevych AZholtkevych moved this from In Progress to Todo in Beacon Dec 22, 2022
@TheFirstAvenger
Copy link
Contributor

@leandrocp looks good. This is the natural evolution of what Beacon.Components.Component was intended to be, so I think we should morph that module/context into this feature. I wouldn't be opposed to just wiping out the my_component support in the same PR, forcing any users updating to make the swap. Supporting both at this point in the development process doesn't feel necessary.

@leandrocp
Copy link
Contributor Author

I wouldn't be opposed to just wiping out the my_component support in the same PR

@TheFirstAvenger sounds good 👍🏻

@leandrocp leandrocp self-assigned this Jan 3, 2023
@KronicDeth
Copy link
Contributor

Have the templates string not use ~H and a bare string means that editors or language support tools will need specialized support to highlight the template as HEEx after detecting the outer call.

@AZholtkevych AZholtkevych moved this from Todo to In Progress in Beacon Jan 3, 2023
@leandrocp
Copy link
Contributor Author

Have the templates string not use ~H and a bare string means that editors or language support tools will need specialized support to highlight the template as HEEx after detecting the outer call.

We have the same issue with page_helper and page_event which are Elixir code, but my understanding is that those functions are a low-level API which eventually will be consumed by Page Builder BeaconCMS/page_builder#1 (comment) and we could even add a feature where users write .heex/.exs template files that are converted to those strings. For that reason I'd rather keep a string for now while we explore such options. Wdyt?

@TheFirstAvenger
Copy link
Contributor

For that reason I'd rather keep a string for now while we explore such options. Wdyt?

Agreed. The target audience here for generating page content is not engineers, it is non-tech users. Asking users to add ~H to the data also locks us in if we need to pivot and use the code in a different way.

@leandrocp leandrocp removed their assignment Jan 6, 2023
@AZholtkevych AZholtkevych mentioned this issue Jan 9, 2023
12 tasks
@AZholtkevych AZholtkevych moved this from In Progress to Todo in Beacon Jan 17, 2023
@leandrocp leandrocp mentioned this issue Jan 23, 2023
6 tasks
@leandrocp leandrocp self-assigned this Mar 22, 2023
@leandrocp leandrocp moved this from Todo to In Progress in Beacon Mar 22, 2023
@AZholtkevych AZholtkevych added this to the Version 0.1.0 milestone Mar 23, 2023
@AZholtkevych AZholtkevych mentioned this issue Apr 25, 2023
29 tasks
@AZholtkevych AZholtkevych changed the title User-defined function components MANAGING ASSETS: User-defined function components Apr 25, 2023
@AZholtkevych AZholtkevych added app:admin and removed help wanted Looking for contributors labels Apr 27, 2023
@AZholtkevych AZholtkevych changed the title MANAGING ASSETS: User-defined function components Core -> Components and Pages: User-defined function components Apr 28, 2023
@AZholtkevych AZholtkevych added enhancement New feature or improvement help wanted Looking for contributors app:core labels Apr 28, 2023
@AZholtkevych AZholtkevych mentioned this issue Jun 9, 2023
18 tasks
@AZholtkevych AZholtkevych added this to the Version 0.1.0 milestone Sep 15, 2023
@leandrocp leandrocp removed the status in Beacon Oct 20, 2023
@leandrocp leandrocp moved this to Todo in Beacon Oct 20, 2023
@AZholtkevych AZholtkevych changed the title Core -> Components and Pages: User-defined function components Components and Pages: User-defined function components Oct 23, 2023
@AZholtkevych AZholtkevych assigned leandrocp and unassigned leandrocp Nov 16, 2023
@AZholtkevych AZholtkevych moved this from Todo to In Progress in Beacon Jan 12, 2024
@AZholtkevych AZholtkevych moved this from In Progress to Todo in Beacon Jan 25, 2024
@alexandrexaviersm alexandrexaviersm moved this from Todo to In Progress in Beacon Feb 2, 2024
@AZholtkevych AZholtkevych moved this from In Progress to Code Review in Beacon Apr 19, 2024
@AZholtkevych AZholtkevych mentioned this issue Apr 20, 2024
45 tasks
@leandrocp leandrocp changed the title Components and Pages: User-defined function components User-defined function components May 17, 2024
@leandrocp leandrocp added area:content Related to Content API and Content Management area:component Phoenix components and Page Builder components roadmap Priority issues that will be released in the short term labels May 17, 2024
@leandrocp leandrocp removed their assignment May 24, 2024
@leandrocp
Copy link
Contributor Author

Closed by #423, #535, and BeaconCMS/beacon_live_admin#160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:component Phoenix components and Page Builder components area:content Related to Content API and Content Management enhancement New feature or improvement help wanted Looking for contributors roadmap Priority issues that will be released in the short term
Projects
Status: Code Review
Development

No branches or pull requests

6 participants