All files / modules/70-pipeline/components/LogsContent/LogsState types.ts

100% Statements 11/11
100% Branches 2/2
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169                                    35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x                                                                                                                                                                                                                                                                                        
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import type { ReactNode } from 'react'
import type { ExecutionNode } from 'services/pipeline-ng'
 
/**
 * different statues for loading of log data
 */
export type UnitLoadingStatus = 'SUCCESS' | 'FAILURE' | 'RUNNING' | 'NOT_STARTED' | 'LOADING' | 'QUEUED'
 
/**
 * Actions for reducder
 */
export enum ActionType {
  CreateSections = 'CreateSections',
  FetchSectionData = 'FetchSectionData',
  FetchingSectionData = 'FetchingSectionData',
  UpdateSectionData = 'UpdateSectionData',
  ToggleSection = 'ToggleSection',
  ResetSection = 'ResetSection',
  Search = 'Search',
  ResetSearch = 'ResetSearch',
  GoToNextSearchResult = 'GoToNextSearchResult',
  GoToPrevSearchResult = 'GoToPrevSearchResult'
}
 
/**
 * Search related metadata
 */
export interface SearchData {
  /**
   * Text being searched for
   */
  text: string
  /**
   * active index for current highlighted search result
   */
  currentIndex: number
  /**
   * List of all the line numbers in which result is found
   */
  linesWithResults: number[]
}
 
/**
 * Keys in the json from server
 */
export type TextKeys = 'level' | 'out' | 'time'
 
/**
 *
 */
export interface LogLineData {
  /**
   * Text for the line
   */
  text: Partial<Record<TextKeys, string>>
  /**
   * Indices of the search result with in the current line.
   * This will be a continous list
   *
   * If this values is `[3, 4]`, it means the result number 3 and 4 will be found in this line
   */
  searchIndices?: Partial<Record<TextKeys, number[]>>
}
 
/**
 * Data for a log unit/section
 */
export interface LogSectionData {
  /**
   * Title to shown on accordion
   */
  title: ReactNode
  /**
   * The log data
   */
  data: LogLineData[]
  /**
   * Start time for the section
   */
  startTime?: number
  /**
   * End time for the section
   */
  endTime?: number
  /**
   * Status of Unit. Used to show icons on the UI.
   * This will only take subset of the statues
   */
  status: UnitLoadingStatus
  /**
   * Flag for accordion open?
   */
  isOpen?: boolean
  /**
   * Data source for the logs
   */
  dataSource: 'blob' | 'stream'
  /**
   * Status of data loading
   */
  unitStatus: UnitLoadingStatus
  /**
   * Flag for if the unit/section has been toggled manually by the user
   */
  manuallyToggled?: boolean
}
 
export interface CreateSectionsPayload {
  node: ExecutionNode
  getSectionName(index: number): string
  selectedStep: string
  selectedStage: string
}
 
export interface UpdateSectionsPayload {
  id: string
  data: string
}
 
export interface Action<T extends ActionType> {
  type: T
  payload: T extends ActionType.CreateSections
    ? CreateSectionsPayload
    : T extends ActionType.UpdateSectionData
    ? UpdateSectionsPayload
    : string
}
 
export interface State {
  /**
   * List of unit/section names
   */
  units: string[]
  /**
   * List of logKeys which are used in APIs
   * These will have 1:1 mapping with units
   */
  logKeys: string[]
  /**
   * Map of logKeys to its data.
   */
  dataMap: Record<string, LogSectionData>
  /**
   * Current selected step
   */
  selectedStep: string
  /**
   * Current selected stage
   */
  selectedStage: string
  /**
   * Search related data
   */
  searchData: SearchData
}
 
export interface ProgressMapValue {
  status: UnitLoadingStatus
  startTime?: number
  endTime?: number
}