Skip to content

Commit 07d9f0a

Browse files
authored
Merge branch 'develop' into 543-s3-uploads
2 parents c1ade8c + 23994ad commit 07d9f0a

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

browser/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This changelog covers all three packages, as they are (for now) updated as a who
1111
- [#771](https://github.com/atomicdata-dev/atomic-server/issues/771) Tables: Don't paste in multiple rows when focussed on an input
1212
- [#758](https://github.com/atomicdata-dev/atomic-server/issues/758) Fix Relation column forms to close when clicking on the searchbox
1313
- [#780](https://github.com/atomicdata-dev/atomic-server/issues/780) Use tags in ontology editor to create enum properties.
14+
- [#810](https://github.com/atomicdata-dev/atomic-server/issues/810) Add button to resource selectors to navigate to the selected resource.
1415
- Fix server not rebuilding client when files changed.
1516
- Added persistent scrollbar to table
1617
- Improved table header UX

browser/data-browser/src/components/forms/SearchBox/SearchBox.tsx

+46-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
1+
import {
2+
MouseEventHandler,
3+
useCallback,
4+
useContext,
5+
useEffect,
6+
useRef,
7+
useState,
8+
} from 'react';
29
import { styled } from 'styled-components';
310
import { removeCachedSearchResults, useResource, useStore } from '@tomic/react';
411
import { DropdownPortalContext } from '../../Dropdown/dropdownContext';
512
import * as RadixPopover from '@radix-ui/react-popover';
613
import { SearchBoxWindow } from './SearchBoxWindow';
7-
import { FaSearch, FaTimes } from 'react-icons/fa';
14+
import { FaExternalLinkAlt, FaSearch, FaTimes } from 'react-icons/fa';
815
import { ErrorChip } from '../ErrorChip';
916
import { useValidation } from '../formValidation/useValidation';
17+
import { constructOpenURL } from '../../../helpers/navigation';
18+
import { useNavigateWithTransition } from '../../../hooks/useNavigateWithTransition';
1019

1120
interface SearchBoxProps {
1221
autoFocus?: boolean;
@@ -37,6 +46,7 @@ export function SearchBox({
3746
onClose,
3847
}: React.PropsWithChildren<SearchBoxProps>): JSX.Element {
3948
const store = useStore();
49+
const navigate = useNavigateWithTransition();
4050
const selectedResource = useResource(value);
4151
const triggerRef = useRef<HTMLButtonElement>(null);
4252
const [inputValue, setInputValue] = useState('');
@@ -111,6 +121,21 @@ export function SearchBox({
111121
setError(undefined);
112122
}, [setError, required, value, selectedResource]);
113123

124+
const openLink =
125+
!value || selectedResource.error
126+
? '#'
127+
: constructOpenURL(selectedResource.getSubject());
128+
129+
const navigateToSelectedResource: MouseEventHandler<HTMLAnchorElement> =
130+
e => {
131+
e.preventDefault();
132+
navigate(openLink);
133+
};
134+
135+
const title = selectedResource.error
136+
? selectedResource.getSubject()
137+
: selectedResource.title;
138+
114139
return (
115140
<RadixPopover.Root open={open}>
116141
<RadixPopover.Anchor>
@@ -133,11 +158,7 @@ export function SearchBox({
133158
}}
134159
>
135160
{value ? (
136-
<ResourceTitle>
137-
{selectedResource.error
138-
? selectedResource.getSubject()
139-
: selectedResource.title}
140-
</ResourceTitle>
161+
<ResourceTitle>{title}</ResourceTitle>
141162
) : (
142163
<>
143164
<FaSearch />
@@ -146,13 +167,24 @@ export function SearchBox({
146167
)}
147168
</TriggerButton>
148169
{value && (
149-
<SearchBoxButton
150-
title='clear'
151-
onClick={() => onChange(undefined)}
152-
type='button'
153-
>
154-
<FaTimes />
155-
</SearchBoxButton>
170+
<>
171+
<SearchBoxButton
172+
as='a'
173+
href={openLink}
174+
title={`go to ${title}`}
175+
onClick={navigateToSelectedResource}
176+
type='button'
177+
>
178+
<FaExternalLinkAlt />
179+
</SearchBoxButton>
180+
<SearchBoxButton
181+
title='clear'
182+
onClick={() => onChange(undefined)}
183+
type='button'
184+
>
185+
<FaTimes />
186+
</SearchBoxButton>
187+
</>
156188
)}
157189
{children}
158190
{error && (

browser/data-browser/src/helpers/navigation.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useSearchParams } from 'react-router-dom';
22
import { paths } from '../routes/paths';
3+
import { unknownSubject } from '@tomic/react';
34

45
/** Constructs a URL string with a route, a query Parameter and a value */
56
function constructURL(
@@ -17,6 +18,10 @@ export function constructOpenURL(
1718
subject: string,
1819
extraParams: Record<string, string> = {},
1920
): string {
21+
if (subject === unknownSubject) {
22+
return '#';
23+
}
24+
2025
const url = new URL(subject);
2126

2227
if (window.location.origin === url.origin) {

0 commit comments

Comments
 (0)