All files / modules/10-common/components/DelegateSelectionLogs DelegateSelectionLogsTable.tsx

100% Statements 17/17
66.67% Branches 4/6
100% Functions 4/4
100% Lines 17/17

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              38x   38x 38x 38x 38x   38x   38x 6x 6x                   38x 6x 6x                                   38x     2x   2x 2x                                     2x            
/*
 * 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 React from 'react'
import type { Column, CellProps, Renderer } from 'react-table'
import { Layout, Text, Card, TableV2 } from '@wings-software/uicore'
import { Color, FontVariation } from '@harness/design-system'
import { formatDatetoLocale } from '@common/utils/dateUtils'
import { String, useStrings } from 'framework/strings'
import type { DelegateSelectionLogParams } from 'services/portal'
import css from './DelegateSelectionLogs.module.scss'
 
const RenderConclusion: Renderer<CellProps<DelegateSelectionLogParams>> = ({ row }) => {
  const rowdata = row.original
  return (
    <Text
      rightIconProps={{ color: Color.GREEN_500 }}
      rightIcon={rowdata.conclusion === 'Selected' ? 'tick' : undefined}
    >
      {rowdata.conclusion}
    </Text>
  )
}
 
const RenderMessage: Renderer<CellProps<DelegateSelectionLogParams>> = ({ row }): JSX.Element => {
  const rowdata = row.original
  return (
    <Layout.Vertical spacing="xsmall" padding="medium" style={{ paddingLeft: 0 }} data-testid={rowdata.message}>
      <Text color={Color.GREY_800}>{rowdata.message}</Text>
      <Text lineClamp={1} color={Color.GREY_400} font={FontVariation.SMALL}>
        {rowdata.eventTimestamp ? (
          <String stringID="loggedAt" useRichText vars={{ time: formatDatetoLocale(rowdata.eventTimestamp) }} />
        ) : (
          '-'
        )}
      </Text>
    </Layout.Vertical>
  )
}
 
interface DelegateSelectionLogsTableProps {
  selectionLogs?: DelegateSelectionLogParams[]
}
 
export default function DelegateSelectionLogsTable({
  selectionLogs
}: DelegateSelectionLogsTableProps): React.ReactElement {
  const { getString } = useStrings()
 
  const columns: Column<DelegateSelectionLogParams>[] = React.useMemo(
    () => [
      {
        accessor: 'conclusion',
        width: '20%',
        Header: getString('assessment').toUpperCase(),
        Cell: RenderConclusion,
        disableSortBy: true
      },
      {
        accessor: 'message',
        width: '80%',
        Cell: RenderMessage,
        Header: getString('details').toUpperCase(),
        disableSortBy: true
      }
    ],
    [getString]
  )
 
  return (
    <Card className={css.card}>
      <TableV2<DelegateSelectionLogParams> columns={columns} data={selectionLogs || []} />
    </Card>
  )
}