Repository navigation
OpenConceptLab/ocl_issues#3039 | Restore the "View in TBv2" chip #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paynejd
wants to merge
4
commits into
main
Choose a base branch
from
OpenConceptLab/ocl_issues#3039-view-in-tbv2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+255
−11
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff84b8e
closes OpenConceptLab/ocl_issues#3039 | Restore the "View in TBv2" chip
paynejd ead9b7c
OpenConceptLab/ocl_issues#3039 | Keep an unversioned expansion by nam…
paynejd aace199
OpenConceptLab/ocl_issues#3039 | Drop the logo's unused size prop and…
paynejd eb0bc3d
OpenConceptLab/ocl_issues#3039 | Address review: summary, /orgs/new, …
snyaggarwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,83 @@ | ||
| import { parseRepoPath } from './repoRoute.js' | ||
|
|
||
| const OFFICIAL_ORIGIN = /^https:\/\/app\.(v3\.)?([a-z]+\.)*openconceptlab\.org$/ | ||
|
|
||
| // TBv3 is at app.v3.<env> and TBv2 at app.v2.<env> (OpenConceptLab/ocl_online#236); app.<env> serves one of them. | ||
| // Every one of those hosts shares its environment's API at api.<env>. | ||
| export const toAPIOrigin = origin => origin.replace(/:\/\/app\.(v[23]\.)?/, '://api.') | ||
|
|
||
| export const resolveMapperURL = (configured, origin) => { | ||
| // A configured URL wins. Otherwise an official host links to the same environment's sibling app, and any | ||
| // other deployment has none. | ||
| const resolveSiblingURL = (configured, origin, host) => { | ||
| const url = (configured || '').trim().replace(/\/+$/, '') | ||
| if(url) | ||
| return url | ||
| if(OFFICIAL_ORIGIN.test(origin || '')) | ||
| return origin.replace(/\/\/app\.(v3\.)?/, '//map.') | ||
| return origin.replace(/\/\/app\.(v3\.)?/, `//${host}.`) | ||
| return '' | ||
| } | ||
|
|
||
| export const resolveMapperURL = (configured, origin) => resolveSiblingURL(configured, origin, 'map') | ||
|
|
||
| // app.v2.<env> rather than app.<env>, which serves TBv3 once it becomes the default Term Browser. | ||
| export const resolveTBv2URL = (configured, origin) => resolveSiblingURL(configured, origin, 'app.v2') | ||
|
|
||
| /* | ||
| * TBv2 serves most TBv3 pages at the same path, so moving across is a host swap. Where TBv2 lacks the page, | ||
| * toTBv2Path walks up to the nearest page it has: repository (or version), then owner, then home. | ||
| */ | ||
|
|
||
| // ID_REGEX in constants.js, which this file can't import: its tests run under plain node. | ||
| const ROUTE_ID = /^[a-zA-Z0-9._@-]+$/ | ||
| const isRouteId = segment => Boolean(segment) && ROUTE_ID.test(segment) | ||
|
|
||
| const SHARED_ROOT_PATHS = ['/search', '/imports', '/concepts/compare', '/mappings/compare'] | ||
| const SHARED_OWNER_PATHS = {users: ['settings'], orgs: ['edit']} | ||
| const TBV3_ONLY_OWNER_IDS = ['new'] | ||
| const TBV3_ONLY_REPO_PAGES = ['edit', 'compare-versions'] | ||
| const TBV2_REPO_TABS = { | ||
| sources: ['concepts', 'mappings', 'versions', 'about', 'summary'], | ||
| collections: ['concepts', 'mappings', 'references', 'versions', 'about'], | ||
| } | ||
| const TBV2_RESOURCE_TABS = ['concepts', 'mappings'] | ||
|
|
||
| export const toTBv2Path = path => { | ||
| const pathname = (path || '').split(/[?#]/)[0] | ||
| const segments = pathname.split('/').filter(Boolean) | ||
| const fullPath = '/' + segments.join('/') | ||
|
|
||
| if(SHARED_ROOT_PATHS.includes(fullPath)) | ||
| return fullPath | ||
|
|
||
| const [ownerType, owner, repoType, repo] = segments | ||
|
|
||
| if(!['users', 'orgs'].includes(ownerType) || !isRouteId(owner) || TBV3_ONLY_OWNER_IDS.includes(owner)) | ||
| return '/' | ||
|
|
||
| const ownerHome = `/${ownerType}/${owner}` | ||
|
|
||
| if(segments.length === 3 && SHARED_OWNER_PATHS[ownerType].includes(repoType)) | ||
| return fullPath | ||
|
|
||
| if(!['sources', 'collections'].includes(repoType) || !isRouteId(repo)) | ||
| return ownerHome | ||
|
|
||
| const route = parseRepoPath(pathname) | ||
| const repoHome = `${ownerHome}/${repoType}/${repo}` | ||
|
|
||
| if(TBV3_ONLY_REPO_PAGES.includes(route.version) || (route.version && !isRouteId(route.version))) | ||
| return repoHome | ||
|
|
||
| const base = route.version ? `${repoHome}/${route.version}` : repoHome | ||
|
|
||
| if(!TBV2_REPO_TABS[repoType].includes(route.tab)) | ||
| return base | ||
|
|
||
| if(!TBV2_RESOURCE_TABS.includes(route.tab)) | ||
| return `${base}/${route.tab}` | ||
|
|
||
| const scope = isRouteId(route.expansion) ? `${route.version ? base : `${repoHome}/HEAD`}/expansions/${route.expansion}` : base | ||
| const tabPath = `${scope}/${route.tab}` | ||
|
|
||
| return isRouteId(route.resource) ? `${tabPath}/${route.resource}` : tabPath | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import React from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { useLocation } from 'react-router-dom'; | ||
| import Chip from '@mui/material/Chip'; | ||
| import Tooltip from '@mui/material/Tooltip'; | ||
| import { toTBv2URL } from '../../common/utils'; | ||
| import ClassicOCLLogo from '../common/ClassicOCLLogo'; | ||
|
|
||
| // TBv2's own primary color, so the chip reads as a way into TBv2 (TBv2's "View in TBv3" chip uses TBv3's) | ||
| const V2_PRIMARY = 'rgb(51, 115, 170)'; | ||
|
|
||
| const ClassicTermBrowserButton = () => { | ||
| const { t } = useTranslation(); | ||
| const location = useLocation(); | ||
| const href = toTBv2URL(location.pathname); | ||
|
|
||
| if(!href) | ||
| return null; | ||
|
|
||
| return ( | ||
| <Tooltip title={t('common.back_to_classic_termbrowser')} describeChild arrow> | ||
| <Chip | ||
| variant='outlined' | ||
| clickable | ||
| component='a' | ||
| href={href} | ||
| aria-label={t('common.classic_termbrowser')} | ||
| icon={<ClassicOCLLogo />} | ||
| label={t('common.classic_termbrowser')} | ||
| // The header's right column can't fit the chip beside + and the account button on a phone, nor its | ||
| // label below md, where the tooltip carries it instead. | ||
| sx={{ | ||
| display: {xs: 'none', sm: 'inline-flex'}, | ||
| marginRight: '8px', | ||
| paddingLeft: {sm: '6px', md: '8px'}, | ||
| verticalAlign: 'middle', | ||
| color: V2_PRIMARY, | ||
| borderColor: V2_PRIMARY, | ||
| '.MuiChip-icon': { | ||
| marginRight: {sm: '6px', md: '-6px'} | ||
| }, | ||
| '.MuiChip-label': { | ||
| display: {sm: 'none', md: 'block'}, | ||
| paddingLeft: '6px', | ||
| paddingRight: '8px' | ||
| } | ||
| }} | ||
| /> | ||
| </Tooltip> | ||
| ); | ||
| }; | ||
|
|
||
| export default ClassicTermBrowserButton; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /*eslint spellcheck/spell-checker: 0*/ | ||
| import React from 'react'; | ||
|
|
||
| const CLASSIC_LOGO = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAACshmLzAAAHlUlEQVRYCa1Xa2xUxxX+Zu7dtddev41tDDEmAgsXNQ+3OA3GeF3sNk5bQ+IaRF9K0sRUoqmSP6jKL1SpSf9UVI3UBiq1SVAejcNDShtDw8MlDjEBg0NiiI1AUB42Btavtb2Pe+/0nFnWrJe1SUuOtL73zpyZ851zvnNmLPAVSl1zS4kTMZYqQ2YIYVwaCQW7u97bNjGbCTHb5J3mfE88kWqOpZYrGMsF7HoI40FA3SMMgz7VhBLoUlbkxf27tu6Zaa//GUB185NzUpz0CinUCkepOiFFuZRGliILSjlQjqNtCSEgDQOO4wQc5Ty9v/VPf08G4o4Ampub3X6roFRIe4WSRjUtqBZKLKDNTW2QjSo2n1wYBBxcsiIh34Hd284mapmJA/y96rGNeY6wlxgwaochqg0XKLSuOeSt9pA8h21Hki29bcyxbRima76pXGtp8qVEhWkRqF/7iyoytF4oVENgEYUxTYfWsWf1MnHTxG8KFqXC/sAMnPtBW1tbKH5eR8Dn22y6Cq5tkjB+DSkyOI8cXseZObTxm9zpnXhAKqIi6C0t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gLnxz/nJpPPhF2KcYpLSHSYY58j9YUFeTSujB5KfRafo/9uJ9oiTa0lY2NT2XQbSEqOWkVgfQ86QuMhxaHw2E889M1FOYMYq1E1UP349mfr8OR459hF/WGoZFRFOTn4ic/bCBPle6Ga1fXo27lMmzZ+hYGr/uxuqEGqdQdS+YVEfDFeIDAc8SuXL1G5ObAq7SQkm1TAPr7u5x7yyuLXW6zvvfseQwNjeI7vm+hnup9yaKFuhP+Zftuqm9L9++Tp85ow9+vr0bN8gpq1+nY+tpOdBzpJpKm6oiV3bsA5WWltJ6fCzW5uz/v0+kkBCadDztu0ZxGaps2PkT3yX2UfC/3de7zOdmZGKeSZK+51qPoo2zmsyEnK1P3iyGqHCYwe8nC5wCn4ZYIzano0SyJO84I+eKbdiWbSJWnvUG7j2q6gs4ShCh/V4iUvBH3/nhhIPwbpdY7Mjqm32PGWc+2k5GQQTE4OoQdp9sTMk5PVQEvOvLGy6Nk/BB1Rf7UhrnBxLzWgwl/eI51pnsbXctj039s3GDvx6ktv9TW9nJoGgDe27ZD/6ZJi7ZIMPX/fzIIvh2bppu6ibpGPPrlvh2v6BNxelzJhls5xyzl9FM/v0fdxZ1QG2VvGbdSASqXPht2Ox14rx/ctVWfAzx1GwCvMdI/gsLDdDqui7+AsPKswl5yyNko3X4I+1WbnKHz/0Nb2AedSLCvfferw4l7JI1zfdOGR4Xh3knhSuEjdCaJ5ldSnplUdoj0z0slDilhfagc8dFQnn2xa9u2Wf+BuC0CbCxb+vf6nfzf09H5AnvEt+SYMEHZIAuB8xNdThFf9tF52WGItBN7393ij+l+mWfSCPDCb7S0uLL95jOk8BwZWERsFwSEW/8FOriOSaU+oFthp3vC08ts/jLGkunMCCCmvKrx6UL632oZhCp0LDUgUmT3gdZXLsfm7/b5X8C0XiX7z9h+AAAAAElFTkSuQmCC'; | ||
|
|
||
| const ClassicOCLLogo = () => ( | ||
| <img | ||
| src={CLASSIC_LOGO} | ||
| alt='' | ||
| width={18} | ||
| height={18} | ||
| style={{display: 'block', borderRadius: '3px'}} | ||
| /> | ||
| ); | ||
|
|
||
| export default ClassicOCLLogo; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phone users lose the way back to TBv2. The version that was in production before #89 showed the chip on phones (
maxWidth: {xs: '150px'}). Here it's hidden belowsm, and nothing else in TBv3 links to TBv2, so someone who arrives on a phone from TBv2's "View in TBv3" chip can't get back. An icon-only chip at xs, or an entry in the tray or account menu, would keep it.