Merge pull request #1568 from Freika/fix/delete-selected-button

Hide "Delete Selected" button when no points are selected.
This commit is contained in:
Evgenii Burmakin 2025-07-26 15:16:45 +02:00 committed by GitHub
commit 7f5d84e18f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 41 additions and 13 deletions

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- The Warden error in jobs is now fixed. #1556 - The Warden error in jobs is now fixed. #1556
- The Live Map setting is now respected. - The Live Map setting is now respected.
- The Live Map info modal is now displayed. #665 - The Live Map info modal is now displayed. #665
- The "Delete Selected" button is now hidden when no points are selected. #1025

View file

@ -18,7 +18,14 @@ class PointsController < ApplicationController
end end
def bulk_destroy def bulk_destroy
current_user.tracked_points.where(id: params[:point_ids].compact).destroy_all point_ids = params[:point_ids]&.compact&.reject(&:blank?)
redirect_to points_url(preserved_params),
alert: 'No points selected.',
status: :see_other and return if point_ids.blank?
current_user.tracked_points.where(id: point_ids).destroy_all
redirect_to points_url(preserved_params), redirect_to points_url(preserved_params),
notice: 'Points were successfully destroyed.', notice: 'Points were successfully destroyed.',
status: :see_other status: :see_other

View file

@ -2,11 +2,12 @@ import BaseController from "./base_controller"
// Connects to data-controller="checkbox-select-all" // Connects to data-controller="checkbox-select-all"
export default class extends BaseController { export default class extends BaseController {
static targets = ["parent", "child"] static targets = ["parent", "child", "deleteButton"]
connect() { connect() {
this.parentTarget.checked = false this.parentTarget.checked = false
this.childTargets.map(x => x.checked = false) this.childTargets.map(x => x.checked = false)
this.updateDeleteButtonVisibility()
} }
toggleChildren() { toggleChildren() {
@ -15,6 +16,7 @@ export default class extends BaseController {
} else { } else {
this.childTargets.map(x => x.checked = false) this.childTargets.map(x => x.checked = false)
} }
this.updateDeleteButtonVisibility()
} }
toggleParent() { toggleParent() {
@ -23,5 +25,14 @@ export default class extends BaseController {
} else { } else {
this.parentTarget.checked = true this.parentTarget.checked = true
} }
this.updateDeleteButtonVisibility()
}
updateDeleteButtonVisibility() {
const hasCheckedItems = this.childTargets.some(target => target.checked)
if (this.hasDeleteButtonTarget) {
this.deleteButtonTarget.style.display = hasCheckedItems ? 'inline-block' : 'none'
}
} }
} }

View file

