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

Unified Diff: dashboard/dashboard/static/series_group.html

Issue 2756573004: [Dashboard] Formalize SeriesGroup (Closed)
Patch Set: JSON.parse oops 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dashboard/dashboard/static/series_group_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dashboard/dashboard/static/series_group.html
diff --git a/dashboard/dashboard/static/series_group.html b/dashboard/dashboard/static/series_group.html
new file mode 100644
index 0000000000000000000000000000000000000000..07337ded114f8f824cf9caaac8e8d635b062672e
--- /dev/null
+++ b/dashboard/dashboard/static/series_group.html
@@ -0,0 +1,109 @@
+<!DOCTYPE html>
+<!--
+Copyright 2017 The Chromium Authors. All rights reserved.
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+-->
+
+<link rel="import" href="/dashboard/static/simple_xhr.html">
+<link rel="import" href="/tracing/base/base.html">
+
+<script>
+'use strict';
+
+tr.exportTo('d', function() {
+ class SeriesGroup {
+ /**
+ * @param {string} mainPath
+ * @param {Array.<string>} selectedPaths
+ * @param {Array.<string>} unselectedPaths
+ */
+ constructor(mainPath, selectedPaths, unselectedPaths) {
+ this.mainPath_ = mainPath;
+ this.selectedPaths_ = selectedPaths;
+ this.unselectedPaths_ = unselectedPaths;
+ }
+
+ get mainPath() {
+ return this.mainPath_;
+ }
+
+ get selectedPaths() {
+ return this.selectedPaths_;
+ }
+
+ get unselectedPaths() {
+ return this.unselectedPaths_;
+ }
+ }
+
+ /**
+ * Builds a SeriesGroup instance from an element of a legacy chart state.
+ *
+ * The expected structure of the legacy chart state element is described in
+ * the docstring for listTestsRequestParams.
+ *
+ * @param {Array} element
+ */
+ SeriesGroup.fromLegacyChartStateElement = element => {
+ const mainPath = element[0];
+ const selectedParams = listTestsRequestParams(element, true);
+ const unselectedParams = listTestsRequestParams(element, false);
+ const selectedTests = simple_xhr.asPromise('/list_tests', selectedParams);
+ const unselectedTests = simple_xhr.asPromise(
+ 'list_tests', unselectedParams);
+
+ return Promise.all([selectedTests, unselectedTests]).then(
+ tests => new SeriesGroup(mainPath, ...tests));
+ };
+
+ /**
+ * Returns a dict of arguments to pass to /list_tests.
+ *
+ * The legacy chart state element should be a two-element array, where the
+ * first element is the main path, and the second element is another array.
+ * This array will either have a single element that is a magic string ('all',
+ * 'important', or 'none'), or an exact list of test paths.
+ *
+ * @param {Array} legacyChartStateElement
+ */
+ function listTestsRequestParams(legacyChartStateElement, selected) {
+ let selectedStr = '0';
+ if (selected === true) {
+ selectedStr = '1';
+ }
+
+ return {
+ type: 'test_path_dict',
+ test_path_dict: JSON.stringify(testPathDict(...legacyChartStateElement)),
+ selected: selectedStr
+ };
+ }
+
+ function testPathDict(mainPath, legacySelection) {
+ let selection = [];
+ if (legacySelection.length === 1 && legacySelection[0] === 'all') {
+ selection = 'all';
+ } else if (
+ legacySelection.length === 1 && legacySelection[0] === 'important') {
+ selection = 'core';
+ } else if (
+ legacySelection.length === 1 && legacySelection[0] === 'none') {
+ // TODO(eakuefner): Analyze existing page states to see if this is used.
+ selection = [];
+ } else {
+ selection = legacySelection;
+ }
+
+ const dict = {};
+ dict[mainPath] = selection;
+ return dict;
+ }
+
+ return {
+ SeriesGroup,
+ listTestsRequestParams
+ };
+});
+
+</script>
« no previous file with comments | « no previous file | dashboard/dashboard/static/series_group_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698