From 5f52f1f82cac38ae43daf11a52f359705167d436 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 Jun 2014 09:15:35 -0700 Subject: [PATCH] Fix some off-by-one issues when drag-and-dropping dashboard panels Summary: Fixes T5321. There were a couple of off-by-one issues here which could result in inserts into the wrong position. Test Plan: - Dragged panels to the top, bottom, and first position of columns. - Dragged panels from one column to another. - Reloaded the page after drags, things stayed where I put them. Reviewers: chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T5321 Differential Revision: https://secure.phabricator.com/D9573 --- ...habricatorDashboardMovePanelController.php | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/applications/dashboard/controller/PhabricatorDashboardMovePanelController.php b/src/applications/dashboard/controller/PhabricatorDashboardMovePanelController.php index 4adbcf721f..a0bb30046b 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardMovePanelController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardMovePanelController.php @@ -41,29 +41,32 @@ final class PhabricatorDashboardMovePanelController $layout_config->removePanel($panel_phid); $panel_location_grid = $layout_config->getPanelLocations(); - $panel_columns = idx($panel_location_grid, $column_id, array()); - if ($panel_columns) { + $column_phids = idx($panel_location_grid, $column_id, array()); + $column_phids = array_values($column_phids); + if ($column_phids) { $insert_at = 0; - $new_panel_columns = $panel_columns; - foreach ($panel_columns as $index => $curr_panel_phid) { - if ($curr_panel_phid === $before_phid) { - $insert_at = max($index - 1, 0); - break; - } - if ($curr_panel_phid === $after_phid) { + foreach ($column_phids as $index => $phid) { + if ($phid === $before_phid) { $insert_at = $index; break; } + if ($phid === $after_phid) { + $insert_at = $index + 1; + break; + } } + + $new_column_phids = $column_phids; array_splice( - $new_panel_columns, + $new_column_phids, $insert_at, 0, array($panel_phid)); } else { - $new_panel_columns = array(0 => $panel_phid); + $new_column_phids = array(0 => $panel_phid); } - $panel_location_grid[$column_id] = $new_panel_columns; + + $panel_location_grid[$column_id] = $new_column_phids; $layout_config->setPanelLocations($panel_location_grid); $dashboard->setLayoutConfigFromObject($layout_config); $dashboard->save();