tiagobento commented on code in PR #2887:
URL:
https://github.com/apache/incubator-kie-tools/pull/2887#discussion_r1962549739
##########
packages/scesim-editor/src/creation/TestScenarioCreationPanel.tsx:
##########
@@ -37,45 +39,142 @@ import CubesIcon from
"@patternfly/react-icons/dist/esm/icons/cubes-icon";
import { useTestScenarioEditorStoreApi } from
"../store/TestScenarioStoreContext";
import { useTestScenarioEditorI18n } from "../i18n";
+import { useExternalModels } from
"../externalModels/TestScenarioEditorDependenciesContext";
+import { ExternalDmn } from "../TestScenarioEditor";
+import { createNewDmnTypeTestScenario } from
"../mutations/createNewDmnTypeTestScenario";
+import { createNewRuleTypeTestScenario } from
"../mutations/createNewRuleTypeTestScenario";
+
import "./TestScenarioCreationPanel.css";
function TestScenarioCreationPanel() {
const { i18n } = useTestScenarioEditorI18n();
+ const { onRequestExternalModelsAvailableToInclude,
onRequestExternalModelByPath } = useExternalModels();
+ const testScenarioEditorStoreApi = useTestScenarioEditorStoreApi();
- const assetsOption = [
- { value: "", label: i18n.creationPanel.assetsOption.noChoice, disabled:
true },
- { value: "DMN", label: i18n.creationPanel.assetsOption.dmn, disabled:
false },
- { value: "RULE", label: i18n.creationPanel.assetsOption.rule, disabled:
false },
- ];
-
+ const [allDmnModelNormalizedPosixRelativePaths,
setAllDmnModelNormalizedPosixRelativePaths] = useState<
+ string[] | undefined
+ >(undefined);
const [assetType, setAssetType] = React.useState<"" | "DMN" | "RULE">("");
+ const [callBackError, setCallBackError] = useState<any>(undefined);
const [isAutoFillTableEnabled, setAutoFillTableEnabled] =
React.useState(true);
const [isStatelessSessionRule, setStatelessSessionRule] =
React.useState(false);
const [isTestSkipped, setTestSkipped] = React.useState(false);
const [kieSessionRule, setKieSessionRule] = React.useState("");
const [ruleFlowGroup, setRuleFlowGroup] = React.useState("");
- const testScenarioEditorStoreApi = useTestScenarioEditorStoreApi();
+ const [selectedDmnModel, setSelectedDmnModel] = useState<ExternalDmn |
undefined>(undefined);
+ const [selectedDmnModelPathRelativeToThisScesim,
setSelectedDmnModelPathRelativeToThisScesim] = useState<
+ string | undefined
+ >(undefined);
+
+ const assetsOption = [
+ { value: "", label: i18n.creationPanel.assetsOption.noChoice, disabled:
true },
+ { value: "DMN", label: i18n.creationPanel.assetsOption.dmn, disabled:
false },
+ { value: "RULE", label: i18n.creationPanel.assetsOption.rule, disabled:
false },
+ ];
+
+ /** This callback retrieves all the avaiable DMN files available in the
user's project */
+ useCancelableEffect(
+ useCallback(
+ ({ canceled }) => {
+ onRequestExternalModelsAvailableToInclude?.()
+ .then((dmnModelNormalizedPosixPathRelativePaths) => {
+ console.trace("[TestScenarioCreationPanel] The below external DMN
models have been found");
+ console.trace(dmnModelNormalizedPosixPathRelativePaths);
+
+ if (canceled.get()) {
+ return;
+ }
+ setAllDmnModelNormalizedPosixRelativePaths(
+ dmnModelNormalizedPosixPathRelativePaths.sort((modelA, modelB) =>
+ basename(modelA).localeCompare(basename(modelB))
+ )
+ );
+ })
+ .catch((err) => {
+ setCallBackError(err);
+ console.error(
+ `[TestScenarioCreationPanel] The below error when trying to
retrieve all the External DMN files from the project.`
+ );
+ console.error(err);
+ });
+ },
+ [onRequestExternalModelsAvailableToInclude]
+ )
+ );
+
+ /** This callback return the unmarshalled representation of a DMN model
given its path */
+ useCancelableEffect(
+ useCallback(
+ ({ canceled }) => {
+ if (!selectedDmnModelPathRelativeToThisScesim ||
onRequestExternalModelByPath === undefined) {
+ return;
+ }
+
+ onRequestExternalModelByPath(selectedDmnModelPathRelativeToThisScesim)
+ .then((externalDMNModel) => {
+ console.trace("[TestScenarioCreationPanel] The below external DMN
model have been loaded");
+ console.trace(externalDMNModel);
+
+ if (canceled.get() || !externalDMNModel) {
+ return;
+ }
+
+ setSelectedDmnModel(externalDMNModel);
+ })
+ .catch((err) => {
+ setCallBackError(err);
+ console.error(
+ `[TestScenarioCreationPanel] An error occurred when parsing the
selected model '${selectedDmnModelPathRelativeToThisScesim}'. Please
double-check it is a non-empty valid model.`
+ );
+ console.error(err);
+ });
+ },
+ [onRequestExternalModelByPath, selectedDmnModelPathRelativeToThisScesim]
+ )
+ );
+
+ /* If any error occurs during the execution of useCancelableEffect's
callback, */
+ /* it throws the error that will be catched by the ErrorBoundary.
*/
+ useEffect(() => {
+ if (callBackError) {
+ throw callBackError;
+ }
+ }, [callBackError]);
Review Comment:
What try/catch block? Sorry it seems that are multiple ones. If an error
happens and we do something on the screen to "treat it", I think we shouldn't
re-throw it. Not if it's really an "end of the world" type of error, I think we
should just throw and let the first
[ErrorBoundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary)
catch it.
##########
packages/scesim-editor/src/creation/TestScenarioCreationPanel.tsx:
##########
@@ -37,45 +39,142 @@ import CubesIcon from
"@patternfly/react-icons/dist/esm/icons/cubes-icon";
import { useTestScenarioEditorStoreApi } from
"../store/TestScenarioStoreContext";
import { useTestScenarioEditorI18n } from "../i18n";
+import { useExternalModels } from
"../externalModels/TestScenarioEditorDependenciesContext";
+import { ExternalDmn } from "../TestScenarioEditor";
+import { createNewDmnTypeTestScenario } from
"../mutations/createNewDmnTypeTestScenario";
+import { createNewRuleTypeTestScenario } from
"../mutations/createNewRuleTypeTestScenario";
+
import "./TestScenarioCreationPanel.css";
function TestScenarioCreationPanel() {
const { i18n } = useTestScenarioEditorI18n();
+ const { onRequestExternalModelsAvailableToInclude,
onRequestExternalModelByPath } = useExternalModels();
+ const testScenarioEditorStoreApi = useTestScenarioEditorStoreApi();
- const assetsOption = [
- { value: "", label: i18n.creationPanel.assetsOption.noChoice, disabled:
true },
- { value: "DMN", label: i18n.creationPanel.assetsOption.dmn, disabled:
false },
- { value: "RULE", label: i18n.creationPanel.assetsOption.rule, disabled:
false },
- ];
-
+ const [allDmnModelNormalizedPosixRelativePaths,
setAllDmnModelNormalizedPosixRelativePaths] = useState<
+ string[] | undefined
+ >(undefined);
const [assetType, setAssetType] = React.useState<"" | "DMN" | "RULE">("");
+ const [callBackError, setCallBackError] = useState<any>(undefined);
const [isAutoFillTableEnabled, setAutoFillTableEnabled] =
React.useState(true);
const [isStatelessSessionRule, setStatelessSessionRule] =
React.useState(false);
const [isTestSkipped, setTestSkipped] = React.useState(false);
const [kieSessionRule, setKieSessionRule] = React.useState("");
const [ruleFlowGroup, setRuleFlowGroup] = React.useState("");
- const testScenarioEditorStoreApi = useTestScenarioEditorStoreApi();
+ const [selectedDmnModel, setSelectedDmnModel] = useState<ExternalDmn |
undefined>(undefined);
+ const [selectedDmnModelPathRelativeToThisScesim,
setSelectedDmnModelPathRelativeToThisScesim] = useState<
+ string | undefined
+ >(undefined);
+
+ const assetsOption = [
+ { value: "", label: i18n.creationPanel.assetsOption.noChoice, disabled:
true },
+ { value: "DMN", label: i18n.creationPanel.assetsOption.dmn, disabled:
false },
+ { value: "RULE", label: i18n.creationPanel.assetsOption.rule, disabled:
false },
+ ];
+
+ /** This callback retrieves all the avaiable DMN files available in the
user's project */
+ useCancelableEffect(
+ useCallback(
+ ({ canceled }) => {
+ onRequestExternalModelsAvailableToInclude?.()
+ .then((dmnModelNormalizedPosixPathRelativePaths) => {
+ console.trace("[TestScenarioCreationPanel] The below external DMN
models have been found");
+ console.trace(dmnModelNormalizedPosixPathRelativePaths);
+
+ if (canceled.get()) {
+ return;
+ }
+ setAllDmnModelNormalizedPosixRelativePaths(
+ dmnModelNormalizedPosixPathRelativePaths.sort((modelA, modelB) =>
+ basename(modelA).localeCompare(basename(modelB))
+ )
+ );
+ })
+ .catch((err) => {
+ setCallBackError(err);
+ console.error(
+ `[TestScenarioCreationPanel] The below error when trying to
retrieve all the External DMN files from the project.`
+ );
+ console.error(err);
+ });
+ },
+ [onRequestExternalModelsAvailableToInclude]
+ )
+ );
+
+ /** This callback return the unmarshalled representation of a DMN model
given its path */
+ useCancelableEffect(
+ useCallback(
+ ({ canceled }) => {
+ if (!selectedDmnModelPathRelativeToThisScesim ||
onRequestExternalModelByPath === undefined) {
+ return;
+ }
+
+ onRequestExternalModelByPath(selectedDmnModelPathRelativeToThisScesim)
+ .then((externalDMNModel) => {
+ console.trace("[TestScenarioCreationPanel] The below external DMN
model have been loaded");
+ console.trace(externalDMNModel);
+
+ if (canceled.get() || !externalDMNModel) {
+ return;
+ }
+
+ setSelectedDmnModel(externalDMNModel);
+ })
+ .catch((err) => {
+ setCallBackError(err);
+ console.error(
+ `[TestScenarioCreationPanel] An error occurred when parsing the
selected model '${selectedDmnModelPathRelativeToThisScesim}'. Please
double-check it is a non-empty valid model.`
+ );
+ console.error(err);
+ });
+ },
+ [onRequestExternalModelByPath, selectedDmnModelPathRelativeToThisScesim]
+ )
+ );
+
+ /* If any error occurs during the execution of useCancelableEffect's
callback, */
+ /* it throws the error that will be catched by the ErrorBoundary.
*/
+ useEffect(() => {
+ if (callBackError) {
+ throw callBackError;
+ }
+ }, [callBackError]);
Review Comment:
What try/catch block? Sorry it seems there are multiple ones. If an error
happens and we do something on the screen to "treat it", I think we shouldn't
re-throw it. Not if it's really an "end of the world" type of error, I think we
should just throw and let the first
[ErrorBoundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary)
catch it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]