Skip to content

Commit 694a1b2

Browse files
authoredApr 21, 2022
Bug 1764136: improve styling of uplift request form
1 parent 016779a commit 694a1b2

File tree

4 files changed

+114
-24
lines changed

4 files changed

+114
-24
lines changed
 

‎moz-extensions/src/applications/transactions/commentaction/PhabricatorUpdateUpliftCommentAction.php

+3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ public function getPHUIXControlType() {
99

1010
public function getPHUIXControlSpecification() {
1111
$value = $this->getValue();
12+
$initial = false;
1213

1314
if (empty($value) || $value == null) {
1415
$value = $this->getInitialValue();
16+
$initial = true;
1517
}
1618

1719
return array(
20+
'initial' => $initial,
1821
'questions' => $value,
1922
);
2023

‎moz-extensions/src/differential/customfield/DifferentialUpliftRequestCustomField.php

+32-5
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private function getRemarkup(): string {
278278
public function newCommentAction() {
279279
// Returning `null` causes no comment action to render, effectively
280280
// "disabling" the field.
281-
if (!$this->isUpliftTagSet()) {
281+
if (!$this->isFieldActive()) {
282282
return null;
283283
}
284284

@@ -299,22 +299,49 @@ public function validateUpliftForm(array $form): array {
299299
return $validation_errors;
300300
}
301301

302+
$valid_questions = array_keys(self::BETA_UPLIFT_FIELDS);
303+
304+
$validated_question = array();
302305
foreach($form as $question => $answer) {
303-
// `empty(false)` is `true` so handle `bool` separately.
304-
if (is_bool($answer)) {
306+
# Assert the question is valid.
307+
if (!in_array($question, $valid_questions)) {
308+
$validation_errors[] = "Invalid question: '$question'";
305309
continue;
306310
}
307311

308-
if (empty($answer)) {
312+
$default_type = gettype(self::BETA_UPLIFT_FIELDS[$question]);
313+
314+
# Assert the value is not empty.
315+
$empty_string = $default_type == "string" && empty($answer);
316+
$null_bool = $default_type == "boolean" && is_null($answer);
317+
if ($empty_string || $null_bool) {
309318
$validation_errors[] = "Need to answer '$question'";
319+
continue;
320+
}
321+
322+
# Assert the type from the response matches the type of the default.
323+
$answer_type = gettype($answer);
324+
if ($default_type != $answer_type) {
325+
$validation_errors[] = "Parsing error: type '$answer_type' for '$question' doesn't match expected '$default_type'!";
326+
continue;
327+
}
328+
329+
$validated_question[] = $question;
330+
}
331+
332+
# Make sure we have all the required fields present in the response.
333+
$missing = array_diff($valid_questions, $validated_question);
334+
if (empty($validation_errors) && $missing) {
335+
foreach($missing as $missing_question) {
336+
$validation_errors[] = "Missing response for $missing_question";
310337
}
311338
}
312339

313340
return $validation_errors;
314341
}
315342

316343
public function qeRequired() {
317-
return $this->getValue()['Needs manual QE test'];
344+
return $this->getValue()['Needs manual QE test'] === true;
318345
}
319346

320347
public function validateApplicationTransactions(

‎webroot/rsrc/css/phui/phui-form-view.css

+26
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,32 @@ properly, and submit values. */
557557
margin-left: 4px;
558558
}
559559

560+
.phuix-form-form-row {
561+
margin: 2px;
562+
display: table-row;
563+
}
564+
565+
.phuix-form-form-label {
566+
margin: 2px;
567+
display: table-cell;
568+
}
569+
570+
.phuix-form-form-textarea {
571+
width: auto;
572+
margin-left: 4px;
573+
vertical-align: middle;
574+
display: table-cell;
575+
}
576+
577+
.phuix-form-form-select {
578+
margin: 2px;
579+
display: table-cell;
580+
}
581+
582+
.phuix-form-form-table {
583+
display: table;
584+
}
585+
560586
.phui-form-timer-icon {
561587
width: 28px;
562588
height: 28px;

‎webroot/rsrc/js/phuix/PHUIXFormControl.js

+53-19
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,24 @@ JX.install('PHUIXFormControl', {
347347
};
348348
},
349349

350+
// Convert "true" and "false" strings to bool.
351+
_boolValue: function(string_value) {
352+
switch (string_value) {
353+
case 'true':
354+
return true;
355+
case 'false':
356+
return false;
357+
}
358+
359+
return null;
360+
},
361+
350362
// Render a sub-form within the form control space.
351363
// Takes a spec of fields and their answer formats and returns
352364
// a mapping of fields to values.
353365
_newForm: function(spec) {
354-
//var questions_parsed = JX.JSON.parse(spec.questions);
355366
var questions_parsed = spec.questions;
367+
var initial = spec.initial;
356368

357369
var questions = [];
358370
var question_list = [];
@@ -362,42 +374,62 @@ JX.install('PHUIXFormControl', {
362374

363375
// Determine input format, either a bool or a text value.
364376
var value_type = typeof (value);
365-
var input_type;
377+
378+
var question_obj;
366379
if (value_type == "string") {
367-
input_type = "textarea";
380+
question_obj = JX.$N(
381+
'input',
382+
{
383+
className: 'aphront-form-control phuix-form-form-textarea',
384+
type: 'textarea',
385+
value: value,
386+
id: question_id,
387+
question: question,
388+
});
368389
} else if (value_type == "boolean") {
369-
input_type = "checkbox";
390+
// Set "Select One" as the default.
391+
if (initial) {
392+
value = null;
393+
}
394+
question_obj = JX.Prefab.renderSelect(
395+
{
396+
null: 'Select One',
397+
true: 'Yes',
398+
false: 'No',
399+
},
400+
value,
401+
{
402+
className: 'phuix-form-form-select',
403+
id: question_id,
404+
question: question,
405+
value: value,
406+
},
407+
[null, true, false]
408+
);
370409
}
371410

372-
var question_obj = JX.$N(
373-
'input',
374-
{
375-
type: input_type,
376-
value: value,
377-
id: question_id,
378-
question: question,
379-
});
380-
381411
questions.push(question_obj);
382412

383413
var label = JX.$N(
384414
'label',
385415
{
386-
className: 'phuix-form-checkbox-label',
416+
className: 'phuix-form-form-label',
387417
htmlFor: question_id,
388418
},
389419
JX.$H(question || ''));
390420

391421
var display = JX.$N(
392422
'div', {
393-
className: 'phuix-form-checkbox-item'
423+
className: 'phuix-form-form-row',
394424
},
395-
[question_obj, label]);
425+
[label, question_obj]);
396426

397427
question_list.push(display);
398428
}
399429

400-
var node = JX.$N('div', {}, question_list);
430+
var node = JX.$N('div', {
431+
className: 'phui-form-view phui-form-form-table'
432+
}, question_list);
401433

402434
return {
403435
node: node,
@@ -406,8 +438,10 @@ JX.install('PHUIXFormControl', {
406438
for (var ii = 0; ii < questions.length; ii++) {
407439
var question_obj = questions[ii];
408440

409-
if (question_obj.type == "checkbox") {
410-
map[question_obj.question] = question_obj.checked;
441+
if (question_obj.type == "select-one") {
442+
// Convert "true" and "false" string values to boolean.
443+
var bool_val = this._boolValue(question_obj.value);
444+
map[question_obj.question] = bool_val;
411445
} else {
412446
map[question_obj.question] = question_obj.value;
413447
}

0 commit comments

Comments
 (0)
Failed to load comments.