-
-
Notifications
You must be signed in to change notification settings - Fork 572
4821 part2 partner profile remove attached docs #5090
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
Merged
awwaiid
merged 4 commits into
rubyforgood:main
from
danielabar:4821-part2-partner-profile-remove-attached-docs
Mar 15, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1fd8e7c
use remove_element_button ui helper to remove individual attached doc…
danielabar 6e5957f
style attached documents list and remove buttons
danielabar 06edb5d
system test to verify removal of individual attached doc for partner …
danielabar 771a028
enhance multiple file input with javascript to display selected file …
danielabar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { Controller } from "@hotwired/stimulus"; | ||
|
|
||
| /** | ||
| * Stimulus controller to enhance the file input UI for multiple files. | ||
| * | ||
| * This controller: | ||
| * - Listens for file selection on an `<input type="file" multiple="multiple">` | ||
| * - Displays selected file names in a custom list **when multiple files are selected | ||
| * - Defaults to the browser’s built-in display for a single file selection | ||
| * | ||
| * Expected HTML structure should have a placeholder div for the selected file names: | ||
| * | ||
| * ```erb | ||
| * <div data-controller="file-input"> | ||
| * <input type="file" multiple data-file-input-target="input"> | ||
| * <div data-file-input-target="list"></div> | ||
| * </div> | ||
| * ``` | ||
| */ | ||
| export default class extends Controller { | ||
| static targets = ["input", "list"]; | ||
|
|
||
| connect() { | ||
| this.inputTarget.addEventListener("change", () => this.updateFileList()); | ||
| } | ||
|
|
||
| updateFileList() { | ||
| const files = this.inputTarget.files; | ||
| this.listTarget.innerHTML = ""; // Clear previous list | ||
|
|
||
| // If no files or only one file is selected, let the native UI handle it | ||
| if (files.length <= 1) { | ||
| return; | ||
| } | ||
|
|
||
| const ul = document.createElement("ul"); | ||
| ul.classList.add("list-unstyled", "mt-2"); | ||
|
|
||
| Array.from(files).forEach((file) => { | ||
| const li = document.createElement("li"); | ||
| li.classList.add("p-1", "rounded", "mb-1"); | ||
| li.textContent = file.name; | ||
| ul.appendChild(li); | ||
| }); | ||
|
|
||
| this.listTarget.appendChild(ul); | ||
| } | ||
| } | ||
20 changes: 13 additions & 7 deletions
20
app/views/partners/profiles/step/_attached_documents_form.html.erb
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,24 @@ | ||
| <%= f.fields_for :profile, profile do |pf| %> | ||
| <div class="form-group"> | ||
| <div class="form-group" data-controller="file-input"> | ||
| <% if profile.documents.attached? %> | ||
| <strong>Attached files:</strong> | ||
| <ul> | ||
| <ul class="list-unstyled"> | ||
| <% profile.documents.each do |doc| %> | ||
| <% if doc.persisted? %> | ||
| <li><%= link_to doc.blob['filename'], rails_blob_path(doc), class: "font-weight-bold" %></li> | ||
| <%= pf.hidden_field :documents, multiple: true, value: doc.signed_id %> | ||
| <li class="attached-document d-flex justify-content-between align-items-center p-2 border rounded mb-2" data-document-id="<%= doc.signed_id %>"> | ||
| <div class="text-truncate" style="max-width: 75%;"> | ||
| <%= link_to doc.blob.filename.to_s, rails_blob_path(doc), class: "font-weight-bold" %> | ||
| <%= pf.hidden_field :documents, multiple: true, value: doc.signed_id %> | ||
| </div> | ||
| <%= remove_element_button "Remove", container_selector: "li", class: "btn btn-sm btn-danger" %> | ||
| </li> | ||
| <% end %> | ||
| <% end %> | ||
| </ul> | ||
| <%= pf.file_field :documents, multiple: true, class: "form-control-file" %> | ||
| <% else %> | ||
| <%= pf.file_field :documents, multiple: true, class: "form-control-file" %> | ||
| <% end %> | ||
|
|
||
| <%# Native file input and placeholder for selected file names %> | ||
| <%= pf.file_field :documents, multiple: true, class: "form-control-file", data: { file_input_target: "input" } %> | ||
| <div data-file-input-target="list" class="mt-2"></div> | ||
| </div> | ||
| <% end %> |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fine way to do it, but thinking to myself here I wish we didn't need the
mt-2; seems like it might later be harder to maintain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried removing the
mt-2and it looks fine. This has already been merged but there's still a Part 3 for this issue, so I can remove the extra margin in that PR.