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 {SchedSqlId} from '../sql_utils/core_types'; 17import {Anchor} from '../../widgets/anchor'; 18import {Icons} from '../../base/semantic_icons'; 19import {AppImpl} from '../../core/app_impl'; 20 21interface SchedRefAttrs { 22 // The id of the referenced sched slice in the sched_slice table. 23 readonly id: SchedSqlId; 24 25 // If not present, a placeholder name will be used. 26 readonly name?: string; 27 28 // Whether clicking on the reference should change the current tab 29 // to "current selection" tab in addition to updating the selection 30 // and changing the viewport. True by default. 31 readonly switchToCurrentSelectionTab?: boolean; 32} 33 34export function goToSchedSlice(id: SchedSqlId) { 35 // TODO(primiano): the Trace object should be properly injected here. 36 AppImpl.instance.trace?.selection.selectSqlEvent('sched_slice', id, { 37 scrollToSelection: true, 38 }); 39} 40 41export class SchedRef implements m.ClassComponent<SchedRefAttrs> { 42 view(vnode: m.Vnode<SchedRefAttrs>) { 43 return m( 44 Anchor, 45 { 46 icon: Icons.UpdateSelection, 47 onclick: () => { 48 // TODO(primiano): the Trace object should be properly injected here. 49 AppImpl.instance.trace?.selection.selectSqlEvent( 50 'sched_slice', 51 vnode.attrs.id, 52 { 53 switchToCurrentSelectionTab: 54 vnode.attrs.switchToCurrentSelectionTab ?? true, 55 scrollToSelection: true, 56 }, 57 ); 58 }, 59 }, 60 vnode.attrs.name ?? `Sched ${vnode.attrs.id}`, 61 ); 62 } 63} 64