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

fix: invalid date_time #2279

Merged
merged 14 commits into from Jan 4, 2024
@@ -1,3 +1,3 @@
<%= turbo_frame_tag @field.turbo_frame, src: @field.frame_url, loading: loading, target: :_top, class: "block" do %>
<%= turbo_frame_tag @field.turbo_frame, src: @field.frame_url, loading: turbo_frame_loading, target: :_top, class: "block" do %>
<%= render(Avo::LoadingComponent.new(title: @field.plural_name)) %>
<% end %>
7 changes: 1 addition & 6 deletions app/components/avo/fields/has_many_field/show_component.rb
Expand Up @@ -2,10 +2,5 @@

class Avo::Fields::HasManyField::ShowComponent < Avo::Fields::ShowComponent
include Turbo::FramesHelper

def turbo_frame_loading = kwargs[:turbo_frame_loading]

def loading
turbo_frame_loading || params[:turbo_frame_loading] || "eager"
end
include Avo::Fields::Concerns::FrameLoading
end
@@ -1,5 +1,5 @@
<% if @field.value %>
<turbo-frame id="<%= @field.turbo_frame %>" src="<%= @field.frame_url %>" target="_top" class="block">
<turbo-frame id="<%= @field.turbo_frame %>" src="<%= @field.frame_url %>" loading=<%= turbo_frame_loading %> target="_top" class="block">
<%= render(Avo::LoadingComponent.new(title: @field.name)) %>
</turbo-frame>
<% else %>
Expand Down
1 change: 1 addition & 0 deletions app/components/avo/fields/has_one_field/show_component.rb
Expand Up @@ -2,6 +2,7 @@

class Avo::Fields::HasOneField::ShowComponent < Avo::Fields::ShowComponent
include Avo::ApplicationHelper
include Avo::Fields::Concerns::FrameLoading

def can_attach?
policy_result = true
Expand Down
Expand Up @@ -78,7 +78,7 @@ export default class extends Controller {

// Parse the time as if it were UTC
get parsedValue() {
return DateTime.fromISO(this.initialValue, { zone: 'UTC' })
return DateTime.fromISO(this.initialValue.trim(), { zone: 'UTC' })
}

get displayTimezone() {
Expand Down
14 changes: 14 additions & 0 deletions lib/avo/fields/concerns/frame_loading.rb
@@ -0,0 +1,14 @@
module Avo
module Fields
module Concerns
module FrameLoading
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
extend ActiveSupport::Concern

def turbo_frame_loading
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this change will impact any other components @Paul-Bob?

Copy link
Contributor Author

@Paul-Bob Paul-Bob Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also apply this change on app/components/avo/fields/has_many_field/show_component.html.erb

kwargs[:turbo_frame_loading] || params[:turbo_frame_loading] || "eager"
end
end
end
end
end
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved

1 change: 1 addition & 0 deletions spec/dummy/app/avo/resources/post.rb
Expand Up @@ -25,6 +25,7 @@ class Avo::Resources::Post < Avo::BaseResource
def fields
field :id, as: :id
field :name, required: true, sortable: true
field :created_at, as: :date_time
field :body,
as: :trix,
placeholder: "Enter text",
Expand Down
6 changes: 6 additions & 0 deletions spec/dummy/app/avo/resources/user.rb
Expand Up @@ -222,6 +222,11 @@ def first_tabs_group
test_tab
test_field("Inside tabs")
first_tabs_group_fields
tab "Created at" do
panel do
field :created_at, as: :date_time
end
end
end
end

Expand All @@ -240,6 +245,7 @@ def second_tabs_group
# show_on: :edit,
scope: -> { query.starts_with parent.first_name[0].downcase },
description: "The comments listed in the attach modal all start with the name of the parent user."
field :comment, as: :has_one, name: "Main comment"
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/dummy/app/models/user.rb
Expand Up @@ -30,6 +30,7 @@ class User < ApplicationRecord
validates :last_name, presence: true

has_one :post
has_one :comment
has_one :fish
has_many :posts, inverse_of: :user
has_many :people
Expand Down
14 changes: 12 additions & 2 deletions spec/system/avo/tabs_spec.rb
Expand Up @@ -48,7 +48,7 @@
visit avo.resources_user_path user

within first_tab_group do
expect(find('[data-tabs-target="tabSwitcher"]').text).to eq "Fish\nTeams\nPeople\nSpouses\nProjects\nTeam memberships"
expect(find('[data-tabs-target="tabSwitcher"]').text).to eq "Fish\nTeams\nPeople\nSpouses\nProjects\nTeam memberships\nCreated at"
end
end
end
Expand Down Expand Up @@ -101,7 +101,7 @@
scroll_to first_tab_group

within first_tab_group do
expect(find('[data-tabs-target="tabSwitcher"]')).to have_text "Fish\nTeams\nPeople\nSpouses\nProjects\nTeam memberships", exact: true
expect(find('[data-tabs-target="tabSwitcher"]')).to have_text "Fish\nTeams\nPeople\nSpouses\nProjects\nTeam memberships\nCreated at", exact: true
end
end
end
Expand Down Expand Up @@ -162,4 +162,14 @@
find('a[data-selected="true"][data-tabs-tab-name-param="Team memberships"]')
end
end

it "date_time field works on tabs" do
visit avo.resources_user_path user

find('a[data-selected="false"][data-tabs-tab-name-param="Main comment"]').click
expect(page).not_to have_text 'Invalid DateTime'

find('a[data-selected="false"][data-tabs-tab-name-param="Created at"]').click
expect(page).not_to have_text 'Invalid DateTime'
end
end
2 changes: 1 addition & 1 deletion spec/system/avo/test_helpers_spec.rb
Expand Up @@ -73,7 +73,7 @@
it "finds the wrapper" do
users.each do |user|
visit "admin/resources/users/#{user.id}"
has_one_post = has_one_field_wrapper(id: :post)
scroll_to(has_one_post = has_one_field_wrapper(id: :post))

name_wrapper = within(has_one_post) { show_field_wrapper(id: "name", type: "text") }
name_wrapper_without_type = within(has_one_post) { show_field_wrapper(id: "name") }
Expand Down