Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: dashboard/dashboard/elements/test-picker.html

Issue 2767433002: Start using /list_tests to populate subtest menus in test-picker (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright 2016 The Chromium Authors. All rights reserved. 3 Copyright 2016 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 7
8 <link rel="import" href="/components/iron-flex-layout/iron-flex-layout-classes.h tml"> 8 <link rel="import" href="/components/iron-flex-layout/iron-flex-layout-classes.h tml">
9 <link rel="import" href="/components/paper-button/paper-button.html"> 9 <link rel="import" href="/components/paper-button/paper-button.html">
10 <link rel="import" href="/components/paper-icon-button/paper-icon-button.html"> 10 <link rel="import" href="/components/paper-icon-button/paper-icon-button.html">
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 * Handles dropdown menu select; updates the subsequent menu accordingly. 246 * Handles dropdown menu select; updates the subsequent menu accordingly.
247 */ 247 */
248 onDropdownSelect: function(event) { 248 onDropdownSelect: function(event) {
249 var model = event.model; 249 var model = event.model;
250 var boxIndex = model.index; 250 var boxIndex = model.index;
251 if (boxIndex === undefined) { 251 if (boxIndex === undefined) {
252 return; 252 return;
253 } else if (boxIndex == 0) { 253 } else if (boxIndex == 0) {
254 this.updateTestSuiteDescription(); 254 this.updateTestSuiteDescription();
255 this.updateBotMenu(); 255 this.updateBotMenu();
256 } else if (boxIndex == 1) {
257 this.sendSubtestRequest();
258 } else { 256 } else {
259 // Update all the next dropdown menus for subtests. 257 // Update all the next dropdown menus for subtests.
260 this.updateSubtestMenus(boxIndex + 1); 258 this.updateSubtestMenus(boxIndex + 1);
261 } 259 }
262 }, 260 },
263 261
264 updateTestSuiteDescription: function() { 262 updateTestSuiteDescription: function() {
265 // Display the test suite description if there is one. 263 // Display the test suite description if there is one.
266 var descriptionElement = this.$['suite-description']; 264 var descriptionElement = this.$['suite-description'];
267 var suite = this.getSelectionMenu(0).selectedName; 265 var suite = this.getSelectionMenu(0).selectedName;
(...skipping 14 matching lines...) Expand all
282 280
283 /** 281 /**
284 * Updates bot dropdown menu with bot items. 282 * Updates bot dropdown menu with bot items.
285 */ 283 */
286 updateBotMenu: function() { 284 updateBotMenu: function() {
287 var menu = this.getSelectionMenu(1); 285 var menu = this.getSelectionMenu(1);
288 var botItems = this.getBotItems(); 286 var botItems = this.getBotItems();
289 menu.set('items', botItems); 287 menu.set('items', botItems);
290 menu.set('disabled', botItems.length === 0); 288 menu.set('disabled', botItems.length === 0);
291 this.subtestDict = null; 289 this.subtestDict = null;
292 // If there's a selection, send a subtest request. 290 // If there's a selection, update the subtest menus.
293 if (menu.selectedItem) { 291 if (menu.selectedItem) {
294 this.sendSubtestRequest(); 292 this.updateSubtestMenus(2);
295 } else { 293 } else {
296 // Clear all subtest menus. 294 // Clear all subtest menus.
297 this.splice('selectionModels', 2); 295 this.splice('selectionModels', 2);
298 } 296 }
299 this.updateAddButtonState(); 297 this.updateAddButtonState();
300 }, 298 },
301 299
302 /** 300 /**
303 * Sends a request for subtestDict base on selected test suite and bot.
304 */
305 sendSubtestRequest: function() {
306 if (this.subtestXhr) {
307 this.subtestXhr.abort();
308 this.subtestXhr = null;
309 }
310 var bot = this.getCheckedBot();
311 // If no bot is selected, just leave the current subtests.
312 if (bot === null) {
313 return;
314 }
315 var suite = this.getCheckedSuite();
316 if (!suite) {
317 return;
318 }
319
320 this.loading = true;
321
322 var params = {
323 type: 'sub_tests',
324 suite: suite,
325 bots: bot,
326 xsrf_token: this.xsrfToken
327 };
328 this.subtestXhr = simple_xhr.send(
329 '/list_tests',
330 params,
331 function(response) {
332 this.loading = false;
333 this.subtestDict = response;
334 // Start at first subtest menu.
335 this.updateSubtestMenus(2);
336 }.bind(this),
337 function(error) {
338 // TODO: Display error.
339 this.loading = false;
340 }.bind(this)
341 );
342 },
343
344 /**
345 * Updates all subtest menus starting at 'startIndex'. 301 * Updates all subtest menus starting at 'startIndex'.
346 */ 302 */
347 updateSubtestMenus: function(startIndex) { 303 updateSubtestMenus: async function(startIndex) {
shatch 2017/03/22 17:10:13 Just for record-keeping since we spoke offline, si
348 var subtestDict = this.getSubtestAtIndex(startIndex); 304 // If there's no selection model at this level yet, we must make one.
305 if (startIndex >= this.selectionModels.length) {
306 this.loading = true;
349 307
350 // Update existing subtest menu. 308 const children = await this.getChildren(
309 this.getCurrentPreselectedPath());
310 this.loading = false;
311
312 this.push('selectionModels', {
313 placeholder: this.SUBTEST_LABEL,
314 datalist: children,
315 disabled: false,
316 });
317
318 Polymer.dom.flush();
319 }
320
351 for (var i = startIndex; i < this.selectionModels.length; i++) { 321 for (var i = startIndex; i < this.selectionModels.length; i++) {
352 // Remove the rest of the menu if no subtestDict. 322 const children = await this.getChildren(
353 if (!subtestDict || Object.keys(subtestDict).length == 0) { 323 this.getCurrentPreselectedPath());
sullivan 2017/03/21 13:24:23 This is pretty confusing. It seems like either: *
shatch 2017/03/21 17:48:02 Yeah this could use some clarification, had to pas
324 // Remove the rest of the menu if no children.
325 if (children.length === 0) {
354 this.splice('selectionModels', i); 326 this.splice('selectionModels', i);
355 this.updateAddButtonState(); 327 this.updateAddButtonState();
356 return; 328 return;
357 } 329 }
358 var subtestItems = this.getSubtestItems(subtestDict); 330 const menu = this.getSelectionMenu(i);
359 var menu = this.getSelectionMenu(i); 331 menu.set('items', children);
360 menu.set('items', subtestItems);
361 332
362 // If there are selected item, update next menu. 333 // If there are selected item, update next menu.
363 if (menu.selectedItem) { 334 if (menu.selectedItem) {
364 subtestDict = subtestDict[menu.selectedName]['sub_tests']; 335 continue;
365 } else { 336 } else {
366 subtestDict = null; 337 break;
367 } 338 }
368 } 339 }
369 340
370 // Check if we still need to add a subtest menu.
371 if (subtestDict && Object.keys(subtestDict).length > 0) {
372 var subtestItems = this.getSubtestItems(subtestDict);
373 this.push('selectionModels', {
374 placeholder: this.SUBTEST_LABEL,
375 datalist: subtestItems,
376 disabled: false,
377 });
378 Polymer.dom.flush();
379 var menu = this.getSelectionMenu(this.selectionModels.length - 1);
380 menu.set('items', subtestItems);
381 }
382
383 this.updateAddButtonState(); 341 this.updateAddButtonState();
384 }, 342 },
385 343
386 updateAddButtonState: function() { 344 updateAddButtonState: function() {
387 this.enableAddSeries = this.getCurrentSelection() instanceof Array; 345 this.enableAddSeries = this.getCurrentSelection() instanceof Array;
388 }, 346 },
389 347
390 getSubtestAtIndex: function(index) { 348 getChildren: function(path) {
391 var subtestDict = this.subtestDict; 349 const testPathDict = {};
392 for (var i = 2; i < index; i++) { 350 testPathDict[path] = 'all';
393 var test = this.getSelectionMenu(i).selectedName; 351 const params = {
394 if (test in subtestDict) { 352 type: 'test_path_dict',
395 subtestDict = subtestDict[test]['sub_tests']; 353 return_selected: '1',
396 } else { 354 test_path_dict: JSON.stringify(testPathDict)
397 return null; 355 };
398 }
399 }
400 return subtestDict;
401 },
402 356
403 getSubtestItems: function(subtestDict) { 357 return simple_xhr.asPromise('/list_tests', params);
404 var subtestItems = [];
405 var subtestNames = Object.keys(subtestDict).sort();
406 for (var i = 0; i < subtestNames.length; i++) {
407 var name = subtestNames[i];
408 subtestItems.push({
409 name: name,
410 tag: (subtestDict[name]['deprecated'] ? this.DEPRECATED_TAG : '')
411 });
412 }
413 return subtestItems;
414 }, 358 },
415 359
416 getCheckedBot: function() { 360 getCheckedBot: function() {
417 var botMenu = this.getSelectionMenu(1); 361 var botMenu = this.getSelectionMenu(1);
418 if (botMenu.selectedItem) { 362 if (botMenu.selectedItem) {
419 let item = botMenu.selectedItem; 363 let item = botMenu.selectedItem;
420 return item['group'] + '/' + item['name']; 364 return item['group'] + '/' + item['name'];
421 } 365 }
422 return null; 366 return null;
423 }, 367 },
(...skipping 27 matching lines...) Expand all
451 */ 395 */
452 onAddButtonClicked: function(event, detail) { 396 onAddButtonClicked: function(event, detail) {
453 this.fire('add'); 397 this.fire('add');
454 }, 398 },
455 399
456 /** 400 /**
457 * Gets the current selection from the menus. Returns null unless there 401 * Gets the current selection from the menus. Returns null unless there
458 * is a valid selection. 402 * is a valid selection.
459 */ 403 */
460 getCurrentSelection: function() { 404 getCurrentSelection: function() {
405 const path = this.getCurrentPreselectedPath(true);
406 if (this.currentSelectedPath_ === path) {
407 return this.currentSelectedTests_;
408 }
409 this.currentSelectedPath_ = path;
410 this.sendListTestsRequest(path);
411 return null;
412 },
413
414 getCurrentPreselectedPath: function(onlyValid) {
461 var level = 0; 415 var level = 0;
462 var parts = []; 416 var parts = [];
463 while (true) { 417 while (true) {
464 var menu = this.getSelectionMenu(level); 418 var menu = this.getSelectionMenu(level);
465 if (!menu || !menu.selectedItem) { 419 if (!menu || !menu.selectedItem) {
466 // A selection is only valid if it specifies at least one subtest 420 // A selection is only valid if it specifies at least one subtest
467 // component, which is the third level. 421 // component, which is the third level.
468 if (level <= 2) return null; 422 if (onlyValid && level <= 2) return null;
469 break; 423 break;
470 } else { 424 } else {
471 // We want to collect all the subtest components so we can form 425 // We want to collect all the subtest components so we can form
472 // the full test path after this loop is done. 426 // the full test path after this loop is done.
473 if (level >= 2) parts.push(menu.selectedItem.name); 427 if (level >= 2) parts.push(menu.selectedItem.name);
474 } 428 }
475 level += 1; 429 level += 1;
476 } 430 }
477 431
478 var suite = this.getSelectionMenu(0).selectedItem.name; 432 var suite = this.getSelectionMenu(0).selectedItem.name;
479 var bot = this.getCheckedBot(); 433 var bot = this.getCheckedBot();
480 parts.unshift(suite); 434 parts.unshift(suite);
481 parts.unshift(bot); 435 parts.unshift(bot);
482 436
483 var path = parts.join('/'); 437 return parts.join('/');
484
485 if (this.currentSelectedPath_ === path)
486 return this.currentSelectedTests_;
487 this.sendListTestsRequest(path);
488 return null;
489 }, 438 },
490 439
491 getCurrentSelectedPath: function() { 440 getCurrentSelectedPath: function() {
492 return this.currentSelectedPath_; 441 return this.currentSelectedPath_;
493 }, 442 },
494 443
495 getCurrentUnselected: function() { 444 getCurrentUnselected: function() {
496 return this.currentUnselectedTests_; 445 return this.currentUnselectedTests_;
497 }, 446 },
498 447
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 * Converts a link in markdown format to a HTML link (anchor elements). 525 * Converts a link in markdown format to a HTML link (anchor elements).
577 * @param {string} text A link in markdown format. 526 * @param {string} text A link in markdown format.
578 * @return {string} A hyperlink string. 527 * @return {string} A hyperlink string.
579 */ 528 */
580 convertMarkdownLinks: function(text) { 529 convertMarkdownLinks: function(text) {
581 return text.replace(/\[(.+?)\]\((.+?)\)/g, '<a href="$2">$1</a>'); 530 return text.replace(/\[(.+?)\]\((.+?)\)/g, '<a href="$2">$1</a>');
582 } 531 }
583 }); 532 });
584 </script> 533 </script>
585 </dom-module> 534 </dom-module>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698