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#208: Renaming any "NamedElement" on the DMN Editor should update all references to the old name #2760

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 @@ -27,12 +27,12 @@ import {
boxedExpressionEditorI18nDefaults,
} from "./i18n";
import { ExpressionDefinitionRoot } from "./expressions/ExpressionDefinitionRoot/ExpressionDefinitionRoot";
import { BoxedExpressionEditorContextProvider } from "./BoxedExpressionEditorContext";
import { FeelVariables } from "@kie-tools/dmn-feel-antlr4-parser";
import { BoxedExpressionEditorContextProvider, OnExpressionChange } from "./BoxedExpressionEditorContext";
import { FeelIdentifiers } from "@kie-tools/dmn-feel-antlr4-parser";
import "./base-no-reset-wrapped.css";
import "./@types/react-table";

export type OnRequestFeelVariables = () => FeelVariables;
export type OnRequestFeelIdentifiers = () => FeelIdentifiers;

export interface BoxedExpressionEditorProps {
/** The API methods which BoxedExpressionEditor component can use to dialog with GWT layer. Although the GWT layer is deprecated, and the new DMN Editor does not have GWT, some methods here are still necessary. */
Expand All @@ -46,7 +46,7 @@ export interface BoxedExpressionEditorProps {
/** The boxed expression itself */
expression: Normalized<BoxedExpression> | undefined;
/** Called every time something changes on the expression */
onExpressionChange: React.Dispatch<React.SetStateAction<Normalized<BoxedExpression> | undefined>>;
onExpressionChange: OnExpressionChange;
/** KIE Extension to represent IDs of individual columns or expressions */
widthsById: Map<string, number[]>;
/** Called every time a width changes on the expression */
Expand All @@ -61,8 +61,8 @@ export interface BoxedExpressionEditorProps {
pmmlDocuments?: PmmlDocument[];
/** The containing HTMLElement which is scrollable */
scrollableParentRef: React.RefObject<HTMLElement>;
/** Parsed variables used for syntax coloring and auto-complete */
onRequestFeelVariables?: OnRequestFeelVariables;
/** Parsed identifiers used for syntax coloring and auto-complete */
onRequestFeelIdentifiers?: OnRequestFeelIdentifiers;
/** Hide DMN 1.4 boxed expressions */
hideDmn14BoxedExpressions?: boolean;
}
Expand All @@ -79,7 +79,7 @@ export function BoxedExpressionEditor({
isResetSupportedOnRootExpression,
scrollableParentRef,
pmmlDocuments,
onRequestFeelVariables,
onRequestFeelIdentifiers,
widthsById,
onWidthsChange,
hideDmn14BoxedExpressions,
Expand All @@ -103,7 +103,7 @@ export function BoxedExpressionEditor({
isReadOnly={isReadOnly}
dataTypes={dataTypes}
pmmlDocuments={pmmlDocuments}
onRequestFeelVariables={onRequestFeelVariables}
onRequestFeelIdentifiers={onRequestFeelIdentifiers}
widthsById={widthsById}
hideDmn14BoxedExpressions={hideDmn14BoxedExpressions}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import * as React from "react";
import { useContext, useMemo, useRef, useState } from "react";
import { BeeGwtService, BoxedExpression, DmnDataType, Normalized, PmmlDocument } from "./api";
import { BoxedExpressionEditorProps, OnRequestFeelVariables } from "./BoxedExpressionEditor";
import { BeeGwtService, BoxedExpression, DmnDataType, ExpressionChangedArgs, Normalized, PmmlDocument } from "./api";
import { BoxedExpressionEditorProps, OnRequestFeelIdentifiers } from "./BoxedExpressionEditor";
import "./BoxedExpressionEditorContext.css";

export interface BoxedExpressionEditorContextType {
Expand All @@ -39,13 +39,13 @@ export interface BoxedExpressionEditorContextType {
currentlyOpenContextMenu: string | undefined;
setCurrentlyOpenContextMenu: React.Dispatch<React.SetStateAction<string | undefined>>;

onRequestFeelVariables?: OnRequestFeelVariables;
onRequestFeelIdentifiers?: OnRequestFeelIdentifiers;
widthsById: Map<string, number[]>;
hideDmn14BoxedExpressions?: boolean;
}

export interface BoxedExpressionEditorDispatchContextType {
setExpression: React.Dispatch<React.SetStateAction<Normalized<BoxedExpression>>>;
setExpression: OnExpressionChange;
setWidthsById: (mutation: ({ newMap }: { newMap: Map<string, number[]> }) => void) => void;
}

Expand Down Expand Up @@ -75,7 +75,7 @@ export function BoxedExpressionEditorContextProvider({
children,
pmmlDocuments,
scrollableParentRef,
onRequestFeelVariables,
onRequestFeelIdentifiers,
widthsById,
hideDmn14BoxedExpressions,
}: React.PropsWithChildren<BoxedExpressionEditorProps>) {
Expand Down Expand Up @@ -118,7 +118,7 @@ export function BoxedExpressionEditorContextProvider({
//state // FIXME: Move to a separate context (https://github.com/apache/incubator-kie-issues/issues/168)
currentlyOpenContextMenu,
setCurrentlyOpenContextMenu,
onRequestFeelVariables,
onRequestFeelIdentifiers,
widthsById,
hideDmn14BoxedExpressions,
}}
Expand All @@ -134,6 +134,12 @@ export function BoxedExpressionEditorContextProvider({

export type OnSetExpression = (args: {
getNewExpression: (prev: Normalized<BoxedExpression> | undefined) => Normalized<BoxedExpression> | undefined;
expressionChangedArgs: ExpressionChangedArgs;
}) => void;

export type OnExpressionChange = (args: {
setExpressionAction: React.SetStateAction<Normalized<BoxedExpression> | undefined>;
expressionChangedArgs: ExpressionChangedArgs;
}) => void;

export function NestedExpressionDispatchContextProvider({
Expand All @@ -145,12 +151,14 @@ export function NestedExpressionDispatchContextProvider({
const { setWidthsById } = useBoxedExpressionEditorDispatch();
const nestedExpressionDispatch = useMemo<BoxedExpressionEditorDispatchContextType>(() => {
return {
setExpression: (newExpressionAction: React.SetStateAction<Normalized<BoxedExpression>>) => {
setExpression: (OnExpressionChange) => {
function getNewExpression(prev: Normalized<BoxedExpression>) {
return typeof newExpressionAction === "function" ? newExpressionAction(prev) : newExpressionAction;
return typeof OnExpressionChange.setExpressionAction === "function"
? (OnExpressionChange.setExpressionAction(prev)! as Normalized<BoxedExpression>)
: OnExpressionChange.setExpressionAction;
}

onSetExpression({ getNewExpression });
onSetExpression({ getNewExpression, expressionChangedArgs: OnExpressionChange.expressionChangedArgs });
},
setWidthsById,
};
Expand Down
116 changes: 116 additions & 0 deletions packages/boxed-expression-component/src/api/ExpressionChange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export type ExpressionChangedArgs =
| ({
action:
| Action.ExpressionReset
| Action.ExpressionCreated
| Action.ExpressionPastedFromClipboard
| Action.DecisionTableCellsUpdated
| Action.DecisionTableHitPolicyChanged
| Action.DecisionTableBuiltInAggregatorChanged
| Action.FunctionParameterAdded
| Action.FunctionParameterTypeChanged
| Action.FunctionParameterRemoved
| Action.IteratorVariableDefined
| Action.RelationCellsUpdated
| Action.InvocationParametersChanged
| Action.ColumnChanged;
} & {})
| ({ action: Action.RowsAdded } & RowsAddedArgs)
| ({ action: Action.RowDuplicated } & RowDuplicatedArgs)
| ({ action: Action.ColumnAdded } & ColumnsAddedArgs)
| ({ action: Action.RowRemoved } & RowRemovedArgs)
| ({ action: Action.RowReset } & RowResetArgs)
| ({ action: Action.ColumnRemoved } & ColumnRemovedArgs)
| ({ action: Action.LiteralTextExpressionChanged } & LiteralTextExpressionChangedArgs)
| ({ action: Action.FunctionKindChanged } & FunctionKindChangedArgs)
| ({ action: Action.VariableChanged } & VariableChangedArgs);

export type VariableChangedProperty = {
from: string | undefined;
to: string | undefined;
};

export type VariableChangedArgs = {
typeChange?: VariableChangedProperty | undefined;
nameChange?: VariableChangedProperty | undefined;
variableUuid: string;
};

export interface ColumnsAddedArgs {
columnIndex: number;
columnCount: number;
}

export interface RowsAddedArgs {
rowIndex: number;
rowsCount: number;
}

export interface RowDuplicatedArgs {
rowIndex: number;
}

export interface RowRemovedArgs {
rowIndex: number;
}
export interface RowResetArgs {
rowIndex: number;
}

export interface ColumnRemovedArgs {
columnIndex: number;
}

export interface LiteralTextExpressionChangedArgs {
from: string;
to: string;
}

export interface FunctionKindChangedArgs {
from: string;
to: string;
}

export enum Action {
ExpressionReset,
ExpressionCreated,
ExpressionPastedFromClipboard,
RowsAdded,
RowRemoved,
RowReset,
RowDuplicated,
ColumnAdded,
ColumnRemoved,
ColumnChanged,
VariableChanged,
LiteralTextExpressionChanged,
DecisionTableCellsUpdated,
DecisionTableHitPolicyChanged,
DecisionTableBuiltInAggregatorChanged,
FunctionKindChanged,
FunctionParameterAdded,
FunctionParameterTypeChanged,
FunctionParameterRemoved,
RelationCellsUpdated,
InvocationParametersChanged,
IteratorVariableDefined,
}
1 change: 1 addition & 0 deletions packages/boxed-expression-component/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from "./DmnBuiltInDataType";
export * from "./DmnDataType";
export * from "./BoxedExpression";
export * from "./BeeTable";
export * from "./ExpressionChange";
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,18 @@ export const PopoverMenu = React.forwardRef(
if (event instanceof KeyboardEvent && NavigationKeysUtils.isEsc(event.key)) {
onCancel(event);
} else {
onHide();
hideFunction?.();
}
},
[onCancel]
);

const onHideCallback: PopoverProps["onHide"] = useCallback(
(tip): void => {
onHide();
setCurrentlyOpenContextMenu(undefined);
hideFunction?.();
},
[onCancel, onHide, setCurrentlyOpenContextMenu]
[onHide, setCurrentlyOpenContextMenu]
);

useImperativeHandle(
Expand Down Expand Up @@ -165,7 +170,7 @@ export const PopoverMenu = React.forwardRef(
bodyContent={body}
isVisible={isPopoverVisible}
onShown={onPopoverShown}
onHide={shouldClose}
onHide={onHideCallback}
shouldClose={shouldClose}
shouldOpen={shouldOpen}
flipBehavior={["bottom-start", "bottom", "bottom-end", "right-start", "left-start", "right-end", "left-end"]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
import { DMN15__tInformationItem } from "@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/ts-gen/types";
import * as React from "react";
import { useCallback, useEffect, useMemo } from "react";
import { BeeTableCellProps, BoxedExpression, DmnBuiltInDataType, Normalized } from "../api";
import {
Action,
BeeTableCellProps,
BoxedExpression,
DmnBuiltInDataType,
ExpressionChangedArgs,
Normalized,
VariableChangedArgs,
} from "../api";
import { useCellWidthToFitDataRef } from "../resizing/BeeTableCellWidthToFitDataContext";
import { getCanvasFont, getTextWidth } from "../resizing/WidthsToFitData";
import { useBeeTableSelectableCellRef } from "../selection/BeeTableSelectionContext";
Expand All @@ -37,7 +45,11 @@ export interface ExpressionWithVariable {
variable: Normalized<DMN15__tInformationItem>;
}

export type OnExpressionWithVariableUpdated = (index: number, { expression, variable }: ExpressionWithVariable) => void;
export type OnExpressionWithVariableUpdated = (
index: number,
{ expression, variable }: ExpressionWithVariable,
variableChangedArgs: VariableChangedArgs
) => void;

export const ExpressionVariableCell: React.FunctionComponent<
BeeTableCellProps<ExpressionWithVariable & { index: number }> & {
Expand All @@ -50,21 +62,44 @@ export const ExpressionVariableCell: React.FunctionComponent<

const onVariableUpdated = useCallback<OnExpressionVariableUpdated>(
({ name = DEFAULT_EXPRESSION_VARIABLE_NAME, typeRef = undefined }) => {
onExpressionWithVariableUpdated(index, {
// `expression` and `variable` must always have the same `typeRef` and `name/label`, as those are dictated by `variable`.
expression: expression
? {
...expression,
"@_label": name,
"@_typeRef": typeRef,
}
: undefined!, // SPEC DISCREPANCY
variable: {
...variable,
"@_name": name,
"@_typeRef": typeRef,
const variableChangedArgs: ExpressionChangedArgs = {
action: Action.VariableChanged,
variableUuid: variable["@_id"],
typeChange:
variable["@_typeRef"] !== typeRef
? {
from: variable["@_typeRef"],
to: typeRef,
}
: undefined,
nameChange:
variable["@_name"] !== name
? {
from: variable["@_name"],
to: name,
}
: undefined,
};

onExpressionWithVariableUpdated(
index,
{
// `expression` and `variable` must always have the same `typeRef` and `name/label`, as those are dictated by `variable`.
expression: expression
? {
...expression,
"@_label": name,
"@_typeRef": typeRef,
}
: undefined!, // SPEC DISCREPANCY
variable: {
...variable,
"@_name": name,
"@_typeRef": typeRef,
},
},
});
variableChangedArgs
);
},
[onExpressionWithVariableUpdated, index, expression, variable]
);
Expand Down Expand Up @@ -144,6 +179,7 @@ export const ExpressionVariableCell: React.FunctionComponent<
selectedExpressionName={variable["@_name"]}
selectedDataType={variable["@_typeRef"]}
onVariableUpdated={onVariableUpdated}
variableUuid={variable["@_id"]}
>
{cellContent}
</ExpressionVariableMenu>
Expand Down
Loading
Loading