Skip to content

Commit

Permalink
Refactor variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
jomarko committed Oct 30, 2024
1 parent 925f925 commit 22270b1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
2 changes: 2 additions & 0 deletions packages/boxed-expression-component/src/api/BeeTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export interface BeeTableProps<R extends object> {
shouldShowColumnsInlineControls: boolean;
resizerStopBehavior: ResizerStopBehavior;
lastColumnMinWidth?: number;
/** Index of the column, where the evaluation hits count should be displayed. If not set, evaluation hits count number is not shown. */
evaluationHitsCountColumnIndex?: number;
/** Method should return true for table rows, that can display evaluation hits count, false otherwise. If not set, BeeTableBody defaults to false. */
getEvaluationHitsCountSupportedByRow?: (row: ReactTable.Row<R>) => boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
border: 0;
}

.expression-container .table-component tr.evaluation-highlights-row-overlay > td:first-child::before {
.expression-container .table-component tr.evaluation-hits-count-row-overlay > td:first-child::before {
content: "";
position: absolute;
background-color: rgb(215, 201, 255, 0.5);
Expand All @@ -213,7 +213,7 @@
height: 100%;
}

.evaluation-hit-count-overlay-non-colored::before {
.evaluation-hits-count-badge-non-colored::before {
content: attr(data-evaluation-hits-count);
font-size: 0.8em;
text-align: left;
Expand All @@ -228,7 +228,7 @@
padding-left: 0.2em;
}

.evaluation-hit-count-overlay-colored::before {
.evaluation-hits-count-badge-colored::before {
content: attr(data-evaluation-hits-count);
font-size: 0.8em;
text-align: left;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ export function BeeTableInternal<R extends object>({
lastColumnMinWidth={lastColumnMinWidth}
isReadOnly={isReadOnly}
evaluationHitsCountColumnIndex={evaluationHitsCountColumnIndex}
getEvalationHitsCountSupportedByRow={getEvaluationHitsCountSupportedByRow}
getEvaluationHitsCountSupportedByRow={getEvaluationHitsCountSupportedByRow}
/>
</table>
<BeeTableContextMenuHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export interface BeeTableBodyProps<R extends object> {
rowWrapper?: React.FunctionComponent<React.PropsWithChildren<{ row: R; rowIndex: number }>>;

isReadOnly: boolean;
/** See BeeTable.ts */
evaluationHitsCountColumnIndex?: number;
getEvalationHitsCountSupportedByRow?: (row: ReactTable.Row<R>) => boolean;
/** See BeeTable.ts */
getEvaluationHitsCountSupportedByRow?: (row: ReactTable.Row<R>) => boolean;
}

export function BeeTableBody<R extends object>({
Expand All @@ -76,7 +78,7 @@ export function BeeTableBody<R extends object>({
rowWrapper,
isReadOnly,
evaluationHitsCountColumnIndex,
getEvalationHitsCountSupportedByRow,
getEvaluationHitsCountSupportedByRow,
}: BeeTableBodyProps<R>) {
// const { evaluationHitsCountPerId } = useBoxedExpressionEditor();
const evaluationHitsCountPerId: Map<string, number> = new Map();
Expand All @@ -94,20 +96,19 @@ export function BeeTableBody<R extends object>({
reactTableInstance.prepareRow(row);

const rowKey = getRowKey(row);
const isEvalationHitsCountSupportedByRow: boolean = getEvalationHitsCountSupportedByRow?.(row) ?? false;
const rowHitCount = evaluationHitsCountPerId ? evaluationHitsCountPerId?.get(rowKey) ?? 0 : undefined;
const rowClassName =
rowHitCount && isEvalationHitsCountSupportedByRow
? rowKey + (rowHitCount > 0 ? " evaluation-highlights-row-overlay" : "")
: undefined;
const isEvalationHitsCountSupportedByRow: boolean = getEvaluationHitsCountSupportedByRow?.(row) ?? false;
const rowEvaluationHitsCount = evaluationHitsCountPerId ? evaluationHitsCountPerId?.get(rowKey) ?? 0 : undefined;
const canDisplayEvaluationHitsCountRowOverlay =
rowEvaluationHitsCount !== undefined && isEvalationHitsCountSupportedByRow === true;
const rowClassName = canDisplayEvaluationHitsCountRowOverlay
? rowKey + (rowEvaluationHitsCount > 0 ? " evaluation-hits-count-row-overlay" : "")
: rowKey;
const renderTr = () => (
<tr className={rowClassName} key={rowKey} data-testid={`kie-tools--bee--expression-row-${rowIndex}`}>
{row.cells.map((cell, cellIndex) => {
const columnKey = getColumnKey(reactTableInstance.allColumns[cellIndex]);
const shouldDisplayEvaluationHitsCount =
rowHitCount !== undefined &&
cellIndex === evaluationHitsCountColumnIndex &&
isEvalationHitsCountSupportedByRow;
const canDisplayEvaluationHitsCountBadge =
canDisplayEvaluationHitsCountRowOverlay && cellIndex === evaluationHitsCountColumnIndex;
return (
<React.Fragment key={columnKey}>
{((cell.column.isRowIndexColumn && shouldRenderRowIndexColumn) || !cell.column.isRowIndexColumn) && (
Expand All @@ -131,8 +132,8 @@ export function BeeTableBody<R extends object>({
cellIndex === reactTableInstance.allColumns.length - 1 ? lastColumnMinWidth : undefined
}
isReadOnly={isReadOnly}
shouldDisplayEvaluationHitsCount={shouldDisplayEvaluationHitsCount}
evaluationHitsCount={rowHitCount}
canDisplayEvaluationHitsCountBadge={canDisplayEvaluationHitsCountBadge}
evaluationHitsCount={rowEvaluationHitsCount}
/>
)}
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export interface BeeTableTdProps<R extends object> {
onDataCellClick?: (columnID: string) => void;
onDataCellKeyUp?: (columnID: string) => void;
isReadOnly: boolean;
shouldDisplayEvaluationHitsCount?: boolean;
/** True means the table cell can display evaluation hits count. False means evaluation hits count is not displayed in the table cell. */
canDisplayEvaluationHitsCountBadge?: boolean;
/** Actuall evaluation hits count number that will be displayed in the table cell if 'canDisplayEvaluationHitsCountBadge' is set to true. */
evaluationHitsCount?: number;
}

Expand All @@ -75,7 +77,7 @@ export function BeeTableTd<R extends object>({
onDataCellClick,
onDataCellKeyUp,
isReadOnly,
shouldDisplayEvaluationHitsCount,
canDisplayEvaluationHitsCountBadge,
evaluationHitsCount,
}: BeeTableTdProps<R>) {
const [isResizing, setResizing] = useState(false);
Expand Down Expand Up @@ -229,10 +231,10 @@ export function BeeTableTd<R extends object>({
return onDataCellKeyUp?.(column.id);
}, [column.id, onDataCellKeyUp]);

const evaluationHitsCountCss = shouldDisplayEvaluationHitsCount
const evaluationHitsCountBadgeClassName = canDisplayEvaluationHitsCountBadge
? (evaluationHitsCount ?? 0) > 0
? "evaluation-hit-count-overlay-colored"
: "evaluation-hit-count-overlay-non-colored"
? "evaluation-hits-count-badge-colored"
: "evaluation-hits-count-badge-non-colored"
: "";

return (
Expand All @@ -256,11 +258,11 @@ export function BeeTableTd<R extends object>({
}}
>
{column.isRowIndexColumn ? (
<div className={evaluationHitsCountCss} data-evaluation-hits-count={evaluationHitsCount}>
<div className={evaluationHitsCountBadgeClassName} data-evaluation-hits-count={evaluationHitsCount}>
{rowIndexLabel}
</div>
) : (
<div className={evaluationHitsCountCss} data-evaluation-hits-count={evaluationHitsCount}>
<div className={evaluationHitsCountBadgeClassName} data-evaluation-hits-count={evaluationHitsCount}>
{tdContent}

{!isReadOnly && shouldRenderResizer && (
Expand Down

0 comments on commit 22270b1

Please sign in to comment.