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 {TrackNode, TrackNodeArgs, Workspace} from './workspace'; 16 17/** 18 * Gets or creates a group for user interaction 19 * 20 * @param workspace - The workspace on which to create the group. 21 */ 22export function getOrCreateUserInteractionGroup( 23 workspace: Workspace, 24): TrackNode { 25 return getOrCreateGroup(workspace, 'user_interaction', { 26 title: 'User Interaction', 27 collapsed: false, // Expand this by default 28 isSummary: true, 29 }); 30} 31 32// Internal utility function to avoid duplicating the logic to get or create a 33// group by ID. 34function getOrCreateGroup( 35 workspace: Workspace, 36 id: string, 37 args?: Omit<Partial<TrackNodeArgs>, 'id'>, 38): TrackNode { 39 const group = workspace.getTrackById(id); 40 if (group) { 41 return group; 42 } else { 43 const group = new TrackNode({id, ...args}); 44 workspace.addChildInOrder(group); 45 return group; 46 } 47} 48