-
Notifications
You must be signed in to change notification settings - Fork 787
Add hotkeys for triaging cards in columns #2211
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
+228
−7
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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,130 @@ | ||
| import { Controller } from "@hotwired/stimulus" | ||
| import { post } from "@rails/request.js" | ||
|
|
||
| export default class extends Controller { | ||
| static outlets = [ "navigable-list" ] | ||
|
|
||
| connect() { | ||
| this.morphCompletePromise = null | ||
| this.morphCompleteResolver = null | ||
| } | ||
|
|
||
| handleKeydown(event) { | ||
| if (this.#shouldIgnore(event)) return | ||
|
|
||
| const handler = this.#keyHandlers[event.key.toLowerCase()] | ||
| if (handler) { | ||
| handler.call(this, event) | ||
| } | ||
| } | ||
|
|
||
| // Called when turbo:morph completes - resolves our waiting promise | ||
| handleMorphComplete() { | ||
| if (this.morphCompleteResolver) { | ||
| this.morphCompleteResolver() | ||
| this.morphCompleteResolver = null | ||
| this.morphCompletePromise = null | ||
| } | ||
| } | ||
|
|
||
| // Private | ||
|
|
||
| #shouldIgnore(event) { | ||
| const target = event.target | ||
| return target.tagName === "INPUT" || | ||
| target.tagName === "TEXTAREA" || | ||
| target.isContentEditable || | ||
| target.closest("input, textarea, [contenteditable], lexxy-editor") | ||
| } | ||
|
|
||
| get #selectedCard() { | ||
| // Find the navigable-list that currently has focus | ||
| const focusedList = this.navigableListOutlets.find(list => list.hasFocus) | ||
| if (!focusedList) return null | ||
|
|
||
| const currentItem = focusedList.currentItem | ||
| if (currentItem?.classList.contains("card") && !this.#hotkeysDisabled(focusedList)) { | ||
| return { card: currentItem, controller: focusedList } | ||
| } | ||
| return null | ||
| } | ||
|
|
||
| async #postponeCard(event) { | ||
| const selection = this.#selectedCard | ||
| if (!selection) return | ||
|
|
||
| const url = selection.card.dataset.cardNotNowUrl | ||
| if (url) { | ||
| event.preventDefault() | ||
| await this.#performCardAction(url, selection) | ||
| } | ||
| } | ||
|
|
||
| async #closeCard(event) { | ||
| const selection = this.#selectedCard | ||
| if (!selection) return | ||
|
|
||
| const url = selection.card.dataset.cardClosureUrl | ||
| if (url) { | ||
| event.preventDefault() | ||
| await this.#performCardAction(url, selection) | ||
| } | ||
| } | ||
|
|
||
| async #assignToMe(event) { | ||
| const selection = this.#selectedCard | ||
| if (!selection) return | ||
|
|
||
| const url = selection.card.dataset.cardAssignToMeUrl | ||
| if (url) { | ||
| event.preventDefault() | ||
| await post(url, { responseKind: "turbo-stream" }) | ||
| } | ||
| } | ||
|
|
||
| async #performCardAction(url, selection) { | ||
| const { controller } = selection | ||
| const visibleItems = controller.visibleItems | ||
| const currentIndex = visibleItems.indexOf(selection.card) | ||
| const wasLastItem = currentIndex === visibleItems.length - 1 | ||
|
|
||
| // Set up promise to wait for morph completion | ||
| this.morphCompletePromise = new Promise(resolve => { | ||
| this.morphCompleteResolver = resolve | ||
| }) | ||
|
|
||
| await post(url, { responseKind: "turbo-stream" }) | ||
|
|
||
| // Wait for Turbo Stream morph to complete | ||
| await Promise.race([ | ||
| this.morphCompletePromise, | ||
| new Promise(resolve => setTimeout(resolve, 200)) // Fallback timeout | ||
| ]) | ||
|
|
||
| // Select the next card (or previous if it was the last) | ||
| const newVisibleItems = controller.visibleItems | ||
| if (newVisibleItems.length === 0) { | ||
| controller.clearSelection() | ||
| return | ||
| } | ||
|
|
||
| if (wasLastItem) { | ||
| controller.selectLast() | ||
| } else { | ||
| const nextIndex = Math.min(currentIndex, newVisibleItems.length - 1) | ||
| if (newVisibleItems[nextIndex]) { | ||
| await controller.selectItem(newVisibleItems[nextIndex]) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #hotkeysDisabled(navigableList) { | ||
| return navigableList?.element.dataset.cardHotkeysDisabled === "true" | ||
| } | ||
|
|
||
| #keyHandlers = { | ||
| "["(event) { this.#postponeCard(event) }, | ||
| "]"(event) { this.#closeCard(event) }, | ||
| m(event) { this.#assignToMe(event) } | ||
| } | ||
| } | ||
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
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
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
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
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,9 @@ | ||
| <%= turbo_stream.replace("closed-cards", partial: "boards/show/closed", method: :morph, locals: { board: @card.board }) %> | ||
|
|
||
| <% if @source_column %> | ||
| <%= turbo_stream.replace(dom_id(@source_column), partial: "boards/show/column", method: :morph, locals: { column: @source_column }) %> | ||
| <% elsif @was_in_stream %> | ||
| <%= turbo_stream.replace("the-stream", partial: "boards/show/stream", method: :morph, locals: { board: @card.board, page: @page }) %> | ||
| <% end %> | ||
|
|
||
| <%= turbo_stream.replace([ @card, :card_container ], partial: "cards/container", method: :morph, locals: { card: @card.reload }) %> |
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,9 @@ | ||
| <%= turbo_stream.replace("closed-cards", partial: "boards/show/closed", method: :morph, locals: { board: @card.board }) %> | ||
|
|
||
| <% if @card.column %> | ||
| <%= turbo_stream.replace(dom_id(@card.column), partial: "boards/show/column", method: :morph, locals: { column: @card.column }) %> | ||
| <% elsif @card.awaiting_triage? %> | ||
| <%= turbo_stream.replace("the-stream", partial: "boards/show/stream", method: :morph, locals: { board: @card.board, page: @page }) %> | ||
| <% end %> | ||
|
|
||
| <%= turbo_stream.replace([ @card, :card_container ], partial: "cards/container", method: :morph, locals: { card: @card.reload }) %> |
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
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
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,9 @@ | ||
| <%= turbo_stream.replace("not-now", partial: "boards/show/not_now", method: :morph, locals: { board: @card.board }) %> | ||
|
|
||
| <% if @source_column %> | ||
| <%= turbo_stream.replace(dom_id(@source_column), partial: "boards/show/column", method: :morph, locals: { column: @source_column }) %> | ||
| <% elsif @was_in_stream %> | ||
| <%= turbo_stream.replace("the-stream", partial: "boards/show/stream", method: :morph, locals: { board: @card.board, page: @page }) %> | ||
| <% end %> | ||
|
|
||
| <%= turbo_stream.replace([ @card, :card_container ], partial: "cards/container", method: :morph, locals: { card: @card.reload }) %> |
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.
Uh oh!
There was an error while loading. Please reload this page.