blob: 1265e489c6ec3ad6d7ae8b5aabab87712a9c688b [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2019 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// 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';
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01007import {urlWithNewParams, generateProjectIssueURL} from 'shared/helpers.js';
Copybara854996b2021-09-07 19:36:02 +00008
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) {
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010048 const basePath = generateProjectIssueURL(this.projectName, '/list',{});
Copybara854996b2021-09-07 19:36:02 +000049 const deletedParams = mode ? undefined : ['mode'];
50 return urlWithNewParams(basePath, this.queryParams, {mode}, deletedParams);
51 }
52};
53
54customElements.define('mr-mode-selector', MrModeSelector);