-
Notifications
You must be signed in to change notification settings - Fork 201
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
base: main
Are you sure you want to change the base?
Changes from 44 commits
f94cd78
26163ca
7a2a0b8
f5b569e
5c8c363
b3f30df
fffdcc5
065a5df
37a33f3
a52fa97
e838157
1235854
77be060
3cba7d8
000f526
148c40b
de467be
0291e41
7d93fa1
64a5a35
1a230c8
fbfb876
79487ab
18c7a92
fdad8ba
3b9e17a
ae3d87c
94276c6
1b1e846
81052f9
f7e0c51
630525b
e1045a2
f6334ed
1f16c01
8d96afd
f2e8379
28ce164
1f488c0
ec2e294
2cc14a0
fab6f0a
13f30d6
ed1d20b
890fa9c
2d5e162
7bc1cdd
4aa8e03
81050d2
3d9c22a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm don't think we want to have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// STATEs | ||
const [dmnRunnerTableError, setDmnRunnerTableError] = useState<boolean>(false); | ||
|
||
|
@@ -113,6 +117,9 @@ export function DmnRunnerTable() { | |
setDmnRunnerTableError(false); | ||
}, [jsonSchema]); | ||
|
||
const { settings } = useSettings(); | ||
const isLegacyDmnEditor = useMemo(() => settings.editors.useLegacyDmnEditor, [settings.editors.useLegacyDmnEditor]); | ||
|
||
return ( | ||
<> | ||
{extendedServicesError ? ( | ||
|
@@ -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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
newDmnEditorEnvelopeApi.notifications.dmnEditor_openBoxedExpressionEditor.send( | ||
nodeId | ||
); | ||
} | ||
: undefined | ||
} | ||
/> | ||
</div> | ||
</DrawerPanelContent> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -468,6 +468,7 @@ Error details: ${err}`); | |
workspaceFile={file.workspaceFile} | ||
workspaces={workspaces} | ||
dmnLanguageService={dmnLanguageService} | ||
editor={editor} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned, we could pass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
isEditorReady={editor?.isReady ?? false} | ||
editorValidate={editor?.validate} | ||
> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -74,6 +75,7 @@ | |
workspaces: WorkspacesContextType; | ||
dmnLanguageService?: DmnLanguageService; | ||
isEditorReady: boolean; | ||
editor: EmbeddedEditorRef | undefined; | ||
editorValidate?: () => Promise<Notification[]>; | ||
} | ||
|
||
|
@@ -83,6 +85,7 @@ | |
workspaces, | ||
workspaceFile, | ||
isEditorReady, | ||
editor, | ||
editorValidate, | ||
}: React.PropsWithChildren<Props>) { | ||
const { i18n } = useOnlineI18n(); | ||
|
@@ -186,13 +189,13 @@ | |
case PanelId.DMN_RUNNER_TABLE: | ||
return ( | ||
<DmnRunnerErrorBoundary> | ||
<DmnRunnerTable /> | ||
<DmnRunnerTable editor={editor} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 GitHub Actions / run (ubuntu-latest, 2)
Check warning on line 198 in packages/online-editor/src/editor/EditorPageDockContextProvider.tsx GitHub Actions / run (macos-13, 2)
|
||
|
||
const addToggleItem = useCallback((panelId: PanelId, newItem: JSX.Element) => { | ||
setToggleGroupItem((previousToggleGroupItems) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -80,6 +89,7 @@ export function DmnRunnerOutputsTable({ i18n, jsonSchemaBridge, results, scrolla | |
outputsPropertiesMap={outputsPropertiesMap} | ||
results={results} | ||
id={outputUid} | ||
openBoxedExpressionEditor={openBoxedExpressionEditor} | ||
/> | ||
</ErrorBoundary> | ||
) : ( | ||
|
@@ -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>( | ||
() => [ | ||
{ | ||
|
@@ -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] | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
(I didn't test the code above) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 []; | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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) => { | ||
|
There was a problem hiding this comment.
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 theboxed-expression-component
we are using multiple classes.There was a problem hiding this comment.
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 haveheader-cell
orheader-cell-info
already in use.