Merge pull request #2032 from tomycostantino/update-columns-on-actions
Fix: board columns actions are stale when moving a column moves
This commit is contained in:
@@ -35,7 +35,7 @@ class Boards::ColumnsController < ApplicationController
|
||||
@column.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream
|
||||
format.html { redirect_back_or_to @board }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,6 +31,10 @@ module Column::Positioned
|
||||
right_column.nil?
|
||||
end
|
||||
|
||||
def adjacent_columns
|
||||
board.columns.where(id: [ left_column&.id, right_column&.id ].compact)
|
||||
end
|
||||
|
||||
private
|
||||
def set_position
|
||||
max_position = board.columns.maximum(:position) || 0
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
<%= turbo_stream.before("closed-cards", partial: "boards/show/column", method: :morph, locals: { column: @column }) %>
|
||||
<%= render "columns/refresh_adjacent_columns", column: @column %>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<%= turbo_stream.remove(dom_id(@column)) %>
|
||||
@@ -0,0 +1,3 @@
|
||||
<% column.adjacent_columns.each do |adjacent_column| %>
|
||||
<%= turbo_stream.replace(dom_id(adjacent_column), partial: "boards/show/column", method: :morph, locals: { column: adjacent_column }) %>
|
||||
<% end %>
|
||||
@@ -1,4 +1,5 @@
|
||||
<% if @left_column %>
|
||||
<%= turbo_stream.remove(dom_id(@column)) %>
|
||||
<%= turbo_stream.before(@left_column, partial: "boards/show/column", locals: { column: @column }) %>
|
||||
<%= render "columns/refresh_adjacent_columns", column: @column %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<% if @right_column %>
|
||||
<%= turbo_stream.remove(dom_id(@column)) %>
|
||||
<%= turbo_stream.after(@right_column, partial: "boards/show/column", locals: { column: @column }) %>
|
||||
<%= render "columns/refresh_adjacent_columns", column: @column %>
|
||||
<% end %>
|
||||
|
||||
@@ -19,6 +19,17 @@ class Boards::ColumnsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal "New Column", boards(:writebook).columns.last.name
|
||||
end
|
||||
|
||||
test "create refreshes adjacent columns" do
|
||||
board = boards(:writebook)
|
||||
|
||||
post board_columns_path(board), params: { column: { name: "New Column" } }, as: :turbo_stream
|
||||
|
||||
new_column = board.columns.find_by!(name: "New Column")
|
||||
new_column.adjacent_columns.each do |adjacent_column|
|
||||
assert_turbo_stream action: :replace, target: dom_id(adjacent_column)
|
||||
end
|
||||
end
|
||||
|
||||
test "update" do
|
||||
column = columns(:writebook_in_progress)
|
||||
|
||||
@@ -29,12 +40,12 @@ class Boards::ColumnsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "destroy" do
|
||||
column = columns(:writebook_on_hold)
|
||||
column = columns(:writebook_in_progress)
|
||||
adjacent_columns = column.adjacent_columns.to_a
|
||||
|
||||
assert_difference -> { boards(:writebook).columns.count }, -1 do
|
||||
delete board_column_path(boards(:writebook), column), as: :turbo_stream
|
||||
assert_response :success
|
||||
end
|
||||
delete board_column_path(column.board, column), as: :turbo_stream
|
||||
|
||||
assert_redirected_to board_path(column.board)
|
||||
end
|
||||
|
||||
test "index as JSON" do
|
||||
|
||||
@@ -21,6 +21,16 @@ class Columns::LeftPositionsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal original_position_a, column_b.reload.position
|
||||
end
|
||||
|
||||
test "move left refreshes adjacent columns" do
|
||||
column = columns(:writebook_in_progress)
|
||||
|
||||
post column_left_position_path(column), as: :turbo_stream
|
||||
|
||||
column.reload.adjacent_columns.each do |adjacent_column|
|
||||
assert_turbo_stream action: :replace, target: dom_id(adjacent_column)
|
||||
end
|
||||
end
|
||||
|
||||
test "users can only reorder columns in boards they have access to" do
|
||||
column = columns(:writebook_in_progress)
|
||||
|
||||
|
||||
@@ -21,6 +21,16 @@ class Columns::RightPositionsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal original_position_a, column_b.reload.position
|
||||
end
|
||||
|
||||
test "move right refreshes adjacent columns" do
|
||||
column = columns(:writebook_in_progress)
|
||||
|
||||
post column_right_position_path(column), as: :turbo_stream
|
||||
|
||||
column.reload.adjacent_columns.each do |adjacent_column|
|
||||
assert_turbo_stream action: :replace, target: dom_id(adjacent_column)
|
||||
end
|
||||
end
|
||||
|
||||
test "users can only reorder columns in boards they have access to" do
|
||||
column = columns(:writebook_triage)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user