backpex
backpex copied to clipboard
Uniform Options
Description
- We would like to create a standardised way for options in Backpex.
- In future, there will be three places to set all options:
- Module Level: Modules (Fields, Filters, Metrics, ...) have a standardised location where default options can be defined.
- Config Level: The defaults can be overwritten via the application config.
- 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