Skip to content

Commit

Permalink
[Synthetics] Prevent location id query param on form (elastic#156661)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored May 5, 2023
1 parent 082c0f6 commit 4b0de66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ interface Props {
name: string;
configId: string;
locationId?: string;
updateUrl?: boolean;
}

export const MonitorDetailsLinkPortal = ({ name, configId, locationId }: Props) => {
export const MonitorDetailsLinkPortal = ({ name, configId, locationId, updateUrl }: Props) => {
return (
<InPortal node={MonitorDetailsLinkPortalNode}>
<MonitorDetailsLink name={name} configId={configId} locationId={locationId} />
<MonitorDetailsLink
name={name}
configId={configId}
locationId={locationId}
updateUrl={updateUrl}
/>
</InPortal>
);
};

export const MonitorDetailsLink = ({ name, configId, locationId }: Props) => {
const selectedLocation = useSelectedLocation();
export const MonitorDetailsLink = ({ name, configId, locationId, updateUrl }: Props) => {
const selectedLocation = useSelectedLocation(updateUrl);

let locId = locationId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const MonitorEditPage: React.FC = () => {
<MonitorDetailsLinkPortal
configId={data?.attributes[ConfigKey.CONFIG_ID]}
name={data?.attributes.name}
updateUrl={false}
/>
</MonitorForm>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { selectSelectedLocationId, setMonitorDetailsLocationAction } from '../../../state';
import { useUrlParams, useLocations } from '../../../hooks';

export const useSelectedLocation = () => {
export const useSelectedLocation = (updateUrl = true) => {
const [getUrlParams, updateUrlParams] = useUrlParams();
const { locations } = useLocations();
const selectedLocationId = useSelector(selectSelectedLocationId);
Expand All @@ -21,15 +21,15 @@ export const useSelectedLocation = () => {
useEffect(() => {
if (!urlLocationId) {
const firstLocationId = locations?.[0]?.id;
if (firstLocationId) {
if (firstLocationId && updateUrl) {
updateUrlParams({ locationId: firstLocationId }, true);
}
}

if (urlLocationId && selectedLocationId !== urlLocationId) {
dispatch(setMonitorDetailsLocationAction(urlLocationId));
}
}, [dispatch, updateUrlParams, locations, urlLocationId, selectedLocationId]);
}, [dispatch, updateUrlParams, locations, urlLocationId, selectedLocationId, updateUrl]);

return useMemo(
() => locations.find((loc) => loc.id === urlLocationId) ?? null,
Expand Down

0 comments on commit 4b0de66

Please sign in to comment.