Allow search results to be opened in a new tab (#7500)

- Respond to "ctrl" or "shift" presses in search drawer
- Keep drawer open in this condition
This commit is contained in:
Oliver 2024-06-24 10:31:11 +10:00 committed by GitHub
parent c2a755e3bd
commit b58430b7f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,6 +33,7 @@ import { api } from '../../App';
import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { ModelType } from '../../enums/ModelType'; import { ModelType } from '../../enums/ModelType';
import { UserRoles } from '../../enums/Roles'; import { UserRoles } from '../../enums/Roles';
import { navigateToLink } from '../../functions/navigation';
import { apiUrl } from '../../states/ApiState'; import { apiUrl } from '../../states/ApiState';
import { useUserSettingsState } from '../../states/SettingsState'; import { useUserSettingsState } from '../../states/SettingsState';
import { useUserState } from '../../states/UserState'; import { useUserState } from '../../states/UserState';
@ -58,7 +59,7 @@ function QueryResultGroup({
}: { }: {
query: SearchQuery; query: SearchQuery;
onRemove: (query: ModelType) => void; onRemove: (query: ModelType) => void;
onResultClick: (query: ModelType, pk: number) => void; onResultClick: (query: ModelType, pk: number, event: any) => void;
}) { }) {
if (query.results.count == 0) { if (query.results.count == 0) {
return null; return null;
@ -92,7 +93,9 @@ function QueryResultGroup({
<Stack> <Stack>
{query.results.results.map((result: any) => ( {query.results.results.map((result: any) => (
<Anchor <Anchor
onClick={() => onResultClick(query.model, result.pk)} onClick={(event: any) =>
onResultClick(query.model, result.pk, event)
}
key={result.pk} key={result.pk}
> >
<RenderInstance instance={result} model={query.model} /> <RenderInstance instance={result} model={query.model} />
@ -316,11 +319,20 @@ export function SearchDrawer({
const navigate = useNavigate(); const navigate = useNavigate();
// Callback when one of the search results is clicked // Callback when one of the search results is clicked
function onResultClick(query: ModelType, pk: number) { function onResultClick(query: ModelType, pk: number, event: any) {
closeDrawer();
const targetModel = ModelInformationDict[query]; const targetModel = ModelInformationDict[query];
if (targetModel.url_detail == undefined) return; if (targetModel.url_detail == undefined) {
navigate(targetModel.url_detail.replace(':pk', pk.toString())); return;
}
if (event?.ctrlKey || event?.shiftKey) {
// Keep the drawer open in this condition
} else {
closeDrawer();
}
let url = targetModel.url_detail.replace(':pk', pk.toString());
navigateToLink(url, navigate, event);
} }
return ( return (
@ -400,7 +412,9 @@ export function SearchDrawer({
key={idx} key={idx}
query={query} query={query}
onRemove={(query) => removeResults(query)} onRemove={(query) => removeResults(query)}
onResultClick={(query, pk) => onResultClick(query, pk)} onResultClick={(query, pk, event) =>
onResultClick(query, pk, event)
}
/> />
))} ))}
</Stack> </Stack>