diff --git a/frontend/app/components/Session_/Subheader.js b/frontend/app/components/Session_/Subheader.js index 1a75280aa..7fdb149be 100644 --- a/frontend/app/components/Session_/Subheader.js +++ b/frontend/app/components/Session_/Subheader.js @@ -1,7 +1,7 @@ import React, { useMemo } from 'react'; import { useStore } from 'App/mstore'; import KeyboardHelp from 'Components/Session_/Player/Controls/components/KeyboardHelp'; -import { Icon, Tooltip } from 'UI'; +import { Icon } from 'UI'; import QueueControls from './QueueControls'; import Bookmark from 'Shared/Bookmark'; import SharePopup from '../shared/SharePopup/SharePopup'; @@ -13,8 +13,9 @@ import { connect } from 'react-redux'; import SessionTabs from 'Components/Session/Player/SharedComponents/SessionTabs'; import { IFRAME } from 'App/constants/storageKeys'; import cn from 'classnames'; -import { Switch, Button as AntButton, Popover } from 'antd'; +import { Switch, Button as AntButton, Popover, Tooltip } from 'antd'; import { ShareAltOutlined } from '@ant-design/icons'; +import { checkParam, truncateStringToFit } from 'App/utils'; const localhostWarn = (project) => project + '_localhost_warn'; const disableDevtools = 'or_devtools_uxt_toggle'; @@ -27,6 +28,14 @@ function SubHeader(props) { const { location: currentLocation = 'loading...' } = store.get(); const hasIframe = localStorage.getItem(IFRAME) === 'true'; const { uxtestingStore } = useStore(); + const [hideTools, setHideTools] = React.useState(false); + + React.useEffect(() => { + const hideDevtools = checkParam('hideTools'); + if (hideDevtools) { + setHideTools(true); + } + }, []); const enabledIntegration = useMemo(() => { const { integrations } = props; @@ -37,13 +46,10 @@ function SubHeader(props) { return integrations.some((i) => i.token); }, [props.integrations]); - const location = - currentLocation && currentLocation.length > 140 - ? `${currentLocation.slice(0, 25)}...${currentLocation.slice(-40)}` - : currentLocation; + const locationTruncated = truncateStringToFit(currentLocation, window.innerWidth - 200); const showWarning = - location && /(localhost)|(127.0.0.1)|(0.0.0.0)/.test(location) && showWarningModal; + currentLocation && /(localhost)|(127.0.0.1)|(0.0.0.0)/.test(currentLocation) && showWarningModal; const closeWarning = () => { localStorage.setItem(localhostWarnKey, '1'); setWarning(false); @@ -59,7 +65,7 @@ function SubHeader(props) {
{showWarning ? ( @@ -71,7 +77,7 @@ function SubHeader(props) { left: '50%', bottom: '-24px', transform: 'translate(-50%, 0)', - fontWeight: 500, + fontWeight: 500 }} > Some assets may load incorrectly on localhost. @@ -88,52 +94,57 @@ function SubHeader(props) {
) : null} - -
- - - - {enabledIntegration && } - - - - - - -
- } - /> - {uxtestingStore.isUxt() ? ( - + + {!hideTools && ( +
+ + + + {enabledIntegration && } + + + + + + +
+ } /> - ) : ( -
- -
- )} - + + {uxtestingStore.isUxt() ? ( + + ) : ( +
+ +
+ )} + + )} - {location && ( + + {locationTruncated && (
- - {location} + + {locationTruncated}
@@ -146,5 +157,5 @@ function SubHeader(props) { export default connect((state) => ({ siteId: state.getIn(['site', 'siteId']), integrations: state.getIn(['issues', 'list']), - modules: state.getIn(['user', 'account', 'modules']) || [], + modules: state.getIn(['user', 'account', 'modules']) || [] }))(observer(SubHeader)); diff --git a/frontend/app/components/shared/FetchDetailsModal/components/FetchBasicDetails/FetchBasicDetails.tsx b/frontend/app/components/shared/FetchDetailsModal/components/FetchBasicDetails/FetchBasicDetails.tsx index 94aadfb1d..ef040ea1b 100644 --- a/frontend/app/components/shared/FetchDetailsModal/components/FetchBasicDetails/FetchBasicDetails.tsx +++ b/frontend/app/components/shared/FetchDetailsModal/components/FetchBasicDetails/FetchBasicDetails.tsx @@ -19,10 +19,10 @@ function FetchBasicDetails({ resource, timestamp }: Props) { return (
-
+
Name
-
- {text} +
+ {resource.url}
diff --git a/frontend/app/utils/index.ts b/frontend/app/utils/index.ts index 89e4a49f6..1514b0787 100644 --- a/frontend/app/utils/index.ts +++ b/frontend/app/utils/index.ts @@ -479,4 +479,23 @@ export const checkParam = (paramName: string, storageKey?: string, search?: stri return existsAndTrue; }; -export const isValidUrl = (url) => /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/.test(url); \ No newline at end of file +export const isValidUrl = (url) => /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/.test(url); + +export function truncateStringToFit(string: string, screenWidth: number, charWidth: number = 5): string { + if (string.length * charWidth <= screenWidth) { + return string; + } + + const ellipsis = '...'; + const maxLen = Math.floor(screenWidth / charWidth); + + if (maxLen <= ellipsis.length) { + return ellipsis.slice(0, maxLen); + } + + const frontLen = Math.floor((maxLen - ellipsis.length) / 2); + const backLen = maxLen - ellipsis.length - frontLen; + + return string.slice(0, frontLen) + ellipsis + string.slice(-backLen); +} +