"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useLocationName = useLocationName; var _react = require("react"); var _reactRedux = require("react-redux"); var _state = require("../state"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ function useLocationName({ locationId }) { const dispatch = (0, _reactRedux.useDispatch)(); const { locationsLoaded, locations } = (0, _reactRedux.useSelector)(_state.selectServiceLocationsState); (0, _react.useEffect)(() => { if (!locationsLoaded) { dispatch((0, _state.getServiceLocations)()); } }); return (0, _react.useMemo)(() => { if (!locationsLoaded) { return undefined; } else { return locations.find(location => location.id === locationId); } }, [locationsLoaded, locations, locationId]); }