Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 20 additions & 1 deletion lib/ash_admin/components/resource/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -667,14 +677,23 @@ 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
type="datetime-local"
value={value(@value, @form, @attribute)}
name={@name || @form.name <> "[#{@attribute.name}]"}
id={@id || @form.id <> "_#{@attribute.name}"}
step={@step}
/>
"""
end
Expand Down
16 changes: 15 additions & 1 deletion lib/ash_admin/resource/field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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`."
]
]

Expand Down
Loading