xref: /aosp_15_r20/external/perfetto/ui/src/frontend/notes_list_editor.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1// Copyright (C) 2024 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 {Button} from '../widgets/button';
17import {Icons} from '../base/semantic_icons';
18import {TraceImplAttrs} from '../core/trace_impl';
19
20export class NotesListEditor implements m.ClassComponent<TraceImplAttrs> {
21  view({attrs}: m.CVnode<TraceImplAttrs>) {
22    const notes = attrs.trace.notes.notes;
23    if (notes.size === 0) {
24      return 'No notes found';
25    }
26
27    return m(
28      'table',
29      m(
30        'thead',
31        m(
32          'tr',
33          m('td', 'ID'),
34          m('td', 'Color'),
35          m('td', 'Type'),
36          m('td', 'Text'),
37          m('td', 'Delete'),
38        ),
39      ),
40      m(
41        'tbody',
42        Array.from(notes.entries()).map(([id, note]) => {
43          return m(
44            'tr',
45            m('td', id),
46            m('td', note.color),
47            m('td', note.noteType),
48            m('td', note.text),
49            m(
50              'td',
51              m(Button, {
52                icon: Icons.Delete,
53                onclick: () => {
54                  attrs.trace.notes.removeNote(id);
55                },
56              }),
57            ),
58          );
59        }),
60      ),
61    );
62  }
63}
64