This is an automated email from the ASF dual-hosted git repository.

rantunes pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/incubator-kie-tools-temporary-rnd-do-not-use.git

commit 097dc96e2069bd10b8d0a8cde05b028cc993d0b2
Author: Fabrizio Antonangeli <[email protected]>
AuthorDate: Tue Nov 14 11:23:49 2023 +0100

    KOGITO-9925: Workflow definition endpoints double the last slash (#2048)
---
 .../url/removeTrailingSlashFromUrl.test.ts         | 33 ++++++++++++++++++++++
 .../settings/runtimeTools/RuntimeToolsSettings.tsx | 24 +++++++++++-----
 .../serverless-logic-web-tools/src/url/index.ts    | 28 ++++++++++++++++++
 3 files changed, 78 insertions(+), 7 deletions(-)

diff --git 
a/packages/serverless-logic-web-tools/src/__tests__/url/removeTrailingSlashFromUrl.test.ts
 
b/packages/serverless-logic-web-tools/src/__tests__/url/removeTrailingSlashFromUrl.test.ts
new file mode 100644
index 0000000000..cc08186d56
--- /dev/null
+++ 
b/packages/serverless-logic-web-tools/src/__tests__/url/removeTrailingSlashFromUrl.test.ts
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+import { removeTrailingSlashFromUrl } from "../../url";
+
+describe("removeTrailingSlash", () => {
+  it.each([
+    ["http://example.com/";, "http://example.com";],
+    ["https://example.com/";, "https://example.com";],
+    ["https://example.com";, "https://example.com";],
+    ["https://example.com/graphql";, "https://example.com/graphql";],
+    ["https://example.com/dir/";, "https://example.com/dir";],
+    ["https://example.com/dir/test";, "https://example.com/dir/test";],
+  ])("should remove trailing slash from URL", (inputUrl, expectedUrl) => {
+    expect(removeTrailingSlashFromUrl(inputUrl)).toBe(expectedUrl);
+  });
+});
diff --git 
a/packages/serverless-logic-web-tools/src/settings/runtimeTools/RuntimeToolsSettings.tsx
 
b/packages/serverless-logic-web-tools/src/settings/runtimeTools/RuntimeToolsSettings.tsx
index f0666758a6..111758b4b0 100644
--- 
a/packages/serverless-logic-web-tools/src/settings/runtimeTools/RuntimeToolsSettings.tsx
+++ 
b/packages/serverless-logic-web-tools/src/settings/runtimeTools/RuntimeToolsSettings.tsx
@@ -18,7 +18,6 @@
  */
 
 import React from "react";
-import { QuickStartContext, QuickStartContextValues } from 
"@patternfly/quickstarts";
 import { Button, ButtonVariant } from 
"@patternfly/react-core/dist/js/components/Button";
 import { EmptyState, EmptyStateBody, EmptyStateIcon } from 
"@patternfly/react-core/dist/js/components/EmptyState";
 import { ActionGroup, Form, FormGroup } from 
"@patternfly/react-core/dist/js/components/Form";
@@ -26,17 +25,24 @@ import { InputGroup, InputGroupText } from 
"@patternfly/react-core/dist/js/compo
 import { Modal, ModalVariant } from 
"@patternfly/react-core/dist/js/components/Modal";
 import { PageSection } from "@patternfly/react-core/dist/js/components/Page";
 import { Popover } from "@patternfly/react-core/dist/js/components/Popover";
-import { Text, TextContent, TextVariants } from 
"@patternfly/react-core/dist/js/components/Text";
+import { Text, TextContent } from 
"@patternfly/react-core/dist/js/components/Text";
 import { TextInput } from 
"@patternfly/react-core/dist/js/components/TextInput";
 import { AddCircleOIcon } from 
"@patternfly/react-icons/dist/js/icons/add-circle-o-icon";
 import { CheckCircleIcon } from 
"@patternfly/react-icons/dist/js/icons/check-circle-icon";
 import HelpIcon from "@patternfly/react-icons/dist/js/icons/help-icon";
 import { TimesIcon } from "@patternfly/react-icons/dist/js/icons/times-icon";
-import { useCallback, useContext, useMemo, useState } from "react";
+import { useCallback, useMemo, useState } from "react";
 import { useSettings, useSettingsDispatch } from "../SettingsContext";
 import { SettingsPageContainer } from "../SettingsPageContainer";
 import { SettingsPageProps } from "../types";
-import { EMPTY_CONFIG, isRuntimeToolsConfigValid, resetConfigCookie, 
saveConfigCookie } from "./RuntimeToolsConfig";
+import {
+  EMPTY_CONFIG,
+  RuntimeToolsSettingsConfig,
+  isRuntimeToolsConfigValid,
+  resetConfigCookie,
+  saveConfigCookie,
+} from "./RuntimeToolsConfig";
+import { removeTrailingSlashFromUrl } from "../../url";
 
 const PAGE_TITLE = "Runtime Tools";
 
@@ -45,7 +51,6 @@ export function RuntimeToolsSettings(props: 
SettingsPageProps) {
   const settingsDispatch = useSettingsDispatch();
   const [config, setConfig] = useState(settings.runtimeTools.config);
   const [isModalOpen, setIsModalOpen] = useState(false);
-  const qsContext = useContext<QuickStartContextValues>(QuickStartContext);
 
   const handleModalToggle = useCallback(() => {
     setIsModalOpen((prevIsModalOpen) => !prevIsModalOpen);
@@ -79,8 +84,13 @@ export function RuntimeToolsSettings(props: 
SettingsPageProps) {
   }, [settingsDispatch.runtimeTools]);
 
   const onApply = useCallback(() => {
-    settingsDispatch.runtimeTools.setConfig(config);
-    saveConfigCookie(config);
+    const newConfig: RuntimeToolsSettingsConfig = {
+      dataIndexUrl: removeTrailingSlashFromUrl(config.dataIndexUrl),
+      kogitoServiceUrl: removeTrailingSlashFromUrl(config.kogitoServiceUrl),
+    };
+    setConfig(newConfig);
+    settingsDispatch.runtimeTools.setConfig(newConfig);
+    saveConfigCookie(newConfig);
   }, [config, settingsDispatch.runtimeTools]);
 
   return (
diff --git a/packages/serverless-logic-web-tools/src/url/index.ts 
b/packages/serverless-logic-web-tools/src/url/index.ts
new file mode 100644
index 0000000000..be6c6a1b06
--- /dev/null
+++ b/packages/serverless-logic-web-tools/src/url/index.ts
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+/**
+ * Remove the trailing slash from an URL if it exists.
+ *
+ * @param url -
+ * @returns
+ */
+export function removeTrailingSlashFromUrl(url: string): string {
+  return url.replace(/\/$/, "");
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to