Skip to content

Commit

Permalink
Merge branch 'master' into telemetry-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler authored Dec 20, 2024
2 parents a4efb09 + f7f0db8 commit 96e8089
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type SolrField =
| 'first_author_facet_hier'
| 'first_author_norm'
| 'planetary_feature'
| 'gpn_id'
| 'planetary_feature_id'
| 'grant'
| 'grant_agencies'
| 'grant_facet_hier'
Expand Down
2 changes: 1 addition & 1 deletion src/api/search/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const getAbstractParams = (id: string): IADSApiSearchParams => ({
'pubnote',
'book_author',
'planetary_feature',
'gpn_id',
'planetary_feature_id',
],
q: `identifier:"${id}"`,
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export interface IDocsEntity {
first_author_norm?: string;
first_author?: string;
planetary_feature?: string[];
gpn_id?: string[];
planetary_feature_id?: string[];
grant_agencies?: string;
grant_facet_hier?: string;
grant_id?: string;
Expand Down
4 changes: 3 additions & 1 deletion src/components/ResultList/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface IItemProps {
highlights?: string[];
extraInfo?: string;
linkNewTab?: boolean;
defaultCitation: string;
}

export const Item = (props: IItemProps): ReactElement => {
Expand All @@ -64,6 +65,7 @@ export const Item = (props: IItemProps): ReactElement => {
highlights,
extraInfo,
linkNewTab = false,
defaultCitation = '',
} = props;
const { bibcode, pubdate, title = ['Untitled'], author = [], author_count, pub } = doc;
const formattedPubDate = getFormattedNumericPubdate(pubdate);
Expand Down Expand Up @@ -118,7 +120,7 @@ export const Item = (props: IItemProps): ReactElement => {
<Text as={MathJax} dangerouslySetInnerHTML={{ __html: unwrapStringValue(title) }} />
</SimpleLink>
<Flex alignItems="start" ml={1}>
{!isClient || hideActions ? null : <ItemResourceDropdowns doc={doc} />}
{!isClient || hideActions ? null : <ItemResourceDropdowns doc={doc} defaultCitation={defaultCitation} />}
</Flex>
</Flex>
<Flex direction="column">
Expand Down
25 changes: 5 additions & 20 deletions src/components/ResultList/Item/ItemResourceDropdowns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import { MouseEventHandler, ReactElement, useEffect } from 'react';
import { SimpleLinkDropdown } from '@/components/Dropdown';
import { isBrowser } from '@/utils/common/guards';
import { IDocsEntity } from '@/api/search/types';
import { useGetExportCitation } from '@/api/export/export';
import { useSettings } from '@/lib/useSettings';
import { exportFormats } from '@/components/CitationExporter/models';
import { ExportApiFormatKey } from '@/api/export/types';
import CopyToClipboard from 'react-copy-html-to-clipboard';

export interface IItemResourceDropdownsProps {
doc: IDocsEntity;
defaultCitation: string;
}

export interface IItem {
Expand All @@ -25,22 +22,10 @@ export interface IItem {
path?: string;
}

export const ItemResourceDropdowns = ({ doc }: IItemResourceDropdownsProps): ReactElement => {
export const ItemResourceDropdowns = ({ doc, defaultCitation }: IItemResourceDropdownsProps): ReactElement => {
const router = useRouter();
const isClient = useIsClient();
const toast = useToast({ duration: 2000 });
const { settings } = useSettings();
const { defaultExportFormat, customFormats } = settings;

const { data: citationData } = useGetExportCitation(
{
// format: values(exportFormats).find((f) => f.label === defaultExportFormat).id,
format: ExportApiFormatKey.agu,
customFormat: defaultExportFormat === exportFormats.custom.label ? customFormats[0].code : undefined,
bibcode: [doc.bibcode],
},
{ enabled: !!settings?.defaultExportFormat },
);

const { hasCopied, onCopy, setValue, value } = useClipboard('');

Expand Down Expand Up @@ -172,10 +157,10 @@ export const ItemResourceDropdowns = ({ doc }: IItemResourceDropdownsProps): Rea
};

const handleCitationCopied = () => {
if (citationData?.export) {
if (defaultCitation !== '') {
toast({ status: 'info', title: 'Copied to Clipboard' });
} else {
toast({ status: 'error', title: 'There was a problem fetching citation' });
toast({ status: 'error', title: 'There was a problem fetching citation. Try reloading the page.' });
}
};

Expand Down Expand Up @@ -300,7 +285,7 @@ export const ItemResourceDropdowns = ({ doc }: IItemResourceDropdownsProps): Rea
<MenuList>
<MenuItem onClick={handleCopyAbstractUrl}>Copy URL</MenuItem>

<CopyToClipboard text={citationData?.export} onCopy={handleCitationCopied} options={{ asHtml: true }}>
<CopyToClipboard text={defaultCitation} onCopy={handleCitationCopied} options={{ asHtml: true }}>
<MenuItem>Copy Citation</MenuItem>
</CopyToClipboard>
</MenuList>
Expand Down
39 changes: 38 additions & 1 deletion src/components/ResultList/SimpleResultList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Flex, VisuallyHidden } from '@chakra-ui/react';
import { useIsClient } from '@/lib/useIsClient';
import PT from 'prop-types';
import { HTMLAttributes, ReactElement } from 'react';
import { HTMLAttributes, ReactElement, useMemo } from 'react';
import { Item } from './Item';
import { useHighlights } from './useHighlights';
import { IDocsEntity } from '@/api/search/types';
import { useGetExportCitation } from '@/api/export/export';
import { useSettings } from '@/lib/useSettings';
import { ExportApiFormatKey } from '@/api/export/types';
import { exportFormats } from '../CitationExporter';
import { logger } from '@/logger';

export interface ISimpleResultListProps extends HTMLAttributes<HTMLDivElement> {
docs: IDocsEntity[];
Expand Down Expand Up @@ -38,6 +43,37 @@ export const SimpleResultList = (props: ISimpleResultListProps): ReactElement =>

const { highlights, showHighlights, isFetchingHighlights } = useHighlights();

const { settings } = useSettings();
const { defaultExportFormat, customFormats } = settings;

const bibcodes = docs.map((d) => d.bibcode).sort();

const { data: citationData } = useGetExportCitation(
{
// format: values(exportFormats).find((f) => f.label === defaultExportFormat).id,
format: ExportApiFormatKey.agu,
customFormat: defaultExportFormat === exportFormats.custom.label ? customFormats[0].code : undefined,
bibcode: bibcodes,
sort: ['bibcode asc'],
},
{ enabled: !!settings?.defaultExportFormat },
);

// a map from bibcode to citation
const defaultCitations = useMemo(() => {
const citationSet = new Map<string, string>();
try {
if (!!citationData) {
citationData.export.split('\n').forEach((c, index) => {
citationSet.set(bibcodes[index], c);
});
}
} catch (err) {
logger.error({ err }, 'Error processing citation data');
}
return citationSet;
}, [citationData, bibcodes]);

return (
<Flex
as="section"
Expand All @@ -61,6 +97,7 @@ export const SimpleResultList = (props: ISimpleResultListProps): ReactElement =>
highlights={highlights?.[index] ?? []}
isFetchingHighlights={allowHighlight && isFetchingHighlights}
useNormCite={useNormCite}
defaultCitation={defaultCitations?.get(doc.bibcode)}
/>
))}
</Flex>
Expand Down
18 changes: 5 additions & 13 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ const emitAnalytics = async (req: NextRequest): Promise<void> => {

// For abs/ routes we want to send emit an event to the link gateway
if (path.startsWith('/abs')) {
const url = `${process.env.BASE_URL}/link_gateway${path.replace(
'/abs',
'',
)}`;
const url = `${process.env.BASE_URL}/link_gateway${path.replace('/abs', '')}`;
log.debug({ path, url }, 'Emitting abs route event to link gateway');

try {
Expand All @@ -133,7 +130,8 @@ const getIp = (req: NextRequest) =>
(
req.headers.get('X-Original-Forwarded-For') ||
req.headers.get('X-Forwarded-For') ||
req.headers.get('X-Real-Ip')
req.headers.get('X-Real-Ip') ||
''
)
.split(',')
.shift() || 'unknown';
Expand Down Expand Up @@ -183,21 +181,15 @@ export async function middleware(req: NextRequest) {
return loginMiddleware(req, res);
}

if (
path.startsWith('/user/account/register') ||
path.startsWith('/user/forgotpassword')
) {
if (path.startsWith('/user/account/register') || path.startsWith('/user/forgotpassword')) {
return redirectIfAuthenticated(req, res);
}

if (path.startsWith('/user/libraries') || path.startsWith('/user/settings')) {
return protectedRoute(req, res);
}

if (
path.startsWith('/user/account/verify/change-email') ||
path.startsWith('/user/account/verify/register')
) {
if (path.startsWith('/user/account/verify/change-email') || path.startsWith('/user/account/verify/register')) {
return verifyMiddleware(req, res);
}

Expand Down
3 changes: 2 additions & 1 deletion src/middlewares/botCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const getIp = (req: NextRequest) =>
(
req.headers.get('X-Original-Forwarded-For') ||
req.headers.get('X-Forwarded-For') ||
req.headers.get('X-Real-Ip')
req.headers.get('X-Real-Ip') ||
''
)
.split(',')
.shift() || 'unknown';
Expand Down
4 changes: 2 additions & 2 deletions src/pages/abs/[id]/abstract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
Tooltip,
Tr,
useDisclosure,
VisuallyHidden,
useToast,
VisuallyHidden,
} from '@chakra-ui/react';
import { EditIcon, ExternalLinkIcon, TriangleDownIcon } from '@chakra-ui/icons';

Expand Down Expand Up @@ -244,7 +244,7 @@ const Details = ({ doc }: IDetailsProps): ReactElement => {
)}
</Detail>
<Keywords keywords={doc.keyword} />
<PlanetaryFeatures features={doc.planetary_feature} ids={doc.gpn_id} />
<PlanetaryFeatures features={doc.planetary_feature} ids={doc.planetary_feature_id} />
<Detail label="Comment(s)" value={doc.comment} />
<Detail label="E-Print Comment(s)" value={doc.pubnote} />
</Tbody>
Expand Down

0 comments on commit 96e8089

Please sign in to comment.