• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 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';
16
17import {showModal} from '../../widgets/modal';
18import {ArgumentPopup} from '../pivot_table_argument_popup';
19
20export class AttributeModalHolder {
21  typedArgument = '';
22
23  callback: (arg: string) => void;
24
25  constructor(callback: (arg: string) => void) {
26    this.callback = callback;
27  }
28
29  start() {
30    showModal({
31      title: 'Enter argument name',
32      content: () => this.renderModalContents(),
33      buttons: [
34        {
35          text: 'Add',
36          action: () => {
37            this.callback(this.typedArgument);
38            this.typedArgument = '';
39          },
40        },
41      ],
42    });
43  }
44
45  private renderModalContents() {
46    return m(ArgumentPopup, {
47      onArgumentChange: (arg) => {
48        this.typedArgument = arg;
49      },
50    });
51  }
52}
53