• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2025 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import m from 'mithril';
16import {SortDirection} from '../../../../base/comparison_utils';
17import {Icons} from '../../../../base/semantic_icons';
18import {MenuItem} from '../../../../widgets/menu';
19
20export function renderColumnIcon(sorted: SortDirection | undefined) {
21  if (sorted === undefined) return Icons.ContextMenu;
22  if (sorted === 'ASC') return Icons.SortedAsc;
23  return Icons.SortedDesc;
24}
25
26export function renderSortMenuItems(
27  sorted: SortDirection | undefined,
28  sort: (direction: SortDirection | undefined) => void,
29) {
30  return [
31    sorted !== 'DESC' &&
32      m(MenuItem, {
33        label: 'Sort: highest first',
34        icon: Icons.SortedDesc,
35        onclick: () => sort('DESC'),
36      }),
37    sorted !== 'ASC' &&
38      m(MenuItem, {
39        label: 'Sort: lowest first',
40        icon: Icons.SortedAsc,
41        onclick: () => sort('ASC'),
42      }),
43    sorted !== undefined &&
44      m(MenuItem, {
45        label: 'Unsort',
46        icon: Icons.Close,
47        onclick: () => sort(undefined),
48      }),
49  ];
50}
51