mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-10 09:49:56 +08:00
## 🔍 Overview This PR adds bulk selection functionality to the PostList component and implements optimized bulk deletion for the drafts page. Users can now select multiple drafts and delete them all at once with a single network request, significantly improving performance and user experience. The implementation includes: - A new reusable bulk selection system for PostList components - Optimized bulk delete endpoint that reduces network requests by 90% - Comprehensive bulk controls UI with select all/clear all functionality - Shift+click range selection similar to topic lists - Complete test coverage for all new functionality ## ➕ More details **Bulk Selection System** The PostList component now supports optional bulk selection through these new parameters: - `@bulkSelectEnabled={{true}}` - Shows checkboxes next to each post - `@bulkSelectHelper={{helper}}` - Manages selection state (use `PostBulkSelectHelper`) - `@bulkActions={{actions}}` - Array of bulk action objects for the dropdown menu **Usage Example:** ```gjs import Component from "@glimmer/component"; import { action } from "@ember/object"; import didUpdate from "@ember/render-modifiers/modifiers/did-update"; import PostBulkSelectHelper from "discourse/lib/post-bulk-select-helper"; export default class MyComponent extends Component { bulkSelectHelper = new PostBulkSelectHelper(this); constructor() { super(...arguments); // Initial updatePosts call this.updateBulkSelectPosts(); } @action updateBulkSelectPosts() { if (this.shouldEnableBulkSelect && this.args.posts) { this.bulkSelectHelper.updatePosts(this.args.posts); } } get showBulkSelectHelper() { return this.shouldEnableBulkSelect ? this.bulkSelectHelper : null; } get bulkActions() { return [ { label: "delete_selected", icon: "trash-can", action: this.handleBulkDelete, class: "btn-danger" } ]; } <template> <PostList @posts={{@posts}} @bulkSelectEnabled={{this.shouldEnableBulkSelect}} @bulkSelectHelper={{this.showBulkSelectHelper}} @bulkActions={{this.bulkActions}} {{didUpdate this.updateBulkSelectPosts @posts}} /> </template> } ``` **Performance Optimization** The drafts page now uses a new bulk delete endpoint (`DELETE /drafts/bulk_destroy`) that: - Processes multiple drafts in a single HTTP request instead of N individual requests - Uses database transactions for atomic operations (all-or-nothing) - Reduces database queries from 2N to 2 total queries - Validates draft sequences upfront to fail fast on conflicts **Technical Implementation** - `PostBulkSelectHelper`: New helper class for managing selection state with support for individual selection, range selection (shift+click), and bulk operations with reactive posts tracking - `PostListBulkControls`: New component providing selection count, select all/clear all buttons, and bulk actions dropdown - Enhanced PostList and PostListItem components with conditional bulk selection UI - Updated user-stream component to use optimized bulk deletion with automatic selection cleanup - Comprehensive styling with responsive design **API Changes** - New controller action: `DraftsController#bulk_destroy` - New route: `DELETE /drafts/bulk_destroy` - New JavaScript method: `Draft.bulkClear(drafts)` - Enhanced `PostBulkSelectHelper` with `updatePosts()` method for reactive data updates - Fully backward compatible - existing single delete functionality unchanged **Testing** - 9 new controller specs covering bulk deletion edge cases, validation, and API access - 11 integration tests for PostList bulk selection functionality - 10 system specs for end-to-end drafts page bulk selection workflows - All existing tests continue to pass ## 📹 Screen Recording https://github.com/user-attachments/assets/2d5a9b38-f1cb-43ee-88ac-285b71083612 |
||
|---|---|---|
| .. | ||
| admin | ||
| users | ||
| about_controller.rb | ||
| application_controller.rb | ||
| associated_groups_controller.rb | ||
| badges_controller.rb | ||
| bookmarks_controller.rb | ||
| bootstrap_controller.rb | ||
| categories_controller.rb | ||
| clicks_controller.rb | ||
| composer_controller.rb | ||
| composer_messages_controller.rb | ||
| csp_reports_controller.rb | ||
| directory_columns_controller.rb | ||
| directory_items_controller.rb | ||
| do_not_disturb_controller.rb | ||
| drafts_controller.rb | ||
| edit_directory_columns_controller.rb | ||
| email_controller.rb | ||
| embed_controller.rb | ||
| emojis_controller.rb | ||
| exceptions_controller.rb | ||
| export_csv_controller.rb | ||
| extra_locales_controller.rb | ||
| finish_installation_controller.rb | ||
| form_templates_controller.rb | ||
| forums_controller.rb | ||
| groups_controller.rb | ||
| hashtags_controller.rb | ||
| highlight_js_controller.rb | ||
| home_page_controller.rb | ||
| inline_onebox_controller.rb | ||
| invites_controller.rb | ||
| list_controller.rb | ||
| metadata_controller.rb | ||
| new_invite_controller.rb | ||
| new_topic_controller.rb | ||
| notifications_controller.rb | ||
| offline_controller.rb | ||
| onebox_controller.rb | ||
| pageview_controller.rb | ||
| permalinks_controller.rb | ||
| post_action_users_controller.rb | ||
| post_actions_controller.rb | ||
| post_localizations_controller.rb | ||
| post_readers_controller.rb | ||
| posts_controller.rb | ||
| presence_controller.rb | ||
| published_pages_controller.rb | ||
| push_notification_controller.rb | ||
| qunit_controller.rb | ||
| reviewable_claimed_topics_controller.rb | ||
| reviewable_notes_controller.rb | ||
| reviewables_controller.rb | ||
| robots_txt_controller.rb | ||
| safe_mode_controller.rb | ||
| search_controller.rb | ||
| session_controller.rb | ||
| sidebar_sections_controller.rb | ||
| similar_topics_controller.rb | ||
| site_controller.rb | ||
| sitemap_controller.rb | ||
| slugs_controller.rb | ||
| static_controller.rb | ||
| steps_controller.rb | ||
| stylesheets_controller.rb | ||
| svg_sprite_controller.rb | ||
| tag_groups_controller.rb | ||
| tags_controller.rb | ||
| test_requests_controller.rb | ||
| theme_javascripts_controller.rb | ||
| topic_localizations_controller.rb | ||
| topic_view_stats_controller.rb | ||
| topics_controller.rb | ||
| uploads_controller.rb | ||
| user_actions_controller.rb | ||
| user_api_key_clients_controller.rb | ||
| user_api_keys_controller.rb | ||
| user_avatars_controller.rb | ||
| user_badges_controller.rb | ||
| user_status_controller.rb | ||
| users_controller.rb | ||
| users_email_controller.rb | ||
| webhooks_controller.rb | ||
| wizard_controller.rb | ||