Skip to content

Commit

Permalink
Merge branch 'main' into feat/548-hide-elements-api
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-mayrgundter committed Apr 11, 2023
2 parents 5e40c3d + 04a8a22 commit 446f374
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 42 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "bldrs",
"version": "1.0.0-r661",
"version": "1.0.0-r767",
"main": "src/index.jsx",
"license": "MIT",
Expand Down Expand Up @@ -33,10 +34,10 @@
"@bldrs-ai/ifclib": "^5.3.3",
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@iconscout/react-unicons": "^2.0.0",
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@iconscout/react-unicons": "^2.0.0",
"@mui/icons-material": "^5.11.9",
"@mui/lab": "^5.0.0-alpha.95",
"@mui/material": "^5.9.2",
Expand All @@ -45,7 +46,6 @@
"@octokit/rest": "^19.0.3",
"@sentry/react": "^7.31.1",
"@sentry/tracing": "^7.31.1",
"canvas": "^2.11.0",
"clsx": "^1.2.1",
"material-ui-popup-state": "^5.0.4",
"matrix-widget-api": "^1.1.1",
Expand Down Expand Up @@ -87,6 +87,7 @@
"@types/three": "^0.146.0",
"babel-jest": "^28.1.3",
"babel-loader": "^8.2.5",
"canvas": "^2.11.0",
"cypress": "^12.3.0",
"cypress-real-events": "^1.7.6",
"esbuild": "^0.15.5",
Expand Down
20 changes: 6 additions & 14 deletions src/BaseRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {useEffect} from 'react'
import {Outlet, Route, Routes, useLocation, useNavigate} from 'react-router-dom'
import ShareRoutes from './ShareRoutes'
import debug from './utils/debug'
import {navWith} from './utils/navigate'
import {useAuth0} from '@auth0/auth0-react'
import useStore from './store/useStore'
import * as Sentry from '@sentry/react'
Expand All @@ -26,7 +27,7 @@ const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes)
*/
export default function BaseRoutes({testElt = null}) {
const location = useLocation()
const navigation = useNavigate()
const navigate = useNavigate()
const installPrefix = window.location.pathname.startsWith('/Share') ? '/Share' : ''
const basePath = `${installPrefix }/`
const {isLoading, isAuthenticated, getAccessTokenSilently} = useAuth0()
Expand All @@ -35,18 +36,9 @@ export default function BaseRoutes({testElt = null}) {
useEffect(() => {
if (location.pathname === installPrefix ||
location.pathname === basePath) {
debug().log('BaseRoutes#useEffect[], forwarding to: ', `${installPrefix }/share`)

let targetURL = `${installPrefix}/share`
if (location.search !== '') {
targetURL += location.search
}

if (location.hash !== '') {
targetURL += location.hash
}

navigation(targetURL)
const fwdPath = `${installPrefix}/share`
debug().log('BaseRoutes#useEffect[], forwarding to: ', fwdPath)
navWith(navigate, fwdPath)
}

if (process.env.NODE_ENV === 'development' && process.env.GITHUB_API_TOKEN) {
Expand All @@ -65,7 +57,7 @@ export default function BaseRoutes({testElt = null}) {
}
})
}
}, [basePath, installPrefix, location, navigation, getAccessTokenSilently, isAuthenticated, isLoading, setAccessToken])
}, [basePath, installPrefix, location, navigate, getAccessTokenSilently, isAuthenticated, isLoading, setAccessToken])

