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

Uniform Options #336

Open
5 tasks
pehbehbeh opened this issue Jun 14, 2024 · 0 comments
Open
5 tasks

Uniform Options #336

pehbehbeh opened this issue Jun 14, 2024 · 0 comments
Labels
enhancement Changes that are not breaking

Comments

@pehbehbeh
Copy link
Member

pehbehbeh commented Jun 14, 2024

Description

  • We would like to create a standardised way for options in Backpex.
  • In future, there will be three places to set all options:
    1. Module Level: Modules (Fields, Filters, Metrics, ...) have a standardised location where default options can be defined.
    2. Config Level: The defaults can be overwritten via the application config.
    3. Resource Level: The value set in the respective LiveResource has the highest priority.
  • At the same time, we can then implement a validation of the options to prevent errors during development.

Todos

  • Backpex.Field
  • Backpex.Filter
  • Backpex.Metric
  • ...
  • Backpex.LiveResource

Concept

Module Level (package defaults)

see also nimble_options

defmodule Backpex.Fields.Date do
  # ... 
 
  def options() do
    [
      format: [
        type: :string,
        default: "%Y-%m-%d"
      ],
      foo: [
        type: :non_neg_integer,
        required: true
      ]
    ]
  end  
end

Config Level (application config)

config :backpe, Backpex.Fields.Date,
  format: "%d.%m.%Y"

config: :backpex, Backpex.Fields.Upload,
  max_file_size: 42_000_000

Resource Level (application domain)

The familiar way:

def fields do
  [
    %{
      module: Backpex.Fields.Date,
      label: "Created At",
      name: :created_at,
      format: "%d.%m.%Y"
    }
  ]
end
@pehbehbeh pehbehbeh closed this as completed by moving to Medium Term in Backpex Roadmap Jun 14, 2024
@pehbehbeh pehbehbeh added the enhancement Changes that are not breaking label Jun 14, 2024
@pehbehbeh pehbehbeh reopened this Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Changes that are not breaking
Projects
Status: Medium Term
Development

No branches or pull requests

1 participant