Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kie-issues#1547: DMN Editor: Render evaluation highlights in the Boxed Expression Editor #2681

Merged
merged 26 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
19bd400
kie-issues#1547: Render evaluation highlights in the Boxed Expression…
jomarko Oct 18, 2024
713e27d
restrict ::before size
jomarko Oct 18, 2024
d99ef6a
Display evaluationHitsCount in the leading column of the DT and Condi…
jomarko Oct 21, 2024
262e4b5
Merge branch 'main' into kie-issues#1547
jomarko Oct 29, 2024
f2274d0
Adapt props to Map<string, number>
jomarko Oct 30, 2024
84a6a46
Style the first column only
jomarko Oct 30, 2024
527aad4
Prevent evaluationHitCount in 'if' row
jomarko Oct 30, 2024
925f925
Merge branch 'main' into kie-issues#1547
jomarko Oct 30, 2024
22270b1
Refactor variable names
jomarko Oct 30, 2024
b2bf4a9
Cleanup
jomarko Oct 30, 2024
d7b4635
Merge branch 'main' into kie-issues#1547
jomarko Dec 10, 2024
22996a0
Update packages/boxed-expression-component/src/BoxedExpressionEditorC…
jomarko Dec 10, 2024
0ec93a0
evaluationHitsCountPerId -> evaluationHitsCountById
jomarko Dec 10, 2024
6e4ea9b
useMemo
jomarko Dec 10, 2024
19e8b23
supportsEvaluationHitsCount
jomarko Dec 10, 2024
d52e553
inline variable
jomarko Dec 10, 2024
4312521
missing hook dependencies
jomarko Dec 10, 2024
d5194b2
fix useMemo
jomarko Dec 10, 2024
3991237
split ternary operator to multiline
jomarko Dec 10, 2024
4ca0587
remove one ternary operator
jomarko Dec 10, 2024
080f4cd
fix styling: highlight whole row
jomarko Dec 11, 2024
1fe7f31
add stories
jomarko Dec 11, 2024
156db3e
stories wrapper
jomarko Dec 12, 2024
8b20094
Merge branch 'main' into kie-issues#1547
jomarko Dec 13, 2024
f1f356e
Remove evaluationHitsCountColumnIndex
jomarko Dec 13, 2024
7ce7cdc
Fix boxedExpressionStoriesWrapper.tsx
jomarko Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface BoxedExpressionEditorProps {
isReadOnly?: boolean;
/** PMML models available to use on Boxed PMML Function */
pmmlDocuments?: PmmlDocument[];
evaluationHitsCountPerId?: Map<string, number>;
/** The containing HTMLElement which is scrollable */
scrollableParentRef: React.RefObject<HTMLElement>;
/** Parsed variables used for syntax coloring and auto-complete */
Expand All @@ -79,6 +80,7 @@ export function BoxedExpressionEditor({
isResetSupportedOnRootExpression,
scrollableParentRef,
pmmlDocuments,
evaluationHitsCountPerId,
onRequestFeelVariables,
widthsById,
onWidthsChange,
Expand All @@ -103,6 +105,7 @@ export function BoxedExpressionEditor({
isReadOnly={isReadOnly}
dataTypes={dataTypes}
pmmlDocuments={pmmlDocuments}
evaluationHitsCountPerId={evaluationHitsCountPerId}
onRequestFeelVariables={onRequestFeelVariables}
widthsById={widthsById}
hideDmn14BoxedExpressions={hideDmn14BoxedExpressions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface BoxedExpressionEditorContextType {
pmmlDocuments?: PmmlDocument[];
dataTypes: DmnDataType[];
isReadOnly?: boolean;
evaluationHitsCountPerId?: Map<string, number>;
jomarko marked this conversation as resolved.
Show resolved Hide resolved

// State
currentlyOpenContextMenu: string | undefined;
Expand Down Expand Up @@ -74,6 +75,7 @@ export function BoxedExpressionEditorContextProvider({
beeGwtService,
children,
pmmlDocuments,
evaluationHitsCountPerId,
scrollableParentRef,
onRequestFeelVariables,
widthsById,
Expand Down Expand Up @@ -114,6 +116,7 @@ export function BoxedExpressionEditorContextProvider({
dataTypes,
isReadOnly,
pmmlDocuments,
evaluationHitsCountPerId,

//state // FIXME: Move to a separate context (https://github.com/apache/incubator-kie-issues/issues/168)
currentlyOpenContextMenu,
Expand Down
1 change: 1 addition & 0 deletions packages/boxed-expression-component/src/api/BeeTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface BeeTableProps<R extends object> {
shouldShowColumnsInlineControls: boolean;
resizerStopBehavior: ResizerStopBehavior;
lastColumnMinWidth?: number;
evaluationHitsCountColumnIndex?: number;
}

/** Possible status for the visibility of the Table's Header */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ export function ConditionalExpression({
[setExpression]
);

const getRowKey = useCallback((row: ReactTable.Row<ROWTYPE>) => {
return row.original.part["@_id"];
}, []);

return (
<NestedExpressionContainerContext.Provider value={nestedExpressionContainerValue}>
<div data-testid={"kie-tools--boxed-expression-component---conditional"}>
Expand All @@ -234,6 +238,7 @@ export function ConditionalExpression({
isEditableHeader={!isReadOnly}
resizerStopBehavior={ResizerStopBehavior.SET_WIDTH_WHEN_SMALLER}
tableId={id}
getRowKey={getRowKey}
headerLevelCountForAppendingRowIndexColumn={1}
headerVisibility={headerVisibility}
cellComponentByColumnAccessor={cellComponentByColumnAccessor}
Expand All @@ -247,6 +252,7 @@ export function ConditionalExpression({
shouldRenderRowIndexColumn={false}
shouldShowRowsInlineControls={false}
shouldShowColumnsInlineControls={false}
evaluationHitsCountColumnIndex={1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 1? Could you please add a comment here? Or make it a variable with a very good name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed from the codebase

/>
</div>
</NestedExpressionContainerContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ export function DecisionTableExpression({
shouldRenderRowIndexColumn={true}
shouldShowRowsInlineControls={true}
shouldShowColumnsInlineControls={true}
evaluationHitsCountColumnIndex={0}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the 0 here, but it would be good to add a comment too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed from the codebase

// lastColumnMinWidth={lastColumnMinWidth} // FIXME: Check if this is a good strategy or not when doing https://github.com/apache/incubator-kie-issues/issues/181
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,46 @@
border: 0;
}

.expression-container .table-component tr.evaluation-highlights-row-overlay > td:first-child::before {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first-child here was my decision to use, otherwise there is problem, when then/ else branch has nested decision table, but not all decision table rules were evaluated. see:
Screenshot 2024-10-30 132337

content: "";
position: absolute;
background-color: rgb(215, 201, 255, 0.5);
left: 0;
top: 0;
width: 100%;
height: 100%;
}

.evaluation-hit-count-overlay-non-colored::before {
content: attr(data-evaluation-hits-count);
font-size: 0.8em;
text-align: left;
color: white;
background-color: var(--pf-global--palette--black-600);
position: absolute;
top: 0px;
left: 0px;
height: 40px;
width: 40px;
clip-path: polygon(0% 100%, 100% 0%, 0% 0%);
padding-left: 0.2em;
}

.evaluation-hit-count-overlay-colored::before {
content: attr(data-evaluation-hits-count);
font-size: 0.8em;
text-align: left;
color: white;
background-color: rgb(134, 106, 212);
position: absolute;
top: 0px;
left: 0px;
height: 40px;
width: 40px;
clip-path: polygon(0% 100%, 100% 0%, 0% 0%);
padding-left: 0.2em;
}

.expression-container .table-component table tbody tr td.row-index-cell-column {
padding: 1.1em 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function BeeTableInternal<R extends object>({
resizerStopBehavior,
lastColumnMinWidth,
rowWrapper,
evaluationHitsCountColumnIndex,
}: BeeTableProps<R> & {
selectionRef?: React.RefObject<BeeTableSelectionRef>;
}) {
Expand Down Expand Up @@ -657,6 +658,7 @@ export function BeeTableInternal<R extends object>({
onDataCellKeyUp={onDataCellKeyUp}
lastColumnMinWidth={lastColumnMinWidth}
isReadOnly={isReadOnly}
evaluationHitsCountColumnIndex={evaluationHitsCountColumnIndex}
/>
</table>
<BeeTableContextMenuHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { BeeTableTdForAdditionalRow } from "./BeeTableTdForAdditionalRow";
import { BeeTableTd } from "./BeeTableTd";
import { BeeTableCoordinatesContextProvider } from "../../selection/BeeTableSelectionContext";
import { ResizerStopBehavior } from "../../resizing/ResizingWidthsContext";
import { useBoxedExpressionEditor } from "../../BoxedExpressionEditorContext";

export interface BeeTableBodyProps<R extends object> {
/** Table instance */
Expand Down Expand Up @@ -55,6 +56,7 @@ export interface BeeTableBodyProps<R extends object> {
rowWrapper?: React.FunctionComponent<React.PropsWithChildren<{ row: R; rowIndex: number }>>;

isReadOnly: boolean;
evaluationHitsCountColumnIndex?: number;
}

export function BeeTableBody<R extends object>({
Expand All @@ -72,15 +74,28 @@ export function BeeTableBody<R extends object>({
lastColumnMinWidth,
rowWrapper,
isReadOnly,
evaluationHitsCountColumnIndex,
}: BeeTableBodyProps<R>) {
// const { evaluationHitsCountPerId } = useBoxedExpressionEditor();
const evaluationHitsCountPerId: Map<string, number> = new Map();
evaluationHitsCountPerId.set("_1FA12B9F-288C-42E8-B77F-BE2D3702B7B6", 10);
evaluationHitsCountPerId.set("_1FA12B9F-288C-42E8-B77F-BE2D3702B7B7", 20);

const renderRow = useCallback(
(row: ReactTable.Row<R>, rowIndex: number) => {
reactTableInstance.prepareRow(row);

const rowKey = getRowKey(row);
const rowHitCount = evaluationHitsCountPerId ? evaluationHitsCountPerId?.get(rowKey) ?? 0 : undefined;
const rowClassName = rowHitCount
? rowKey + (rowHitCount > 0 ? " evaluation-highlights-row-overlay" : "")
: undefined;
const renderTr = () => (
<tr className={rowKey} key={rowKey} data-testid={`kie-tools--bee--expression-row-${rowIndex}`}>
<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;
return (
<React.Fragment key={columnKey}>
{((cell.column.isRowIndexColumn && shouldRenderRowIndexColumn) || !cell.column.isRowIndexColumn) && (
Expand All @@ -104,6 +119,8 @@ export function BeeTableBody<R extends object>({
cellIndex === reactTableInstance.allColumns.length - 1 ? lastColumnMinWidth : undefined
}
isReadOnly={isReadOnly}
shouldDisplayEvaluationHitsCount={shouldDisplayEvaluationHitsCount}
evaluationHitsCount={rowHitCount}
/>
)}
</React.Fragment>
Expand All @@ -114,8 +131,6 @@ export function BeeTableBody<R extends object>({

const RowWrapper = rowWrapper;

const rowKey = getRowKey(row);

return (
<React.Fragment key={rowKey}>
{RowWrapper ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface BeeTableTdProps<R extends object> {
onDataCellClick?: (columnID: string) => void;
onDataCellKeyUp?: (columnID: string) => void;
isReadOnly: boolean;
shouldDisplayEvaluationHitsCount?: boolean;
evaluationHitsCount?: number;
}

export type HoverInfo =
Expand All @@ -73,6 +75,8 @@ export function BeeTableTd<R extends object>({
onDataCellClick,
onDataCellKeyUp,
isReadOnly,
shouldDisplayEvaluationHitsCount,
evaluationHitsCount,
}: BeeTableTdProps<R>) {
const [isResizing, setResizing] = useState(false);
const [hoverInfo, setHoverInfo] = useState<HoverInfo>({ isHovered: false });
Expand Down Expand Up @@ -225,6 +229,12 @@ export function BeeTableTd<R extends object>({
return onDataCellKeyUp?.(column.id);
}, [column.id, onDataCellKeyUp]);

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

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

{!isReadOnly && shouldRenderResizer && (
Expand All @@ -262,7 +274,7 @@ export function BeeTableTd<R extends object>({
setResizing={setResizing}
/>
)}
</>
</div>
)}

{!isReadOnly &&
Expand Down
Loading