backpex icon indicating copy to clipboard operation
backpex copied to clipboard

Uniform Options

Open pehbehbeh opened this issue 8 months ago • 0 comments

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 avatar Jun 14 '24 16:06 pehbehbeh