Skip to content

Commit 968ac76

Browse files
author
epriestley
committed
Don't adjust task priority after a workboard drag unless we need to
Summary: Fixes T8197. Currently, if you priority-sort a workboard and drag a card to the top or bottom, we change the priority even if we do not need to. For example, if the lowest priority in a column is "Low", and you drag a "Wishlist" task underneath it, we incorrectly increase the priority of the task to "Low", when we do not actually need to touch it. This is bad/confusing. A similar thing happens when dragging a "High" priority task to the top of a column where the highest priority is currently "Normal". Test Plan: - Create a column with a "Normal" task. - Sort workboard by Priority. - Drag a "High" task above it. After patch: task still "High". - Drag a "Wishlist" task below it. After patch: task still "Wishlist". Also dragged a ton of tasks into the middle of other tasks. Reviewers: chad Reviewed By: chad Maniphest Tasks: T8197 Differential Revision: https://secure.phabricator.com/D15240
1 parent 0b5abf7 commit 968ac76

File tree

2 files changed

+133
-49
lines changed

2 files changed

+133
-49
lines changed

src/applications/maniphest/storage/ManiphestTask.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,39 @@ public function getWorkboardOrderVectors() {
221221
);
222222
}
223223

224+
private function comparePriorityTo(ManiphestTask $other) {
225+
$upri = $this->getPriority();
226+
$vpri = $other->getPriority();
227+
228+
if ($upri != $vpri) {
229+
return ($upri - $vpri);
230+
}
231+
232+
$usub = $this->getSubpriority();
233+
$vsub = $other->getSubpriority();
234+
235+
if ($usub != $vsub) {
236+
return ($usub - $vsub);
237+
}
238+
239+
$uid = $this->getID();
240+
$vid = $other->getID();
241+
242+
if ($uid != $vid) {
243+
return ($uid - $vid);
244+
}
245+
246+
return 0;
247+
}
248+
249+
public function isLowerPriorityThan(ManiphestTask $other) {
250+
return ($this->comparePriorityTo($other) < 0);
251+
}
252+
253+
public function isHigherPriorityThan(ManiphestTask $other) {
254+
return ($this->comparePriorityTo($other) > 0);
255+
}
256+
224257
public function getWorkboardProperties() {
225258
return array(
226259
'status' => $this->getStatus(),

src/applications/project/controller/PhabricatorProjectMoveController.php

Lines changed: 100 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -90,55 +90,13 @@ public function handleRequest(AphrontRequest $request) {
9090
'projectPHID' => $column->getProjectPHID(),
9191
));
9292

93-
$task_phids = array();
94-
if ($after_phid) {
95-
$task_phids[] = $after_phid;
96-
}
97-
if ($before_phid) {
98-
$task_phids[] = $before_phid;
99-
}
100-
101-
if ($task_phids && ($order == PhabricatorProjectColumn::ORDER_PRIORITY)) {
102-
$tasks = id(new ManiphestTaskQuery())
103-
->setViewer($viewer)
104-
->withPHIDs($task_phids)
105-
->needProjectPHIDs(true)
106-
->requireCapabilities(
107-
array(
108-
PhabricatorPolicyCapability::CAN_VIEW,
109-
PhabricatorPolicyCapability::CAN_EDIT,
110-
))
111-
->execute();
112-
if (count($tasks) != count($task_phids)) {
113-
return new Aphront404Response();
114-
}
115-
$tasks = mpull($tasks, null, 'getPHID');
116-
117-
$try = array(
118-
array($after_phid, true),
119-
array($before_phid, false),
120-
);
121-
122-
$pri = null;
123-
$sub = null;
124-
foreach ($try as $spec) {
125-
list($task_phid, $is_after) = $spec;
126-
$task = idx($tasks, $task_phid);
127-
if ($task) {
128-
list($pri, $sub) = ManiphestTransactionEditor::getAdjacentSubpriority(
129-
$task,
130-
$is_after);
131-
break;
132-
}
133-
}
134-
135-
if ($pri !== null) {
136-
$xactions[] = id(new ManiphestTransaction())
137-
->setTransactionType(ManiphestTransaction::TYPE_PRIORITY)
138-
->setNewValue($pri);
139-
$xactions[] = id(new ManiphestTransaction())
140-
->setTransactionType(ManiphestTransaction::TYPE_SUBPRIORITY)
141-
->setNewValue($sub);
93+
if ($order == PhabricatorProjectColumn::ORDER_PRIORITY) {
94+
$priority_xactions = $this->getPriorityTransactions(
95+
$object,
96+
$after_phid,
97+
$before_phid);
98+
foreach ($priority_xactions as $xaction) {
99+
$xactions[] = $xaction;
142100
}
143101
}
144102

@@ -179,4 +137,97 @@ public function handleRequest(AphrontRequest $request) {
179137
return $this->newCardResponse($board_phid, $object_phid);
180138
}
181139

140+
private function getPriorityTransactions(
141+
ManiphestTask $task,
142+
$after_phid,
143+
$before_phid) {
144+
145+
list($after_task, $before_task) = $this->loadPriorityTasks(
146+
$after_phid,
147+
$before_phid);
148+
149+
$must_move = false;
150+
if ($after_task && !$task->isLowerPriorityThan($after_task)) {
151+
$must_move = true;
152+
}
153+
154+
if ($before_task && !$task->isHigherPriorityThan($before_task)) {
155+
$must_move = true;
156+
}
157+
158+
// The move doesn't require a priority change to be valid, so don't
159+
// change the priority since we are not being forced to.
160+
if (!$must_move) {
161+
return array();
162+
}
163+
164+
$try = array(
165+
array($after_task, true),
166+
array($before_task, false),
167+
);
168+
169+
$pri = null;
170+
$sub = null;
171+
foreach ($try as $spec) {
172+
list($task, $is_after) = $spec;
173+
174+
if (!$task) {
175+
continue;
176+
}
177+
178+
list($pri, $sub) = ManiphestTransactionEditor::getAdjacentSubpriority(
179+
$task,
180+
$is_after);
181+
}
182+
183+
$xactions = array();
184+
if ($pri !== null) {
185+
$xactions[] = id(new ManiphestTransaction())
186+
->setTransactionType(ManiphestTransaction::TYPE_PRIORITY)
187+
->setNewValue($pri);
188+
$xactions[] = id(new ManiphestTransaction())
189+
->setTransactionType(ManiphestTransaction::TYPE_SUBPRIORITY)
190+
->setNewValue($sub);
191+
}
192+
193+
return $xactions;
194+
}
195+
196+
private function loadPriorityTasks($after_phid, $before_phid) {
197+
$viewer = $this->getViewer();
198+
199+
$task_phids = array();
200+
201+
if ($after_phid) {
202+
$task_phids[] = $after_phid;
203+
}
204+
if ($before_phid) {
205+
$task_phids[] = $before_phid;
206+
}
207+
208+
if (!$task_phids) {
209+
return array(null, null);
210+
}
211+
212+
$tasks = id(new ManiphestTaskQuery())
213+
->setViewer($viewer)
214+
->withPHIDs($task_phids)
215+
->execute();
216+
$tasks = mpull($tasks, null, 'getPHID');
217+
218+
if ($after_phid) {
219+
$after_task = idx($tasks, $after_phid);
220+
} else {
221+
$after_task = null;
222+
}
223+
224+
if ($before_phid) {
225+
$before_task = idx($tasks, $before_phid);
226+
} else {
227+
$before_task = null;
228+
}
229+
230+
return array($after_task, $before_task);
231+
}
232+
182233
}

0 commit comments

Comments
 (0)