Skip to content

Commit

Permalink
feat: add sort direction state to table cell testID (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChitlangeSahas authored Oct 19, 2021
1 parent 8982258 commit d6425a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion giraffe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@influxdata/giraffe",
"version": "2.18.7",
"version": "2.18.8",
"main": "dist/index.js",
"module": "src/index.js",
"license": "MIT",
Expand Down
22 changes: 21 additions & 1 deletion giraffe/src/components/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,26 @@ const getTimeFieldIndex = (resolvedRenamableFields): number => {
return timeIndex - hiddenBeforeTime
}

const getCellIdString = (props: Props): string => {
const {isVerticalTimeAxis, rowIndex, columnIndex, sortOptions, data} = props

if (
isFieldName(isVerticalTimeAxis, rowIndex, columnIndex) &&
isSorted(sortOptions, data) &&
isAscending(sortOptions)
) {
return 'table-graph-cell__sort-asc'
} else if (
isFieldName(isVerticalTimeAxis, rowIndex, columnIndex) &&
isSorted(sortOptions, data) &&
!isAscending(sortOptions)
) {
return 'table-graph-cell__sort-desc'
} else {
return 'table-graph-cell'
}
}

export const TableCell: FunctionComponent<Props> = (props: Props) => {
const {
data,
Expand All @@ -310,7 +330,7 @@ export const TableCell: FunctionComponent<Props> = (props: Props) => {
onClick={handleClick}
data-column-index={columnIndex}
data-row-index={rowIndex}
data-testid={`${data}-table-header`}
data-testid={`${data}-table-header ${getCellIdString(props)}`}
onMouseOver={onHover}
title={getContents(props)}
>
Expand Down

0 comments on commit d6425a9

Please sign in to comment.