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#1741: Sandbox: Add “Open Boxed Expression Editor” button in the DMN Runner table output columns #2849

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f94cd78
kie-issues#1595: Sandbox: Add "Open in Boxed Expression Editor" butto…
jomarko Nov 1, 2024
26163ca
Merge branch 'main' into kie-issues#1595
jomarko Nov 4, 2024
7a2a0b8
Merge branch 'main' into kie-issues#1595
jomarko Nov 18, 2024
f5b569e
Merge branch 'main' into kie-issues#1595
jomarko Dec 17, 2024
5c8c363
ChannelApi changes
jomarko Dec 17, 2024
b3f30df
Merge branch 'main' into kie-issues#1595
jomarko Dec 18, 2024
fffdcc5
unsupported operation
jomarko Dec 18, 2024
065a5df
Remove console.error logs
jomarko Dec 18, 2024
37a33f3
remove async and Promise
jomarko Dec 18, 2024
a52fa97
Use button
jomarko Dec 18, 2024
e838157
Introduce NewDmn* envelope and channel APIs
jomarko Dec 20, 2024
1235854
Merge branch 'main' into kie-issues#1595
jomarko Dec 20, 2024
77be060
Merge branch 'main' into kie-issues#1595
jomarko Jan 7, 2025
3cba7d8
Do not show button for legacy editor
jomarko Jan 7, 2025
000f526
documentation
jomarko Jan 7, 2025
148c40b
Add arrow button
jomarko Jan 8, 2025
de467be
handlers
jomarko Jan 9, 2025
0291e41
Merge branch 'main' into kie-issues#1741
jomarko Jan 10, 2025
7d93fa1
pass proper editor instance
jomarko Jan 10, 2025
64a5a35
output columns
jomarko Jan 10, 2025
1a230c8
all output columns
jomarko Jan 10, 2025
fbfb876
Merge branch 'main' into kie-issues#1741
jomarko Jan 13, 2025
79487ab
Merge branch 'main' into kie-issues#1741
jomarko Jan 14, 2025
18c7a92
Merge branch 'main' into kie-issues#1595
jomarko Jan 15, 2025
fdad8ba
Fix useMemo dependencies
jomarko Jan 15, 2025
3b9e17a
Merge branch 'kie-issues#1595' into kie-issues#1741
jomarko Jan 15, 2025
ae3d87c
useContext
jomarko Jan 15, 2025
94276c6
Merge branch 'main' into kie-issues#1595
jomarko Jan 16, 2025
1b1e846
Merge branch 'kie-issues#1595' into kie-issues#1741
jomarko Jan 16, 2025
81052f9
Merge branch 'main' into kie-issues#1595
jomarko Jan 21, 2025
f7e0c51
useSettings to obtain isLegacyDMNeditor
jomarko Jan 21, 2025
630525b
Merge branch 'kie-issues#1595' into kie-issues#1741
jomarko Jan 21, 2025
e1045a2
use Flex and column vertical alignment
jomarko Jan 21, 2025
f6334ed
clean up passed props
jomarko Jan 22, 2025
1f16c01
Merge branch 'kie-issues#1595' into kie-issues#1741
jomarko Jan 22, 2025
8d96afd
Merge branch 'main' into kie-issues#1741
jomarko Jan 23, 2025
f2e8379
simplify properties
jomarko Jan 23, 2025
28ce164
simplify props
jomarko Jan 23, 2025
1f488c0
Merge branch 'main' into kie-issues#1741
jomarko Jan 24, 2025
ec2e294
refactor props
jomarko Jan 24, 2025
2cc14a0
do not use decisionId in columnKey
jomarko Jan 24, 2025
fab6f0a
better callback parameters names
jomarko Jan 24, 2025
13f30d6
Merge branch 'main' into kie-issues#1741
jomarko Jan 27, 2025
ed1d20b
use position absolute top right
jomarko Jan 27, 2025
890fa9c
Merge branch 'main' into kie-issues#1741
jomarko Jan 28, 2025
2d5e162
Merge branch 'main' into kie-issues#1741
jomarko Jan 30, 2025
7bc1cdd
refactor arrow up click handler
jomarko Jan 30, 2025
4aa8e03
remove kie-tools-bee-- css prefix
jomarko Jan 30, 2025
81050d2
useContext instead of props
jomarko Jan 30, 2025
3d9c22a
remove: as unknown
jomarko Jan 30, 2025
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 @@ -50,6 +50,8 @@ declare module "react-table" {
label: string;
/** Custom Element to be rendered in place of the column label */
headerCellElement?: JSX.Element;
/** Additional Element to be rendered in the Header Cell top right corner */
headerCellElementExtension?: JSX.Element;
/** It makes this column header inline editable (with double-click) */
isInlineEditable?: boolean;
/** Column data type */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@
font-size: smaller;
color: #1b515f;
}

