Draft
Conversation
da57861 to
30202f6
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a mobile-friendly rendering for Shared::IndexTableComponent by splitting the existing table markup into dedicated desktop/mobile ViewComponents and updating the Stimulus controller to paginate/filter only the active (visible) layout.
Changes:
- Introduces
DesktopComponentandMobileComponentvariants for the index table UI. - Updates
Shared::IndexTableComponentto render the new subcomponents and centralizes helpers (column_sizes, empty state text, cell renderer). - Adjusts the Stimulus controller to handle multiple layouts/targets and refresh on window resize.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| app/javascript/controllers/index_table_component_controller.js | Refreshes active rows by visible layout; updates empty state + pagination across desktop/mobile targets. |
| app/components/shared/index_table_component.rb | Adds helper methods to support rendering via subcomponents. |
| app/components/shared/index_table_component.html.erb | Renders new desktop/mobile subcomponents and hooks resize refresh action. |
| app/components/shared/index_table_component/desktop_component.rb | New ViewComponent class for desktop layout. |
| app/components/shared/index_table_component/desktop_component.html.erb | Desktop layout markup extracted from original component template. |
| app/components/shared/index_table_component/mobile_component.rb | New ViewComponent class for mobile layout. |
| app/components/shared/index_table_component/mobile_component.html.erb | Mobile card-based layout markup for small screens. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| <div data-controller="index-table-component" data-index-table-component-per-page-value="<%= per_page %>"> | ||
| <div | ||
| data-controller="index-table-component" | ||
| data-action="resize@window->index-table-component#refreshLayout" |
Comment on lines
+1
to
+14
| module Shared | ||
| class IndexTableComponent | ||
| class DesktopComponent < ViewComponent::Base | ||
| attr_reader :records, :columns, :column_sizes, :empty_state_text, :cell_content_renderer | ||
|
|
||
| def initialize(records:, columns:, column_sizes:, empty_state_text:, cell_content_renderer:) | ||
| super() | ||
| @records = records | ||
| @columns = columns | ||
| @column_sizes = column_sizes | ||
| @empty_state_text = empty_state_text | ||
| @cell_content_renderer = cell_content_renderer | ||
| end | ||
| end |
Comment on lines
+1
to
+27
| module Shared | ||
| class IndexTableComponent | ||
| class MobileComponent < ViewComponent::Base | ||
| attr_reader :records, :columns, :empty_state_text, :cell_content_renderer | ||
|
|
||
| def initialize(records:, columns:, empty_state_text:, cell_content_renderer:) | ||
| super() | ||
| @records = records | ||
| @columns = columns | ||
| @empty_state_text = empty_state_text | ||
| @cell_content_renderer = cell_content_renderer | ||
| end | ||
|
|
||
| def content_columns | ||
| columns.reject { |column| action_column?(column) } | ||
| end | ||
|
|
||
| def actions_column | ||
| columns.find { |column| action_column?(column) } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def action_column?(column) | ||
| column.attribute.to_sym == :actions | ||
| end | ||
| end |
Comment on lines
+88
to
+115
| _updatePagination(lastPage) { | ||
| this.paginationTargets.forEach((container, index) => { | ||
| const layout = container.closest("[data-index-table-component-layout]"); | ||
| const isActive = layout && window.getComputedStyle(layout).display !== "none"; | ||
|
|
||
| if (!isActive || lastPage === 0) { | ||
| container.classList.add("hidden"); | ||
| } else { | ||
| container.classList.remove("hidden"); | ||
| } | ||
|
|
||
| const prevBtn = container.querySelector("[data-prev]"); | ||
| const nextBtn = container.querySelector("[data-next]"); | ||
|
|
||
| if (prevBtn) { | ||
| prevBtn.disabled = this._page === 0; | ||
| prevBtn.classList.toggle("btn-disabled", this._page === 0); | ||
| } | ||
|
|
||
| if (nextBtn) { | ||
| nextBtn.disabled = this._page === lastPage; | ||
| nextBtn.classList.toggle("btn-disabled", this._page === lastPage); | ||
| } | ||
|
|
||
| const pageInfo = this.pageInfoTargets[index]; | ||
| if (pageInfo) { | ||
| pageInfo.textContent = `${this._page + 1} of ${lastPage + 1}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Briefly describe what this PR does and why it is needed. Include any relevant background or context.

Checklist