All files / modules/72-templates-library/components/TemplateStudio/TemplateContext TemplateActions.ts

97.06% Statements 33/34
100% Branches 4/4
90.91% Functions 10/11
100% Lines 25/25

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                          47x 47x 47x 47x 47x 47x 47x 47x 47x 47x     47x 47x 47x 47x     47x                                                         47x 47x 47x 47x       47x       47x 47x 47x 47x   47x                      
/*
 * 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 { GetDataError } from 'restful-react'
import type { Failure } from 'services/cd-ng'
import type { EntityGitDetails, EntityValidityDetails, NGTemplateInfoConfig } from 'services/template-ng'
import type { TemplateViewData } from '@templates-library/components/TemplateStudio/TemplateContext/TemplateReducer'
import type { YamlBuilderHandlerBinding } from '@common/interfaces/YAMLBuilderProps'
 
export enum TemplateActions {
  DBInitialize = 'DBInitialize',
  Initialize = 'Initialize',
  Fetching = 'Fetching',
  Loading = 'Loading',
  UpdateTemplateView = 'UpdateTemplateView',
  UpdateTemplate = 'UpdateTemplate',
  SetYamlHandler = 'SetYamlHandler',
  Success = 'Success',
  Error = 'Error'
}
 
export enum DrawerTypes {
  AddStep = 'AddCommand',
  TemplateVariables = 'TemplateVariables',
  TemplateInputs = 'TemplateInputs'
}
 
export const DrawerSizes: Record<DrawerTypes, React.CSSProperties['width']> = {
  [DrawerTypes.AddStep]: 700,
  [DrawerTypes.TemplateVariables]: 876,
  [DrawerTypes.TemplateInputs]: 876
}
 
export interface ActionResponse {
  error?: string
  isUpdated?: boolean
  template?: NGTemplateInfoConfig
  yamlHandler?: YamlBuilderHandlerBinding
  originalTemplate?: NGTemplateInfoConfig
  isBETemplateUpdated?: boolean
  templateView?: TemplateViewData
  stableVersion?: string
  lastPublishedVersion?: string
  versions?: string[]
  isLoading?: boolean
  gitDetails?: EntityGitDetails
  entityValidityDetails?: EntityValidityDetails
  templateYaml?: string
  templateError?: GetDataError<Failure | Error> | null
}
 
export interface ActionReturnType {
  type: TemplateActions
  response?: ActionResponse
}
 
const dbInitialized = (): ActionReturnType => ({ type: TemplateActions.DBInitialize })
const initialized = (): ActionReturnType => ({ type: TemplateActions.Initialize })
const loading = (response: ActionResponse): ActionReturnType => ({ type: TemplateActions.Loading, response })
const updateTemplateView = (response: ActionResponse): ActionReturnType => ({
  type: TemplateActions.UpdateTemplateView,
  response
})
const setYamlHandler = (response: ActionResponse): ActionReturnType => ({
  type: TemplateActions.SetYamlHandler,
  response
})
const updating = (): ActionReturnType => ({ type: TemplateActions.UpdateTemplate })
const fetching = (): ActionReturnType => ({ type: TemplateActions.Fetching })
const success = (response: ActionResponse): ActionReturnType => ({ type: TemplateActions.Success, response })
const error = (response: ActionResponse): ActionReturnType => ({ type: TemplateActions.Error, response })
 
export const TemplateContextActions = {
  dbInitialized,
  initialized,
  loading,
  updating,
  fetching,
  updateTemplateView,
  setYamlHandler,
  success,
  error
}