All files / modules/70-pipeline/components/PipelineSteps/Steps/Common ApprovalCommons.ts

92.86% Statements 13/14
88.89% Branches 8/9
100% Functions 5/5
91.67% Lines 11/12

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                114x   114x 11x 49x       114x 43x           114x 1819x 114x   1705x     1705x    
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Free Trial 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/05/PolyForm-Free-Trial-1.0.0.txt.
 */
 
// Common helpers and types for approval forms
import { flatMap } from 'lodash-es'
 
const getEntries = function <T>(object: T, prefix = ''): Array<any> {
  return flatMap(Object.entries(object), ([k, v]: { k: string; v: any }[]) =>
    Object(v) === v ? getEntries(v, `${prefix}${k}.`) : [[`${prefix}${k}`, v]]
  )
}
 
export function flatObject(object: Record<string, any>): Record<string, unknown> {
  return getEntries(object).reduce((o, k) => ((o[k[0]] = k[1]), o), {})
}
 
// returns if an approval form field is disabled.
// More params might be added in the future
// readonly denotes RBAC
export const isApprovalStepFieldDisabled = (readonly = false, fetching = false): boolean => {
  if (readonly) {
    return true
  }
  Iif (fetching) {
    return true
  }
  return false
}