Skip to content

Commit

Permalink
KOGITO-9925: Workflow definition endpoints double the last slash (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
fantonangeli authored Nov 14, 2023
1 parent 0f5b37a commit 097dc96
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,31 @@
*/

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";
import { InputGroup, InputGroupText } from "@patternfly/react-core/dist/js/components/InputGroup";
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";

Expand All @@ -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);
Expand Down Expand Up @@ -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 (
Expand Down
28 changes: 28 additions & 0 deletions packages/serverless-logic-web-tools/src/url/index.ts
Original file line number Diff line number Diff line change
@@ -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(/\/$/, "");
}

0 comments on commit 097dc96

Please sign in to comment.