Skip to content

Commit

Permalink
kie-issues#883: On the DMN Editor, allow deleting DRDs + `extend-node…
Browse files Browse the repository at this point in the history
…-path=false` for safer `node_modules` structure (apache#2230)

Co-authored-by: Thiago Lugli <[email protected]>
  • Loading branch information
2 people authored and fantonangeli committed Apr 23, 2024
1 parent 94bada1 commit 1805ef6
Show file tree
Hide file tree
Showing 65 changed files with 521 additions and 402 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dedupe-peer-dependents=false # Without this, pnpm will always install all packages when `pnpm booststrap:root` runs. See https://github.com/pnpm/pnpm/issues/6300.
extend-node-path=false # Prevent `pnpm` from allowing binaries to require transitive dependencies through `node_modules/.pnpm/node_modules` when on files that are inside workspace packages.
2 changes: 1 addition & 1 deletion packages/backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
testRegex: "/tests/.*\\.test\\.(jsx?|tsx?)$",
transform: {
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }], "@babel/react"] }],
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }]] }],
"^.+\\.tsx?$": "ts-jest",
},
transformIgnorePatterns: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/bpmn-marshaller/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
testRegex: "/tests/.*\\.test\\.(jsx?|tsx?)$",
transform: {
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }], "@babel/react"] }],
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }]] }],
"^.+\\.tsx?$": "ts-jest",
},
};
1 change: 1 addition & 0 deletions packages/bpmn-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@vscode/test-web": "^0.0.30",
"@vscode/vsce": "^2.22.0",
"copy-webpack-plugin": "^11.0.0",
"process": "^0.11.10",
"rimraf": "^3.0.2",
"webpack": "^5.88.2",
"webpack-cli": "^4.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"jest": "^26.6.3",
"jest-junit": "^14.0.0",
"jest-when": "^3.5.0",
"process": "^0.11.10",
"rimraf": "^3.0.2",
"selenium-webdriver": "^4.15.0",
"start-server-and-test": "^1.12.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
"@types/jest-when": "^2.7.4",
"copy-webpack-plugin": "^11.0.0",
"jest": "^26.6.3",
"jest-junit": "^14.0.0",
"jest-when": "^3.5.0",
"monaco-editor": "^0.39.0",
"monaco-editor-webpack-plugin": "^7.0.1",
"monaco-yaml": "^4.0.4",
"process": "^0.11.10",
"rimraf": "^3.0.2",
"start-server-and-test": "^1.12.1",
"ts-jest": "^26.5.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/cors-proxy-api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
testRegex: "/tests/.*\\.test\\.(jsx?|tsx?)$",
transform: {
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }], "@babel/react"] }],
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }]] }],
"^.+\\.tsx?$": "ts-jest",
},
moduleNameMapper: {
Expand Down
2 changes: 2 additions & 0 deletions packages/cors-proxy-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
},
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@kie-tools/eslint": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"@kie-tools/tsconfig": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/cors-proxy/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
testRegex: "/tests/.*\\.test\\.(jsx?|tsx?)$",
transform: {
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }], "@babel/react"] }],
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }]] }],
"^.+\\.tsx?$": "ts-jest",
},
};
3 changes: 3 additions & 0 deletions packages/cors-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"node-fetch": "^3.3.1"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@kie-tools-core/webpack-base": "workspace:*",
"@kie-tools/cors-proxy-api": "workspace:*",
"@kie-tools/eslint": "workspace:*",
Expand All @@ -42,6 +44,7 @@
"@types/node": "^18.13.0",
"cross-env": "^7.0.3",
"jest": "^26.6.3",
"jest-junit": "^14.0.0",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"ts-jest": "^26.5.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/dashbuilder-language-service/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
testRegex: "/tests/.*\\.test\\.(jsx?|tsx?)$",
transform: {
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }], "@babel/react"] }],
"^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }]] }],
"^.+\\.tsx?$": "ts-jest",
},
moduleNameMapper: {
Expand Down
2 changes: 2 additions & 0 deletions packages/dashbuilder-viewer-deployment-webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
"@kie-tools/eslint": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"@kie-tools/tsconfig": "workspace:*",
"@testing-library/jest-dom": "^5.16.1",
"@types/jest": "^26.0.23",
"@types/jest-when": "^2.7.4",
"@types/react": "^17.0.6",
"@types/react-dom": "^17.0.5",
"@types/react-router": "^5.1.20",
"@types/react-router-dom": "^5.3.3",
"@types/testing-library__jest-dom": "^5.9.1",
"copy-webpack-plugin": "^11.0.0",
"html-replace-webpack-plugin": "^2.6.0",
"html-webpack-plugin": "^5.3.2",
Expand Down
99 changes: 66 additions & 33 deletions packages/dmn-editor/src/diagram/DrdSelectorPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,32 @@ import { Title } from "@patternfly/react-core/dist/js/components/Title";
import { Form, FormGroup, FormSection } from "@patternfly/react-core/dist/js/components/Form";
import { ToggleGroup, ToggleGroupItem } from "@patternfly/react-core/dist/js/components/ToggleGroup";
import { AlternativeInputDataIcon, InputDataIcon } from "../icons/Icons";
import { EmptyState, EmptyStateBody } from "@patternfly/react-core/dist/js/components/EmptyState";
import { Flex } from "@patternfly/react-core/dist/js/layouts/Flex";
import { useCallback } from "react";

export function DrdSelectorPanel() {
const thisDmn = useDmnEditorStore((s) => s.dmn);
const diagram = useDmnEditorStore((s) => s.diagram);
const isAlternativeInputDataShape = useDmnEditorStore((s) => s.computed(s).isAlternativeInputDataShape());
const drdName = useDmnEditorStore(
(s) =>
s.dmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"]?.[s.diagram.drdIndex]["@_name"] ||
s.dmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"]?.[s.diagram.drdIndex]?.["@_name"] ||
getDefaultDrdName({ drdIndex: s.diagram.drdIndex })
);

const dmnEditorStoreApi = useDmnEditorStoreApi();

const drds = thisDmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"] ?? [];

const removeDrd = useCallback(() => {
dmnEditorStoreApi.setState((s) => {
const nextDrds = s.dmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"];
nextDrds?.splice(s.diagram.drdIndex, 1);
s.diagram.drdIndex = Math.max(0, Math.min(s.diagram.drdIndex, (nextDrds?.length ?? 0) - 1));
});
}, [dmnEditorStoreApi]);

return (
<>
<div
Expand Down Expand Up @@ -89,28 +102,48 @@ export function DrdSelectorPanel() {
<div style={{ gridArea: "divider-list" }}>
<Divider style={{ marginBottom: "8px" }} />
</div>
<div style={{ gridArea: "content-list" }} className={"kie-dmn-editor--drd-list"}>
{thisDmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"]?.map((drd, i) => (
<React.Fragment key={drd["@_id"]!}>
<button
className={i === diagram.drdIndex ? "active" : undefined}
onClick={() => {
dmnEditorStoreApi.setState((state) => {
state.diagram.drdIndex = i;
});
}}
>
{`${i + 1}. ${drd["@_name"] || getDefaultDrdName({ drdIndex: i })}`}
</button>
<br />
</React.Fragment>
))}
</div>
{(drds.length <= 0 && (
<>
<EmptyState>
<Title size={"md"} headingLevel={"h4"}>
{"You're on the default DRD"}
</Title>
<EmptyStateBody>
{"Adding nodes or making changes to the Diagram will automatically create a DRD for you."}
</EmptyStateBody>
</EmptyState>
</>
)) || (
<div style={{ gridArea: "content-list" }} className={"kie-dmn-editor--drd-list"}>
{drds.map((drd, i) => (
<React.Fragment key={drd["@_id"]!}>
<button
className={i === diagram.drdIndex ? "active" : undefined}
onClick={() => {
dmnEditorStoreApi.setState((state) => {
state.diagram.drdIndex = i;
});
}}
>
{`${i + 1}. ${drd["@_name"] || getDefaultDrdName({ drdIndex: i })}`}
</button>
<br />
</React.Fragment>
))}
</div>
)}

<div style={{ gridArea: "header-properties" }}>
<Title headingLevel="h3" style={{ height: "36px" }}>
{drdName}
</Title>
<Flex justifyContent={{ default: "justifyContentSpaceBetween" }}>
<Title headingLevel="h3" style={{ height: "36px" }}>
{drdName}
</Title>
{drds.length > 0 && (
<Button variant={ButtonVariant.link} onClick={removeDrd} style={{ padding: 0 }}>
Remove
</Button>
)}
</Flex>
</div>
<div style={{ gridArea: "divider-properties" }}>
<Divider style={{ marginBottom: "8px" }} />
Expand All @@ -129,12 +162,12 @@ export function DrdSelectorPanel() {
buttonId="classic-input-node-shape"
isSelected={isAlternativeInputDataShape === false}
onChange={() =>
dmnEditorStoreApi.setState((state) => {
state.dmn.model.definitions["dmndi:DMNDI"] ??= {};
state.dmn.model.definitions["dmndi:DMNDI"]["dmndi:DMNDiagram"] ??= [];
state.dmn.model.definitions["dmndi:DMNDI"]["dmndi:DMNDiagram"][state.diagram.drdIndex][
"@_useAlternativeInputDataShape"
] = false;
dmnEditorStoreApi.setState((s) => {
const { diagram: drd } = addOrGetDrd({
definitions: s.dmn.model.definitions,
drdIndex: s.diagram.drdIndex,
});
drd["@_useAlternativeInputDataShape"] = false;
})
}
/>
Expand All @@ -151,12 +184,12 @@ export function DrdSelectorPanel() {
buttonId="alternative-input-node-shape"
isSelected={isAlternativeInputDataShape === true}
onChange={() =>
dmnEditorStoreApi.setState((state) => {
state.dmn.model.definitions["dmndi:DMNDI"] ??= {};
state.dmn.model.definitions["dmndi:DMNDI"]["dmndi:DMNDiagram"] ??= [];
state.dmn.model.definitions["dmndi:DMNDI"]["dmndi:DMNDiagram"][state.diagram.drdIndex][
"@_useAlternativeInputDataShape"
] = true;
dmnEditorStoreApi.setState((s) => {
const { diagram: drd } = addOrGetDrd({
definitions: s.dmn.model.definitions,
drdIndex: s.diagram.drdIndex,
});
drd["@_useAlternativeInputDataShape"] = true;
})
}
/>
Expand Down
76 changes: 47 additions & 29 deletions packages/dmn-editor/src/diagram/DrgNodesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import { Unpacked } from "../tsExt/tsExt";
import { buildXmlHref } from "../xml/xmlHrefs";
import { Divider } from "@patternfly/react-core/dist/js/components/Divider";
import { computeContainingDecisionServiceHrefsByDecisionHrefs } from "../store/computed/computeContainingDecisionServiceHrefsByDecisionHrefs.ts";
import { EmptyState, EmptyStateBody, EmptyStateIcon } from "@patternfly/react-core/dist/js/components/EmptyState";
import { Title } from "@patternfly/react-core/dist/js/components/Title";
import CubesIcon from "@patternfly/react-icons/dist/js/icons/cubes-icon";

export const MIME_TYPE_FOR_DMN_EDITOR_DRG_NODE = "kie-dmn-editor--drg-node";

Expand Down Expand Up @@ -100,37 +103,52 @@ export function DrgNodesPanel() {

return (
<>
<div className="kie-dmn-editor--sticky-top-glass-header" style={{ padding: "12px" }}>
<Flex justifyContent={{ default: "justifyContentSpaceBetween" }}>
<TextContent>
<Text component="h3">DRG Nodes</Text>
</TextContent>
<Button
title={"Close"}
variant={ButtonVariant.plain}
onClick={() =>
dmnEditorStoreApi.setState((state) => {
state.diagram.openLhsPanel = DiagramLhsPanel.NONE;
})
}
>
<TimesIcon />
</Button>
</Flex>
{(nodes.length <= 0 && (
<>
<EmptyState>
<EmptyStateIcon icon={CubesIcon} />
<Title size={"md"} headingLevel={"h4"}>
No DRG nodes yet
</Title>
<EmptyStateBody>Use the Palette on the left-hand-side to drag new nodes into the Diagram.</EmptyStateBody>
</EmptyState>
</>
)) || (
<>
<div className="kie-dmn-editor--sticky-top-glass-header" style={{ padding: "12px" }}>
<Flex justifyContent={{ default: "justifyContentSpaceBetween" }}>
<TextContent>
<Text component="h3">DRG Nodes</Text>
</TextContent>
<Button
title={"Close"}
variant={ButtonVariant.plain}
onClick={() =>
dmnEditorStoreApi.setState((state) => {
state.diagram.openLhsPanel = DiagramLhsPanel.NONE;
})
}
>
<TimesIcon />
</Button>
</Flex>

<Divider style={{ marginBottom: "12px" }} />

<Divider style={{ marginBottom: "12px" }} />
<SearchInput
style={{ marginBottom: "12px", height: "36px" }}
onKeyDown={(e) => e.stopPropagation()}
autoFocus={true}
placeholder="Filter..."
value={filter}
onChange={(_event, value) => setFilter(value)}
onClear={() => setFilter("")}
/>
</div>

<SearchInput
style={{ marginBottom: "12px", height: "36px" }}
onKeyDown={(e) => e.stopPropagation()}
autoFocus={true}
placeholder="Filter..."
value={filter}
onChange={(_event, value) => setFilter(value)}
onClear={() => setFilter("")}
/>
</div>
<div style={{ padding: "12px" }}>{nodes}</div>
<div style={{ padding: "12px" }}>{nodes}</div>
</>
)}
</>
);
}
2 changes: 1 addition & 1 deletion packages/dmn-editor/src/icons/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function AlternativeInputDataIcon(props: {
isIcon={true}
width={80}
height={100}
strokeWidth={8}
strokeWidth={10}
transform={props.transform ?? "translate(80, 60)"}
isCollection={false}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Draggable, DragAndDrop, useDraggableItemContext } from "../draggable/Dr
import "./DocumentationLinksFormGroup.css";

const PLACEHOLDER_URL_TITLE = "Enter a title...";
const PLACEHOLDER_URL = "http://";
const PLACEHOLDER_URL = "https://...";

export function DocumentationLinksFormGroup({
isReadonly,
Expand Down Expand Up @@ -173,8 +173,8 @@ export function DocumentationLinksFormGroup({
rowClassName={index !== 0 ? "kie-dmn-editor--documentation-link--not-first-element" : ""}
handlerStyle={
expandedUrls[index]
? { alignSelf: "flex-start", paddingTop: "8px", paddingLeft: "24px", paddingRight: "8px" }
: { paddingLeft: "24px", paddingRight: "8px" }
? { alignSelf: "flex-start", paddingTop: "8px", paddingLeft: "16px", paddingRight: "16px" }
: { paddingLeft: "16px", paddingRight: "16px" }
}
>
<li>
Expand Down Expand Up @@ -257,7 +257,7 @@ function DocumentationLinksInput({
} catch (error) {
try {
if (!newUrl.includes("http://") && !newUrl.includes("https://")) {
const urlWithProtocol = "http://" + newUrl + "/";
const urlWithProtocol = "https://" + newUrl + "/";
const url = new URL(urlWithProtocol);
// the new URL automatically converts the whitespaces to %20
// this check verifies if the url has whitespaces
Expand Down
2 changes: 1 addition & 1 deletion packages/dmn-editor/src/store/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export function createDmnEditorStore(model: State["dmn"]["model"], computedCache
isAlternativeInputDataShape: () =>
computedCache.cached(
"isAlternativeInputDataShape",
(drdIndex, dmnDiagram) => dmnDiagram?.[drdIndex]["@_useAlternativeInputDataShape"] ?? false,
(drdIndex, dmnDiagram) => dmnDiagram?.[drdIndex]?.["@_useAlternativeInputDataShape"] ?? false,
[s.diagram.drdIndex, s.dmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"]] as const
),

Expand Down
Loading

0 comments on commit 1805ef6

Please sign in to comment.