.kie-tools--bee--header-cell-element-extension {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to be picky here, but for this particular case, we don't use the kie-tools--bee prefix. For the boxed-expression-component we are using multiple classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sorry I used wrong prefix, as you mentioned and I noticed, we use multiple prefixes, and I am sorry, I didn't figure out from the codebase which prefix should I use in my PR.

Is header-cell-element-extension fine for you? I see we have header-cell or header-cell-info already in use.

position: absolute;
top: 0;
right: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ export function BeeTableHeader<R extends object>({
({column.dataType})
</p>
) : null}
{column.headerCellElementExtension !== undefined && (
<div className="kie-tools--bee--header-cell-element-extension">
{column.headerCellElementExtension}
</div>
)}
</div>
}
/>
Expand Down
3 changes: 1 addition & 2 deletions packages/form-dmn/src/FormDmnOutputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,8 @@ export function FormDmnOutputs({ openExecutionTab, openBoxedExpressionEditor, ..
{onOpenBoxedExpressionEditor !== undefined && (
<Button
variant={"plain"}
title={`Open ${dmnFormResult.decisionName} expression`}
title={`Open '${dmnFormResult.decisionName}' expression`}
icon={<ArrowUpIcon />}
data-navigate-to-expression-id={dmnFormResult.decisionId}
onClick={() => onOpenBoxedExpressionEditor?.(dmnFormResult.decisionId)}
/>
)}
Expand Down
21 changes: 20 additions & 1 deletion packages/online-editor/src/dmnRunner/DmnRunnerTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ import setObjectValueByPath from "lodash/set";
import cloneDeep from "lodash/cloneDeep";
import { DmnRunnerProviderActionType } from "./DmnRunnerTypes";
import { DmnRunnerExtendedServicesError } from "./DmnRunnerContextProvider";
import { MessageBusClientApi } from "@kie-tools-core/envelope-bus/dist/api";
import { NewDmnEditorEnvelopeApi } from "@kie-tools/dmn-editor-envelope/dist/NewDmnEditorEnvelopeApi";
import { EmbeddedEditorRef } from "@kie-tools-core/editor/dist/embedded";
import { useSettings } from "../settings/SettingsContext";

export function DmnRunnerTable() {
export function DmnRunnerTable(props: { editor: EmbeddedEditorRef | undefined }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm don't think we want to have an undefined editor as props of the DmnRunnerTable. Also, the getEnvelopeServer() is the only property of editor that is used, which could be accordlying typed to avoid casting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// STATEs
const [dmnRunnerTableError, setDmnRunnerTableError] = useState<boolean>(false);

Expand Down Expand Up @@ -113,6 +117,9 @@ export function DmnRunnerTable() {
setDmnRunnerTableError(false);
}, [jsonSchema]);

const { settings } = useSettings();
const isLegacyDmnEditor = useMemo(() => settings.editors.useLegacyDmnEditor, [settings.editors.useLegacyDmnEditor]);

return (
<>
{extendedServicesError ? (
Expand All @@ -137,6 +144,18 @@ export function DmnRunnerTable() {
i18n={i18n.dmnRunner.table}
jsonSchemaBridge={jsonSchemaBridge}
results={results}
openBoxedExpressionEditor={
!isLegacyDmnEditor
? (nodeId: string) => {
const newDmnEditorEnvelopeApi = props.editor?.getEnvelopeServer()
.envelopeApi as unknown as MessageBusClientApi<NewDmnEditorEnvelopeApi>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the as unknown is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


newDmnEditorEnvelopeApi.notifications.dmnEditor_openBoxedExpressionEditor.send(
nodeId
);
}
: undefined
}
/>
</div>
</DrawerPanelContent>
Expand Down
1 change: 1 addition & 0 deletions packages/online-editor/src/editor/EditorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ Error details: ${err}`);
workspaceFile={file.workspaceFile}
workspaces={workspaces}
dmnLanguageService={dmnLanguageService}
editor={editor}
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned, we could pass the editorEnvelopeServer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

isEditorReady={editor?.isReady ?? false}
editorValidate={editor?.validate}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import { DmnRunnerTable } from "../dmnRunner/DmnRunnerTable";
import { ErrorBoundary } from "../reactExt/ErrorBoundary";
import { DmnRunnerErrorBoundary } from "../dmnRunner/DmnRunnerErrorBoundary";
import { EmbeddedEditorRef } from "@kie-tools-core/editor/dist/embedded";

interface EditorPageDockContextType {
panel: PanelId;
Expand Down Expand Up @@ -74,6 +75,7 @@
workspaces: WorkspacesContextType;
dmnLanguageService?: DmnLanguageService;
isEditorReady: boolean;
editor: EmbeddedEditorRef | undefined;
editorValidate?: () => Promise<Notification[]>;
}

Expand All @@ -83,6 +85,7 @@
workspaces,
workspaceFile,
isEditorReady,
editor,
editorValidate,
}: React.PropsWithChildren<Props>) {
const { i18n } = useOnlineI18n();
Expand Down Expand Up @@ -186,13 +189,13 @@
case PanelId.DMN_RUNNER_TABLE:
return (
<DmnRunnerErrorBoundary>
<DmnRunnerTable />
<DmnRunnerTable editor={editor} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

</DmnRunnerErrorBoundary>
);
default:
return undefined;
}
}, [notificationsPanelRef, notificationsPanelTabNames, panel]);

Check warning on line 198 in packages/online-editor/src/editor/EditorPageDockContextProvider.tsx

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest, 2)

React Hook useMemo has a missing dependency: 'editor'. Either include it or remove the dependency array

Check warning on line 198 in packages/online-editor/src/editor/EditorPageDockContextProvider.tsx

View workflow job for this annotation

GitHub Actions / run (macos-13, 2)

React Hook useMemo has a missing dependency: 'editor'. Either include it or remove the dependency array

Check warning on line 198 in packages/online-editor/src/editor/EditorPageDockContextProvider.tsx

View workflow job for this annotation

GitHub Actions / run (windows-latest, 2)

React Hook useMemo has a missing dependency: 'editor'. Either include it or remove the dependency array

const addToggleItem = useCallback((panelId: PanelId, newItem: JSX.Element) => {
setToggleGroupItem((previousToggleGroupItems) => {
Expand Down
69 changes: 58 additions & 11 deletions packages/unitables-dmn/src/DmnRunnerOutputsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,24 @@ import "@kie-tools/boxed-expression-component/dist/@types/react-table";
import { ResizerStopBehavior } from "@kie-tools/boxed-expression-component/dist/resizing/ResizingWidthsContext";
import "./DmnRunnerOutputsTable.css";
import { DecisionResult, DmnEvaluationResult } from "@kie-tools/extended-services-api";
import { Button } from "@patternfly/react-core/dist/js/components/Button";
import { ArrowUpIcon } from "@patternfly/react-icons/dist/js/icons/arrow-up-icon";

interface Props {
i18n: DmnUnitablesI18n;
results: Array<DecisionResult[] | undefined> | undefined;
jsonSchemaBridge: DmnUnitablesJsonSchemaBridge;
scrollableParentRef: React.RefObject<HTMLElement>;
openBoxedExpressionEditor?: (nodeId: string) => void;
}

export function DmnRunnerOutputsTable({ i18n, jsonSchemaBridge, results, scrollableParentRef }: Props) {
export function DmnRunnerOutputsTable({
i18n,
jsonSchemaBridge,
results,
scrollableParentRef,
openBoxedExpressionEditor,
}: Props) {
const outputUid = useMemo(() => nextId(), []);
const outputErrorBoundaryRef = useRef<ErrorBoundary>(null);
const [outputError, setOutputError] = useState<boolean>(false);
Expand Down Expand Up @@ -80,6 +89,7 @@ export function DmnRunnerOutputsTable({ i18n, jsonSchemaBridge, results, scrolla
outputsPropertiesMap={outputsPropertiesMap}
results={results}
id={outputUid}
openBoxedExpressionEditor={openBoxedExpressionEditor}
/>
</ErrorBoundary>
) : (
Expand Down Expand Up @@ -129,9 +139,17 @@ interface OutputsTableProps {
results: (DecisionResult[] | undefined)[] | undefined;
outputsPropertiesMap: Map<string, OutputField>;
scrollableParentRef: React.RefObject<HTMLElement>;
openBoxedExpressionEditor?: (nodeId: string) => void;
}

function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollableParentRef }: OutputsTableProps) {
function OutputsBeeTable({
id,
i18n,
outputsPropertiesMap,
results,
scrollableParentRef,
openBoxedExpressionEditor,
}: OutputsTableProps) {
const beeTableOperationConfig = useMemo<BeeTableOperationConfig>(
() => [
{
Expand Down Expand Up @@ -228,8 +246,33 @@ function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollablePa
[getRowValue]
);

const onOpenBoxedExpressionHeaderButtonClick = useCallback(
(clickedDecisionId: string) => {
(results?.[0] ?? []).flatMap(({ decisionId: resultDecisionId }) => {
if (clickedDecisionId === resultDecisionId) {
openBoxedExpressionEditor?.(resultDecisionId);
}
});
},
[openBoxedExpressionEditor, results]
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, everytime we click on the button we will search the array to check if decisionId is part of the results. Why not save the result decisionIds in a set?

const resultsDecisionIds = useMemo(() => results?.[0]?.reduce((set, result) => {
  set.add(result.decisionId);
  return set;
}, new Set()), [results]);

... 
onClick={() => resultsDecisionIds.has(decisionId) && openBoxedExpressionEditor?.(decisionId)}

(I didn't test the code above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, I like this incorporated


const openBoxedExpressionHeaderButton = useCallback(
({ decisionId, decisionName }) => {
return (
<Button
variant={"plain"}
title={`Open '${decisionName}' expression`}
icon={<ArrowUpIcon />}
onClick={() => onOpenBoxedExpressionHeaderButtonClick(decisionId)}
/>
);
},
[onOpenBoxedExpressionHeaderButtonClick]
);

const beeTableColumns = useMemo<ReactTable.Column<ROWTYPE>[]>(() => {
return (results?.[0] ?? []).flatMap(({ result, decisionName }) => {
return (results?.[0] ?? []).flatMap(({ result, decisionName, decisionId }) => {
const outputProperties = outputsPropertiesMap.get(decisionName);
if (!outputProperties) {
return [];
Expand All @@ -245,7 +288,8 @@ function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollablePa
);
return [
{
originalId: `${outputProperties?.name}-` + generateUuid(),
originalId: `${outputProperties?.name}-${generateUuid()}`,
headerCellElementExtension: openBoxedExpressionHeaderButton({ decisionId, decisionName }),
label: outputProperties?.name ?? "",
accessor: (`output-object-parent-${outputProperties?.name}-` + generateUuid()) as any,
dataType: outputProperties?.dataType,
Expand All @@ -259,7 +303,7 @@ function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollablePa
return deepFlattenObjectColumn(collectedOutput, outputProperties?.properties);
}
return {
originalId: "context-" + generateUuid(),
originalId: `context-${generateUuid()}`,
label: "context",
accessor: (`output-context-` + generateUuid()) as any,
dataType: outputProperties?.dataType ?? DmnBuiltInDataType.Any,
Expand All @@ -286,7 +330,7 @@ function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollablePa
if (typeof result === "string" || typeof result === "number" || typeof result === "boolean" || result === null) {
return [
{
originalId: `parent-${outputProperties?.name}-` + generateUuid(),
originalId: `parent-${outputProperties?.name}-${generateUuid()}`,
label: "",
accessor: (`output-parent-${outputProperties?.name}-` + generateUuid()) as any,
dataType: undefined as any,
Expand All @@ -295,7 +339,8 @@ function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollablePa
minWidth: DMN_RUNNER_OUTPUT_COLUMN_MIN_WIDTH,
columns: [
{
originalId: `${outputProperties?.name}-` + generateUuid(),
originalId: `${outputProperties?.name}-${generateUuid()}-${outputProperties?.properties?.id}`,
headerCellElementExtension: openBoxedExpressionHeaderButton({ decisionId, decisionName }),
label: outputProperties?.name ?? "",
accessor: (`output-${outputProperties?.name}-` + generateUuid()) as any,
dataType: outputProperties?.dataType ?? DmnBuiltInDataType.Undefined,
Expand All @@ -312,14 +357,15 @@ function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollablePa
if (Array.isArray(result)) {
return [
{
originalId: `${outputProperties?.name}-` + generateUuid(),
originalId: `${outputProperties?.name}-${generateUuid()}`,
headerCellElementExtension: openBoxedExpressionHeaderButton({ decisionId, decisionName }),
label: `${outputProperties?.name}`,
accessor: (`output-array-parent-${outputProperties?.name}-` + generateUuid()) as any,
dataType: outputProperties?.dataType ?? DmnBuiltInDataType.Undefined,
isRowIndexColumn: false,
groupType: "dmn-runner-output",
columns: result.map((entry, entryIndex) => ({
originalId: `${entryIndex}-` + generateUuid(),
originalId: `${entryIndex}-${generateUuid()}`,
label: `[${entryIndex}]`,
accessor: (`output-array-${entryIndex}-` + generateUuid()) as any,
dataType: undefined as any,
Expand All @@ -336,7 +382,8 @@ function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollablePa
if (typeof result === "object") {
return [
{
originalId: `${outputProperties?.name}-` + generateUuid(),
originalId: `${outputProperties?.name}-${generateUuid()}`,
headerCellElementExtension: openBoxedExpressionHeaderButton({ decisionId, decisionName }),
label: outputProperties?.name ?? "",
accessor: (`output-object-parent-${outputProperties?.name}-` + generateUuid()) as any,
dataType: outputProperties?.dataType ?? DmnBuiltInDataType.Undefined,
Expand All @@ -349,7 +396,7 @@ function OutputsBeeTable({ id, i18n, outputsPropertiesMap, results, scrollablePa
}
return [] as ReactTable.Column<ROWTYPE>[];
});
}, [deepFlattenObjectColumn, outputsPropertiesMap, results]);
}, [deepFlattenObjectColumn, openBoxedExpressionHeaderButton, outputsPropertiesMap, results]);

const beeTableRows = useMemo<ROWTYPE[]>(() => {
return (results ?? []).map((decisionResult, rowIndex) => {
Expand Down
Loading