From af6be7cff79f007b10fa12b1eeea2a6c5c3809fc Mon Sep 17 00:00:00 2001 From: Jozef Marko Date: Thu, 28 Nov 2024 10:31:33 +0100 Subject: [PATCH] The configuration of Extended Services is not working when a path is included in the URL. Closes: - https://github.com/apache/incubator-kie-tools/issues/2759 - https://github.com/apache/incubator-kie-tools/issues/2670 - https://github.com/apache/incubator-kie-issues/issues/387 --- .../ExtendedServicesContextProvider.tsx | 21 ++++------ .../ExtendedServicesModal.tsx | 26 ++++++------ packages/online-editor/src/i18n/locales/de.ts | 2 +- packages/online-editor/src/i18n/locales/en.ts | 2 +- .../settings/ExtendedServicesSettingsTab.tsx | 42 +++++-------------- .../src/settings/SettingsContext.tsx | 17 +++----- 6 files changed, 39 insertions(+), 71 deletions(-) diff --git a/packages/online-editor/src/extendedServices/ExtendedServicesContextProvider.tsx b/packages/online-editor/src/extendedServices/ExtendedServicesContextProvider.tsx index f1e1d406d9a..b36df035c58 100644 --- a/packages/online-editor/src/extendedServices/ExtendedServicesContextProvider.tsx +++ b/packages/online-editor/src/extendedServices/ExtendedServicesContextProvider.tsx @@ -25,6 +25,7 @@ import { ExtendedServicesClient } from "./ExtendedServicesClient"; import { DependentFeature, ExtendedServicesContext } from "./ExtendedServicesContext"; import { ExtendedServicesModal } from "./ExtendedServicesModal"; import { ExtendedServicesStatus } from "./ExtendedServicesStatus"; +import { useEnv } from "../env/hooks/EnvContext"; interface Props { children: React.ReactNode; @@ -38,20 +39,17 @@ export function ExtendedServicesContextProvider(props: Props) { const [isModalOpen, setModalOpen] = useState(false); const [installTriggeredBy, setInstallTriggeredBy] = useState(undefined); const [outdated, setOutdated] = useState(false); + const { env } = useEnv(); const config = useMemo(() => { try { - const url = new URL(settings.extendedServices.host); - const port = settings.extendedServices.port; - if (port) { - url.port = port; - } + const url = new URL(settings.extendedServices.href); - return new ExtendedServicesConfig(url.href, url.port); + return new ExtendedServicesConfig(url.href); } catch (error) { - return new ExtendedServicesConfig(settings.extendedServices.host ?? "", settings.extendedServices.port ?? ""); + return new ExtendedServicesConfig(env.KIE_SANDBOX_EXTENDED_SERVICES_URL); } - }, [settings.extendedServices.port, settings.extendedServices.host]); + }, [settings.extendedServices.href]); const bridge = useMemo(() => new ExtendedServicesBridge(config.url.ping), [config]); const version = useMemo(() => process.env.WEBPACK_REPLACE__extendedServicesCompatibleVersion ?? "0.0.0", []); @@ -117,15 +115,12 @@ export function ExtendedServicesContextProvider(props: Props) { ); } export class ExtendedServicesConfig { - constructor( - public readonly href: string, - public readonly port: string - ) {} + constructor(public readonly href: string) {} public get url() { return { jitExecutor: `${this.href}`, - ping: `${this.href.endsWith("/") ? this.href : this.href + ":" + this.port + "/"}ping`, + ping: `${this.href.endsWith("/") ? this.href : this.href + "/"}ping`, }; } } diff --git a/packages/online-editor/src/extendedServices/ExtendedServicesModal.tsx b/packages/online-editor/src/extendedServices/ExtendedServicesModal.tsx index e1ea349bcd7..d0847e18962 100644 --- a/packages/online-editor/src/extendedServices/ExtendedServicesModal.tsx +++ b/packages/online-editor/src/extendedServices/ExtendedServicesModal.tsx @@ -261,7 +261,7 @@ export function ExtendedServicesModal() { /Applications/KIE\ Tooling\ Extended\ Services.app/Contents/MacOs/kogito -p{" "} - {extendedServices.config.port} + {extendedServices.config.href}
@@ -276,7 +276,7 @@ export function ExtendedServicesModal() { i18n, extendedServices.outdated, extendedServices.status, - extendedServices.config.port, + extendedServices.config.href, downloadExtendedServicesUrl, KIE_SANDBOX_EXTENDED_SERVICES_MACOS_DMG, KIE_SANDBOX_EXTENDED_SERVICES_MACOS_APP, @@ -421,7 +421,7 @@ export function ExtendedServicesModal() { "kie-sandbox-extended-services_windows_{extendedServices.version}.exe" -p{" "} - {extendedServices.config.port} + {new URL(extendedServices.config.href).port}
@@ -437,7 +437,7 @@ export function ExtendedServicesModal() { extendedServices.outdated, extendedServices.status, extendedServices.version, - extendedServices.config.port, + extendedServices.config.href, downloadExtendedServicesUrl, KIE_SANDBOX_EXTENDED_SERVICES_WINDOWS_EXE, ] @@ -576,7 +576,7 @@ export function ExtendedServicesModal() {
- ./kie-sandbox-extended-services -p {extendedServices.config.port} + ./kie-sandbox-extended-services -p {new URL(extendedServices.config.href).port}
@@ -590,7 +590,7 @@ export function ExtendedServicesModal() { i18n, extendedServices.outdated, extendedServices.status, - extendedServices.config.port, + extendedServices.config.href, downloadExtendedServicesUrl, KIE_SANDBOX_EXTENDED_SERVICES_LINUX_TAG_GZ, KIE_SANDBOX_EXTENDED_SERVICES_BINARIES, @@ -856,12 +856,14 @@ function ExtendedServicesPortForm() { const settingsDispatch = useSettingsDispatch(); const { i18n } = useOnlineI18n(); + const configPort = new URL(config.href).port; + return ( <> {config.port}, + port: {configPort}, }} > {i18n.dmnRunner.modal.wizard.advancedSettings.title} @@ -873,18 +875,18 @@ function ExtendedServicesPortForm() { fieldId={"extended-services-port"} label={i18n.dmnRunner.modal.wizard.advancedSettings.label} validated={ - config.port === "" || parseInt(config.port, 10) < 0 || parseInt(config.port, 10) > 65353 - ? "error" - : "success" + configPort === "" || parseInt(configPort, 10) < 0 || parseInt(configPort, 10) > 65353 ? "error" : "success" } helperTextInvalid={i18n.dmnRunner.modal.wizard.advancedSettings.helperTextInvalid} > settingsDispatch.set((settings) => { - settings.extendedServices.port = `${value}`; + const newConfigUrl = new URL(config.href); + newConfigUrl.port = value; + settings.extendedServices.href = newConfigUrl.href; }) } /> diff --git a/packages/online-editor/src/i18n/locales/de.ts b/packages/online-editor/src/i18n/locales/de.ts index 9459a886b98..b395c8f5d76 100644 --- a/packages/online-editor/src/i18n/locales/de.ts +++ b/packages/online-editor/src/i18n/locales/de.ts @@ -577,7 +577,7 @@ export const de: OnlineI18n = { advancedSettings: { title: [ `Der Standard-Port von ${de_common.names.extendedServices} ist `, - wrapped("port"), + "21345", `. Wenn Sie diesen Port bereits für eine andere Anwendung verwenden, können Sie den Port, der für die Verbindung mit ${de_common.names.extendedServices} verwendet wird, ändern.`, ], label: " Port", diff --git a/packages/online-editor/src/i18n/locales/en.ts b/packages/online-editor/src/i18n/locales/en.ts index a616e593f67..2326a988bf5 100644 --- a/packages/online-editor/src/i18n/locales/en.ts +++ b/packages/online-editor/src/i18n/locales/en.ts @@ -561,7 +561,7 @@ export const en: OnlineI18n = { advancedSettings: { title: [ `The default ${en_common.names.extendedServices} port is `, - wrapped("port"), + "21345", `. If you're already using this port for another application, you can change the port used to connect with the ${en_common.names.extendedServices}.`, ], label: "Port", diff --git a/packages/online-editor/src/settings/ExtendedServicesSettingsTab.tsx b/packages/online-editor/src/settings/ExtendedServicesSettingsTab.tsx index e0c2ffe28f1..d1704a9a162 100644 --- a/packages/online-editor/src/settings/ExtendedServicesSettingsTab.tsx +++ b/packages/online-editor/src/settings/ExtendedServicesSettingsTab.tsx @@ -33,18 +33,16 @@ export function ExtendedServicesSettingsTab() { const { settings } = useSettings(); const settingsDispatch = useSettingsDispatch(); const extendedServices = useExtendedServices(); - const [host, setHost] = useState(settings.extendedServices.host); - const [port, setPort] = useState(settings.extendedServices.port); + const [href, setHref] = useState(settings.extendedServices.href); const onSubmit = useCallback( (e: any) => { e.preventDefault(); settingsDispatch.set((settings) => { - settings.extendedServices.host = host; - settings.extendedServices.port = port; + settings.extendedServices.href = href; }); }, - [host, port, settingsDispatch] + [href, settingsDispatch] ); return ( @@ -75,38 +73,18 @@ export function ExtendedServicesSettingsTab() { isRequired={true} helperTextInvalid={""} validated={"default"} - label={"Host"} - fieldId={"host-input"} + label={"Href"} + fieldId={"href-input"} > - - - - - diff --git a/packages/online-editor/src/settings/SettingsContext.tsx b/packages/online-editor/src/settings/SettingsContext.tsx index d9b58c0658a..e8a5fb1e6e6 100644 --- a/packages/online-editor/src/settings/SettingsContext.tsx +++ b/packages/online-editor/src/settings/SettingsContext.tsx @@ -29,12 +29,8 @@ import { useEnv } from "../env/hooks/EnvContext"; import { QueryParams } from "../navigation/Routes"; import { useQueryParams } from "../queryParams/QueryParamsContext"; import { SettingsTabs } from "./SettingsModalBody"; -import { getCookie } from "../cookies"; import { useEditorEnvelopeLocator } from "../envelopeLocator/hooks/EditorEnvelopeLocatorContext"; -export const EXTENDED_SERVICES_HOST_COOKIE_NAME = "kie-tools-COOKIE__kie-sandbox-extended-services--host"; -export const EXTENDED_SERVICES_PORT_COOKIE_NAME = "kie-tools-COOKIE__kie-sandbox-extended-services--port"; - export type SettingsContextType = { settings: { version: number; @@ -42,8 +38,7 @@ export type SettingsContextType = { url: string; }; extendedServices: { - host: string; - port: string; + href: string; }; editors: { useLegacyDmnEditor: boolean; @@ -144,10 +139,9 @@ export function SettingsContextProvider(props: PropsWithChildren<{}>) { const envExtendedServicesUrl = new URL(env.KIE_SANDBOX_EXTENDED_SERVICES_URL); // 0.0.0.0 is "equivalent" to localhost, but browsers don't like having mixed http/https urls with the exception of localhost - const envExtendedServicesHost = `${envExtendedServicesUrl.protocol}//${ - envExtendedServicesUrl.hostname === "0.0.0.0" ? "localhost" : envExtendedServicesUrl.hostname - }`; - const envExtendedServicesPort = envExtendedServicesUrl.port; + if (envExtendedServicesUrl.hostname === "0.0.0.0") { + envExtendedServicesUrl.hostname = "localhost"; + } await persistSettings({ version: SETTINGS_FILE_LATEST_VERSION, @@ -155,8 +149,7 @@ export function SettingsContextProvider(props: PropsWithChildren<{}>) { url: env.KIE_SANDBOX_CORS_PROXY_URL, }, extendedServices: { - host: getCookie(EXTENDED_SERVICES_HOST_COOKIE_NAME) ?? envExtendedServicesHost, - port: getCookie(EXTENDED_SERVICES_PORT_COOKIE_NAME) ?? envExtendedServicesPort, + href: envExtendedServicesUrl.href, }, editors: { useLegacyDmnEditor: false,