-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow cards to be moved to other pages or to new pages
Blocked on atlassian/react-beautiful-dnd#930 for actual mouse-driven drag and drop (since the size of a card is too large relative to the table of contents), but using the keyboard mode this works. Drag a card onto a page in the TOC to move it to that page. Or drag it between two entries in the TOC to create a new page at that location.
- Loading branch information
Showing
15 changed files
with
246 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
# For validating updates to {Card}s | ||
class UpdateCardForm | ||
include ActiveModel::Model | ||
|
||
attr_accessor :card | ||
|
||
validate :new_element_is_page_in_case? | ||
|
||
def save | ||
return unless valid? && card.valid? | ||
|
||
card.save | ||
end | ||
|
||
private | ||
|
||
def new_element_is_page_in_case? | ||
return unless card.element_changed? | ||
return unless card.element.is_a?(Page) && card.element.case == card.case | ||
|
||
errors.add :card, 'can only be moved to a Page in the same Case' | ||
end | ||
end |
This file contains 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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
# For validating updates to {Card}s | ||
class UpdateCardForm | ||
include ActiveModel::Model | ||
|
||
attr_accessor :card, :position, :solid, :raw_content, :page_id | ||
|
||
validates :card, presence: true | ||
validate :new_element_is_page_in_case? | ||
|
||
def save | ||
card.assign_attributes card_params | ||
|
||
return unless valid? | ||
|
||
card.save! | ||
true | ||
end | ||
|
||
private | ||
|
||
def new_element_is_page_in_case? | ||
return unless page.present? | ||
return if page.case == card.case | ||
|
||
errors.add :card, 'can only be moved to a Page in the same Case' | ||
end | ||
|
||
def page | ||
@page ||= Page.find page_id | ||
rescue ActiveRecord::RecordNotFound | ||
nil | ||
end | ||
|
||
def card_params | ||
{ | ||
position: position, | ||
solid: solid, | ||
raw_content: raw_content, | ||
element: page | ||
}.compact | ||
end | ||
end |
This file contains 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 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 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 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 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 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,25 @@ | ||
/* @noflow */ | ||
|
||
import reducer from '../caseData.js' | ||
|
||
describe('caseData reducer', () => { | ||
describe('AddPageAction', () => { | ||
test('works', () => { | ||
const state = { | ||
caseElements: [{ id: 1, position: 1 }, { id: 2, position: 2 }], | ||
} | ||
const action = { | ||
type: 'ADD_PAGE', | ||
data: { caseElement: { id: 3, position: 2 }}, | ||
} | ||
|
||
expect(reducer(state, action)).toEqual({ | ||
caseElements: [ | ||
{ id: 1, position: 1 }, | ||
{ id: 3, position: 2 }, | ||
{ id: 2, position: 2 }, | ||
], | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains 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 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 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 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
Oops, something went wrong.