• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7//     https://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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15import { TableColumn } from './interfaces';
16import { LogViewState } from './state';
17
18export enum NodeType {
19  View = 'view',
20  Split = 'split',
21}
22
23export enum Orientation {
24  Horizontal = 'horizontal',
25  Vertical = 'vertical',
26}
27
28export interface ViewNodeOptions {
29  logViewId?: string;
30  type?: NodeType;
31  orientation?: Orientation;
32  children?: ViewNode[];
33  columnData?: TableColumn[];
34  searchText?: string;
35}
36
37/**
38 * Represents a log view node in a dynamic layout. This class can function as either
39 * a single log view or a container that manages a split between two child views.
40 *
41 * @class ViewContainer
42 * @property {string} logViewId - A unique identifier for the log view.
43 * @property {NodeType} type - Specifies whether the node is a single view (NodeType.View) or a container for split views (NodeType.Split). Defaults to NodeType.View.
44 * @property {Orientation} orientation - Defines the orientation of the split; defaults to undefined.
45 * @property {ViewNode[]} children - An array of child nodes if this is a split type; empty for single view types.
46 * @property {LogViewState} logViewState - State properties for the corresponding log view.
47 */
48export class ViewNode {
49  logViewId?: string;
50  type: NodeType;
51  orientation: Orientation | undefined;
52  children: ViewNode[];
53  logViewState?: LogViewState;
54
55  constructor(options?: ViewNodeOptions) {
56    this.type = options?.type || NodeType.View;
57    this.orientation = options?.orientation || undefined;
58    this.children = options?.children || [];
59
60    if (this.type === NodeType.View) {
61      this.logViewId = options?.logViewId || crypto.randomUUID();
62      this.logViewState = {
63        columnData: options?.columnData || [],
64        searchText: options?.searchText || '',
65      };
66    }
67  }
68}
69