diff --git a/.formatter.exs b/.formatter.exs index e397242..a44d1f7 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -8,6 +8,7 @@ spark_locals_without_parens = [ actor?: 1, actor_load: 1, create_actions: 1, + datetime_step: 1, default_resource_page: 1, destroy_actions: 1, field: 1, diff --git a/lib/ash_admin/components/resource/form.ex b/lib/ash_admin/components/resource/form.ex index b9e1ac1..627c264 100644 --- a/lib/ash_admin/components/resource/form.ex +++ b/lib/ash_admin/components/resource/form.ex @@ -631,6 +631,16 @@ defmodule AshAdmin.Components.Resource.Form do end end + defp datetime_step(resource, attribute) do + case AshAdmin.Resource.field(resource, attribute.name) do + %{datetime_step: datetime_step} -> + datetime_step + + _ -> + "60" + end + end + defp unwrap_type({:array, type}), do: unwrap_type(type) defp unwrap_type(type), do: type @@ -667,7 +677,15 @@ defmodule AshAdmin.Components.Resource.Form do def render_attribute_input(assigns, %{type: type} = attribute, form, value, name, id, _) when type in [Ash.Type.UtcDatetime, Ash.Type.UtcDatetimeUsec, Ash.Type.DateTime] do - assigns = assign(assigns, form: form, value: value, name: name, attribute: attribute, id: id) + assigns = + assign(assigns, + form: form, + value: value, + name: name, + attribute: attribute, + step: datetime_step(assigns.resource, attribute), + id: id + ) ~H""" <.input @@ -675,6 +693,7 @@ defmodule AshAdmin.Components.Resource.Form do value={value(@value, @form, @attribute)} name={@name || @form.name <> "[#{@attribute.name}]"} id={@id || @form.id <> "_#{@attribute.name}"} + step={@step} /> """ end diff --git a/lib/ash_admin/resource/field.ex b/lib/ash_admin/resource/field.ex index 213a3a7..21c24ea 100644 --- a/lib/ash_admin/resource/field.ex +++ b/lib/ash_admin/resource/field.ex @@ -7,7 +7,15 @@ defmodule AshAdmin.Resource.Field do @moduledoc """ The representation of a configured field in the admin UI. """ - defstruct [:name, :type, :default, :max_file_size, :accepted_extensions, :__spark_metadata__] + defstruct [ + :name, + :type, + :default, + :max_file_size, + :accepted_extensions, + :datetime_step, + :__spark_metadata__ + ] @schema [ name: [ @@ -32,6 +40,12 @@ defmodule AshAdmin.Resource.Field do required: false, doc: "A list of unique file extensions (such as \".jpeg\") or mime type (such as \"image/jpeg\" or \"image/*\"). Only applicable to action arguments of `Ash.Type.File`." + ], + datetime_step: [ + type: :string, + required: false, + doc: + "The value for the input's `step` property that determines it's precision. Defaults to \"60\", i.e. minute. Only applicable to action attributes and arguments that are datetimes, e.g. `Ash.Type.UtcDatetime`." ] ]