Skip to content

Commit

Permalink
feat(ui): Improve UX when configuring MQTT or NTP hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Apr 12, 2023
1 parent fc73347 commit cf982c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion frontend/src/options/connectivity/MQTTConnectivity.tsx
Expand Up @@ -41,7 +41,7 @@ import {
useMQTTStatusQuery
} from "../../api";
import {getIn, setIn} from "../../api/utils";
import {convertBytesToHumans, deepCopy} from "../../utils";
import {convertBytesToHumans, deepCopy, extractHostFromUrl} from "../../utils";
import {InputProps} from "@mui/material/Input/Input";
import LoadingFade from "../../components/LoadingFade";
import InfoBox from "../../components/InfoBox";
Expand Down Expand Up @@ -525,6 +525,9 @@ const MQTTConnectivity = (): JSX.Element => {
helperText="The MQTT Broker hostname"
required={true}
configPath={["connection", "host"]}
inputPostProcessor={(value) => {
return extractHostFromUrl(value);
}}
/>
<MQTTInput
mqttConfiguration={mqttConfiguration}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/options/connectivity/NTPConnectivity.tsx
Expand Up @@ -27,6 +27,7 @@ import {
import InfoBox from "../../components/InfoBox";
import PaperContainer from "../../components/PaperContainer";
import DetailPageHeaderRow from "../../components/DetailPageHeaderRow";
import {extractHostFromUrl} from "../../utils";

const NTPClientStateComponent : React.FunctionComponent<{ state: NTPClientState | undefined, stateLoading: boolean, stateError: boolean }> = ({
state,
Expand Down Expand Up @@ -194,7 +195,7 @@ const NTPConnectivity = (): JSX.Element => {
disabled={!enabled}
variant="standard"
onChange={e => {
setServer(e.target.value);
setServer(extractHostFromUrl(e.target.value));
setConfigurationModified(true);
}}
/>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/utils.ts
Expand Up @@ -233,3 +233,6 @@ export const useGetter = <S>(value: S): (() => S) => {
}, [ref]);
};

export function extractHostFromUrl(value: string): string {
return value.replace(/^[a-zA-Z]+:\/\//, "").replace(/\/.*/g, "");
}

0 comments on commit cf982c0

Please sign in to comment.