blob: 8876402dbf575d1cdc3383edf6a84d5cce404d3d [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4import page from 'page';
5import {ChopsChoiceButtons} from
6 'elements/chops/chops-choice-buttons/chops-choice-buttons.js';
7import {urlWithNewParams} from 'shared/helpers.js';
8
9/**
10 * Component for showing the chips to switch between List, Grid, and Chart modes
11 * on the Monorail issue list page.
12 * @extends {ChopsChoiceButtons}
13 */
14export class MrModeSelector extends ChopsChoiceButtons {
15 /** @override */
16 static get properties() {
17 return {
18 ...ChopsChoiceButtons.properties,
19 queryParams: {type: Object},
20 projectName: {type: String},
21 };
22 }
23
24 /** @override */
25 constructor() {
26 super();
27
28 this.queryParams = {};
29 this.projectName = '';
30
31 this._page = page;
32 };
33
34 /** @override */
35 update(changedProperties) {
36 if (changedProperties.has('queryParams') ||
37 changedProperties.has('projectName')) {
38 this.options = [
39 {text: 'List', value: 'list', url: this._newListViewPath()},
40 {text: 'Grid', value: 'grid', url: this._newListViewPath('grid')},
41 {text: 'Chart', value: 'chart', url: this._newListViewPath('chart')},
42 ];
43 }
44 super.update(changedProperties);
45 }
46
47 _newListViewPath(mode) {
48 const basePath = `/p/${this.projectName}/issues/list`;
49 const deletedParams = mode ? undefined : ['mode'];
50 return urlWithNewParams(basePath, this.queryParams, {mode}, deletedParams);
51 }
52};
53
54customElements.define('mr-mode-selector', MrModeSelector);