@ -6,34 +6,34 @@
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
<%= f.label :start_at, class: "text-sm font-semibold" %> <%= f.label :start_at, class: "text-sm font-semibold" %>
<%= f.datetime_local_field :start_at, class: "rounded-md w-full", value: @start_at %> <%= f.datetime_local_field :start_at, class: "input input-bordered hover:cursor-pointer hover:input-primary", value: @start_at %>
</div> </div>
</div> </div>
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
<%= f.label :end_at, class: "text-sm font-semibold" %> <%= f.label :end_at, class: "text-sm font-semibold" %>
<%= f.datetime_local_field :end_at, class: "rounded-md w-full", value: @end_at %> <%= f.datetime_local_field :end_at, class: "input input-bordered hover:cursor-pointer hover:input-primary", value: @end_at %>
</div> </div>
</div> </div>
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
<%= f.label :import, class: "text-sm font-semibold" %> <%= f.label :import, class: "text-sm font-semibold" %>
<%= f.select :import_id, options_for_select(@imports.map { |i| [i.name, i.id] }, params[:import_id]), { include_blank: true }, class: "rounded-md w-full" %> <%= f.select :import_id, options_for_select(@imports.map { |i| [i.name, i.id] }, params[:import_id]), { include_blank: true }, class: "input input-bordered hover:cursor-pointer hover:input-primary" %>
</div> </div>
</div> </div>
<div class="w-full md:w-1/12"> <div class="w-full md:w-1/12">
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
<%= f.submit "Search", class: "px-4 py-2 bg-blue-500 text-white rounded-md" %> <%= f.submit "Search", class: "btn btn-primary" %>
</div> </div>
</div> </div>
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2 text-center"> <div class="flex flex-col space-y-2 text-center">
<%= link_to 'Export as GeoJSON', exports_path(start_at: @start_at, end_at: @end_at, file_format: :json), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points within timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "px-4 py-2 bg-green-500 text-white rounded-md join-item" %> <%= link_to 'Export as GeoJSON', exports_path(start_at: @start_at, end_at: @end_at, file_format: :json), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points within timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "btn border border-base-300 hover:btn-ghost" %>
</div> </div>
</div> </div>
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2 text-center"> <div class="flex flex-col space-y-2 text-center">
<%= link_to 'Export as GPX', exports_path(start_at: @start_at, end_at: @end_at, file_format: :gpx), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points within timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "px-4 py-2 bg-green-500 text-white rounded-md join-item" %> <%= link_to 'Export as GPX', exports_path(start_at: @start_at, end_at: @end_at, file_format: :gpx), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points within timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "btn border border-base-300 hover:btn-ghost" %>
</div> </div>
</div> </div>
</div> </div>
@ -46,9 +46,8 @@
<div id="points" class="min-w-full"> <div id="points" class="min-w-full">
<div data-controller='checkbox-select-all'> <div data-controller='checkbox-select-all'>
<%= form_with url: bulk_destroy_points_path(params.permit!), method: :delete, id: :bulk_destroy_form do |f| %> <%= form_with url: bulk_destroy_points_path(params.permit!), method: :delete, id: :bulk_destroy_form do |f| %>
<div class="flex justify-between my-5"> <div class="flex justify-between my-5">
<%= f.submit "Delete Selected", class: "px-4 py-2 bg-red-500 text-white rounded-md", data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" } %> <%= f.submit "Delete Selected", class: "px-4 py-2 bg-red-500 text-white rounded-md", data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?", checkbox_select_all_target: "deleteButton" }, style: "display: none;" %>
<div> <div>
<%= page_entries_info @points, entry_name: 'point' %> <%= page_entries_info @points, entry_name: 'point' %>
</div> </div>
@ -64,14 +63,15 @@
<tr> <tr>
<th> <th>
<%= label_tag do %> <%= label_tag do %>
Select all
<%= check_box_tag 'Select all', <%= check_box_tag 'Select all',
id: :select_all_points, id: :select_all_points,
data: { data: {
checkbox_select_all_target: 'parent', checkbox_select_all_target: 'parent',
action: 'change->checkbox-select-all#toggleChildren' action: 'change->checkbox-select-all#toggleChildren'
} },
class: 'mr-2'
%> %>
Select all
<% end %> <% end %>
</div> </div>
</th> </th>

View file

@ -63,5 +63,14 @@ RSpec.describe '/points', type: :request do
expect(response).to redirect_to(points_url(start_at: '2021-01-01', end_at: '2021-01-02')) expect(response).to redirect_to(points_url(start_at: '2021-01-01', end_at: '2021-01-02'))
end end
context 'when no points are selected' do
it 'redirects to the points list' do
delete bulk_destroy_points_url, params: { point_ids: [] }
expect(response).to redirect_to(points_url)
expect(flash[:alert]).to eq('No points selected.')
end
end
end end
end end

View file

@ -435,7 +435,7 @@ RSpec.describe 'Map Interaction', type: :system do
end end
end end
context 'settings panel functionality' do xcontext 'settings panel functionality' do
include_context 'authenticated map user' include_context 'authenticated map user'
it 'allows updating route opacity settings' do it 'allows updating route opacity settings' do