Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 1 | // Copyright 2019 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | import page from 'page'; |
| 5 | import {ChopsChoiceButtons} from |
| 6 | 'elements/chops/chops-choice-buttons/chops-choice-buttons.js'; |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 7 | import {urlWithNewParams, generateProjectIssueURL} from 'shared/helpers.js'; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 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 | */ |
| 14 | export 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 48 | const basePath = generateProjectIssueURL(this.projectName, '/list',{}); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 49 | const deletedParams = mode ? undefined : ['mode']; |
| 50 | return urlWithNewParams(basePath, this.queryParams, {mode}, deletedParams); |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | customElements.define('mr-mode-selector', MrModeSelector); |