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 {Selection, TrackEventSelection} from './selection'; 17import {z} from 'zod'; 18 19export interface DetailsPanel { 20 render(selection: Selection): m.Children; 21 isLoading?(): boolean; 22} 23 24export interface TrackEventDetailsPanelSerializeArgs<T> { 25 // The Zod schema which will be used the parse the state in a serialized 26 // permalink JSON object. 27 readonly schema: z.ZodType<T>; 28 29 // The serializable state of the details panel. The usage of this field is 30 // as follows 31 // 1) default initialize this field in the constructor. 32 // 2) if the trace is being restored from a permalink, the UI will use 33 // `schema` to parse the serialized state and will write the result into 34 // `state`. If parsing failed or the trace is not being restored, 35 // `state` will not be touched. 36 // 3) if a permalink is requested, the UI will read the value of `state` 37 // and stash it in the permalink serialzed state. 38 // 39 // This flow has the following consequences: 40 // 1) Details panels *must* respect changes to this object between their 41 // constructor and the first call to `load()`. This is the point where 42 // the core will "inject" the permalink deserialized object 43 // if available. 44 // 2) The `state` object *must* be serializable: that is, it should be a 45 // pure Javascript object. 46 state: T; 47} 48 49export interface TrackEventDetailsPanel { 50 // Optional: Do any loading required to render the details panel in here and 51 // the core will: 52 // - Ensure that no more than one concurrent loads are enqueued at any given 53 // time in order to keep the UI snappy. 54 // - Hold off switching to this tab for up to around 50ms while this loading 55 // is going, to avoid flickering when loading is fast. 56 load?(id: TrackEventSelection): Promise<void>; 57 58 // Called every render cycle to render the details panel. Note: This function 59 // is called regardless of whether |load| has completed yet. 60 render(): m.Children; 61 62 // Optional interface to implement by details panels which want to support 63 // saving/restoring state from a permalink. 64 readonly serialization?: TrackEventDetailsPanelSerializeArgs<unknown>; 65} 66