return (
<SentryRoutes>
Expand Down
15 changes: 11 additions & 4 deletions src/Components/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Paper from '@mui/material/Paper'
import useTheme from '@mui/styles/useTheme'
import {looksLikeLink, githubUrlOrPathToSharePath} from '../ShareRoutes'
import debug from '../utils/debug'
import {navWithSearchParamRemoved} from '../utils/navigate'
import {handleBeforeUnload} from '../utils/event'
import OpenModelControl from './OpenModelControl'
import {TooltipIconButton} from './Buttons'
Expand Down Expand Up @@ -39,13 +40,13 @@ export default function SearchBar({fileOpen}) {
debug().log('SearchBar#useEffect[searchParams]')
if (location.search) {
if (validSearchQuery(searchParams)) {
const newInputText = searchParams.get('q')
const newInputText = searchParams.get(QUERY_PARAM)
if (inputText !== newInputText) {
setInputText(newInputText)
}
} else {
window.removeEventListener('beforeunload', handleBeforeUnload)
navigate(location.pathname)
navWithSearchParamRemoved(navigate, location.pathname, QUERY_PARAM)
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -135,6 +136,7 @@ export default function SearchBar({fileOpen}) {
onClick={() => {
setInputText('')
setError('')
navWithSearchParamRemoved(navigate, location.pathname, QUERY_PARAM)
}}
icon={<ClearIcon/>}
/>
Expand All @@ -156,6 +158,10 @@ export default function SearchBar({fileOpen}) {
}


/** @type {string} */
export const QUERY_PARAM = 'q'


/**
* Return true for paths like
*
Expand All @@ -178,11 +184,12 @@ export function containsIfcPath(location) {
/**
* Returns true iff searchParams query is defined with a string value.
*
* @param {object} searchParams Object with a 'q' parameter and optional string value.
* @param {object} searchParams Object with a QUERY_PARAM(default='q') parameter
* present and optional string value.
* @return {boolean}
*/
export function validSearchQuery(searchParams) {
const value = searchParams.get('q')
const value = searchParams.get(QUERY_PARAM)
return value !== null && value.length > 0
}

Expand Down
10 changes: 4 additions & 6 deletions src/Containers/CadView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import {IfcViewerAPIExtended} from '../Infrastructure/IfcViewerAPIExtended'
import * as Privacy from '../privacy/Privacy'
import debug from '../utils/debug'
import useStore from '../store/useStore'
import {getDownloadURL, parseGitHubRepositoryURL} from '../utils/GitHub'
import {computeElementPathIds, setupLookupAndParentLinks} from '../utils/TreeUtils'
import {assertDefined} from '../utils/assert'
import {handleBeforeUnload} from '../utils/event'
import {getDownloadURL, parseGitHubRepositoryURL} from '../utils/GitHub'
import {navWith} from '../utils/navigate'
import SearchIndex from './SearchIndex'
import {usePlaceMark} from '../hooks/usePlaceMark'
import {getAllHashParams} from '../utils/location'


/**
Expand Down Expand Up @@ -429,7 +429,7 @@ export default function CadView({
resetState()
const repoFilePath = modelPath.gitpath ? modelPath.getRepoPath() : modelPath.filepath
window.removeEventListener('beforeunload', handleBeforeUnload)
navigate(`${pathPrefix}${repoFilePath}`)
navWith(navigate, `${pathPrefix}${repoFilePath}`, {search: '', hash: ''})
}

/**
Expand All @@ -452,9 +452,7 @@ export default function CadView({
const pathIds = getPathIdsForElements(lastId)
const repoFilePath = modelPath.gitpath ? modelPath.getRepoPath() : modelPath.filepath
const path = pathIds.join('/')
const curHashParams = getAllHashParams()
debug().log('CadView#selectItemsInScene: curHashParams: ', curHashParams)
navigate(`${pathPrefix}${repoFilePath}/${path}#${curHashParams}`)
navWith(navigate, `${pathPrefix}${repoFilePath}/${path}`, {search: '', hash: ''})
}
} catch (e) {
// IFCjs will throw a big stack trace if there is not a visual
Expand Down
19 changes: 12 additions & 7 deletions src/Share.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {useNavigate, useParams} from 'react-router-dom'
import CssBaseline from '@mui/material/CssBaseline'
import {ThemeProvider} from '@mui/material/styles'
import Styles from './Styles'
import {CAMERA_PREFIX} from './Components/CameraControl'
import CadView, {searchIndex} from './Containers/CadView'
import WidgetApi from './WidgetApi/WidgetApi'
import useStore from './store/useStore'
import useShareTheme from './theme/Theme'
import debug from './utils/debug'
import {navWith} from './utils/navigate'
import {handleBeforeUnload} from './utils/event'


Expand Down Expand Up @@ -47,8 +49,8 @@ export default function Share({installPrefix, appPrefix, pathPrefix}) {
return
}
if (modelPath === null ||
(modelPath.filepath && modelPath.filepath !== mp.filepath) ||
(modelPath.gitpath && modelPath.gitpath !== mp.gitpath)) {
(modelPath.filepath && modelPath.filepath !== mp.filepath) ||
(modelPath.gitpath && modelPath.gitpath !== mp.gitpath)) {
setModelPath(mp)
debug().log('Share#onChangeUrlParams: new model path: ', mp)
}
Expand Down Expand Up @@ -96,11 +98,14 @@ export function navToDefault(navigate, appPrefix) {
// TODO: probe for index.ifc
const mediaSizeTabletWith = 900
window.removeEventListener('beforeunload', handleBeforeUnload)
if (window.innerWidth <= mediaSizeTabletWith) {
navigate(`${appPrefix}/v/p/index.ifc#c:-150.147,-85.796,167.057,-32.603,17.373,-1.347`)
} else {
navigate(`${appPrefix}/v/p/index.ifc#c:-119.076,0.202,83.165,-44.967,19.4,-4.972`)
}
const defaultPath = `${appPrefix}/v/p/index.ifc${location.query || ''}`
const cameraHash = window.innerWidth > mediaSizeTabletWith ?
`#${CAMERA_PREFIX}:-150.147,-85.796,167.057,-32.603,17.373,-1.347` :
`#${CAMERA_PREFIX}:-119.076,0.202,83.165,-44.967,19.4,-4.972`
navWith(navigate, defaultPath, {
search: location.search,
hash: cameraHash,
})
}


Expand Down
46 changes: 46 additions & 0 deletions src/utils/navigate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Helper for calling navigate that will append search query to path,
* if present, before appending an optional hash.
*
* Either search or hash may be passed as null|undefined, but if they
* are present must either be the empty string or start with their
* standard delimeter.
*
* @param {Function} navigate
* @param {string} path
* @param {object} options
*/
export function navWith(navigate, path, options = {
search: location.search,
hash: location.hash,
}) {
const search = options.search || ''
if (search !== '' && !search.startsWith('?')) {
throw new Error(`Given search must start with ? Got: ${search}`)
}
const hash = options.hash || ''
if (hash !== '' && !hash.startsWith('#')) {
throw new Error(`Given hash must start with # Got: ${hash}`)
}
navigate(`${path}${search}${hash}`)
}


/**
* Helper for calling navigate that will remove a named parameter from search.
*
* @param {Function} navigate
* @param {string} path
* @param {string} paramName
*/
export function navWithSearchParamRemoved(navigate, path, paramName) {
if (typeof(paramName) !== 'string' || paramName.length < 1) {
throw new Error(`Must provide a non-empty string param name. Got "${paramName}"`)
}
const sp = new URLSearchParams(location.search)
sp.delete(paramName)
navWith(navigate, path, {
search: `?${sp.toString()}`,
hash: location.hash,
})
}
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,7 @@ abab@^2.0.6:

abbrev@1:
version "1.1.1"
resolved "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==

accepts@~1.3.4, accepts@~1.3.8:
Expand Down Expand Up @@ -8288,28 +8288,28 @@ minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.6:
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==

minipass@^3.0.0:
version "3.3.4"
resolved "https://registry.npmjs.org/minipass/-/minipass-3.3.4.tgz"
integrity sha512-I9WPbWHCGu8W+6k1ZiGpPu0GkoKBeorkfKNuAFBNS1HNFJvke82sxvI5bzcCNpWPorkOO5QQ+zomzzwRxejXiw==
version "3.3.6"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.3.6.tgz#7bba384db3a1520d18c9c0e5251c3444e95dd94a"
integrity sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==
dependencies:
yallist "^4.0.0"

minipass@^4.0.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.0.tgz#4bf124d8c87c14e99846f9a27c3219d956998c0e"
integrity sha512-ExlilAIS7zJ2EWUMaVXi14H+FnZ18kr17kFkGemMqBx6jW0m8P6XfqwYVPEG53ENlgsED+alVP9ZxC3JzkK23Q==
version "4.2.5"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.5.tgz#9e0e5256f1e3513f8c34691dd68549e85b2c8ceb"
integrity sha512-+yQl7SX3bIT83Lhb4BVorMAHVuqsskxRdlmO9kTpyukp8vsm2Sn/fUOV9xlnG8/a5JsypJzap21lz/y3FBMJ8Q==

minizlib@^2.1.1:
version "2.1.2"
resolved "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz"
resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-2.1.2.tgz#e90d3466ba209b932451508a11ce3d3632145931"
integrity sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==
dependencies:
minipass "^3.0.0"
yallist "^4.0.0"

mkdirp@^1.0.3:
version "1.0.4"
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mri@^1.1.0:
Expand Down

0 comments on commit 446f374

Please sign in to comment.