Skip to content

Commit

Permalink
Merge pull request #582 from shinyichen/uat
Browse files Browse the repository at this point in the history
Add UAT keywords to abstract page & add UAT facet
  • Loading branch information
shinyichen authored Jan 10, 2025
2 parents 9a4e1c0 + 91f903b commit f9598b8
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export type SolrField =
| 'simbtype'
| 'thesis'
| 'title'
| 'uat'
| 'uat_id'
| 'uat_facet_hier'
| 'vizier'
| 'vizier_facet'
| 'volume'
Expand Down
2 changes: 2 additions & 0 deletions src/api/search/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export const getAbstractParams = (id: string): IADSApiSearchParams => ({
'book_author',
'planetary_feature',
'planetary_feature_id',
'uat',
'uat_id',
],
q: `identifier:"${id}"`,
});
Expand Down
6 changes: 5 additions & 1 deletion src/api/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export type FacetField =
| 'ned_object_facet_hier'
| 'nedtype_object_facet_hier'
| 'simbad_object_facet_hier'
| 'planetary_feature_facet_hier_3level';
| 'planetary_feature_facet_hier_3level'
| 'uat_facet_hier';

export interface IFacetCountsFields {
facet_queries: unknown;
Expand Down Expand Up @@ -291,6 +292,9 @@ export interface IDocsEntity {
simbtype?: string;
thesis?: string;
title?: string[];
uat?: string[];
uat_id?: string[];
uat_facet_hier?: string;
vizier_facet?: string;
vizier?: string;
volume?: string;
Expand Down
9 changes: 9 additions & 0 deletions src/components/SearchFacet/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@ export const facetConfig: Record<SearchFacetID, Omit<ISearchFacetProps, 'onQuery
storeId: 'planetary',
maxDepth: 2,
},
uat: {
label: 'UAT',
field: 'uat_facet_hier' as FacetField,
hasChildren: true,
logic: defaultLogic,
storeId: 'uat',
maxDepth: 2,
noLoadMore: true,
},
};
2 changes: 1 addition & 1 deletion src/components/SearchFacet/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const cleanClause = curry((fqKey: string, clause: string) => {
const operator = getOperator(clause);

// for hierarchical facets, there is more processing to make it get the fields
if (fqKey === 'fq_author' || fqKey === 'fq_planetary_feature') {
if (fqKey === 'fq_author' || fqKey === 'fq_planetary_feature' || fqKey === 'fq_uat') {
return pipe(
map(pipe(replace(/["\\]/g, ''), parseTitleFromKey)),

Expand Down
4 changes: 3 additions & 1 deletion src/components/SearchFacet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const facetFields: FacetField[] = [
'nedtype_object_facet_hier',
'simbad_object_facet_hier',
'planetary_feature_facet_hier_3level',
'uat_facet_hier',
];

export type SearchFacetID =
Expand All @@ -64,7 +65,8 @@ export type SearchFacetID =
| 'data'
| 'vizier'
| 'pubtype'
| 'planetary';
| 'planetary'
| 'uat';

export type FacetCountTuple = [string, number];

Expand Down
1 change: 1 addition & 0 deletions src/components/__mocks__/facetCountFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const facetFoundFieldsData: IFacetCountsFields = {
property: [],
simbad_object_facet_hier: [],
planetary_feature_facet_hier_3level: [],
uat_facet_hier: [],
},
facet_ranges: {},
facet_intervals: {},
Expand Down
2 changes: 2 additions & 0 deletions src/mocks/generators/facets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const createVal = (prefix: string, id: FacetField) => {
case 'ned_object_facet_hier':
case 'planetary_feature_facet_hier_3level':
return `${prefix}${faker.lorem.words(2)}`;
case 'uat_facet_hier':
return `${prefix}${faker.lorem.words(2)}`;

default:
return `${faker.lorem.words(3)}`;
Expand Down
55 changes: 54 additions & 1 deletion src/pages/abs/[id]/abstract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ const Details = ({ doc }: IDetailsProps): ReactElement => {
/>
<Detail label="Bibcode" value={doc.bibcode} copiable />
<Keywords keywords={doc.keyword} />
<UATKeywords keywords={doc.uat} ids={doc.uat_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} />
Expand Down Expand Up @@ -303,6 +304,49 @@ const Keywords = memo(({ keywords }: { keywords: Array<string> }) => {
}, equals);
Keywords.displayName = 'Keywords';

const UATKeywords = memo(({ keywords, ids }: { keywords: Array<string>; ids: Array<string> }) => {
const label = `Search for papers that mention this keyword`;
return (
<Detail label={`UAT ${pluralize('Keyword', keywords?.length ?? 0)} (generated)`} value={keywords}>
{(keywords) => (
<Flex flexWrap={'wrap'}>
{keywords.map((keyword, index) => (
<Tag size="md" variant="subtle" whiteSpace={'nowrap'} m="1" key={keyword}>
<HStack spacing="2">
<Tooltip label={keyword}>
<SimpleLink
href={`https://astrothesaurus.org/uat/${encodeURIComponent(ids[index])}`}
newTab
isExternal
>
{shortenKeyword(keyword)}
</SimpleLink>
</Tooltip>
<SearchQueryLink
params={{ q: `uat:"${keyword.split('/').pop()}"` }}
textDecoration="none"
_hover={{
color: 'gray.900',
}}
aria-label={label}
fontSize="md"
>
<Tooltip label={label}>
<Center>
<Icon as={MagnifyingGlassIcon} transform="rotate(90deg)" />
</Center>
</Tooltip>
</SearchQueryLink>
</HStack>
</Tag>
))}
</Flex>
)}
</Detail>
);
}, equals);
UATKeywords.displayName = 'UATKeywords';

const PlanetaryFeatures = memo(({ features, ids }: { features: Array<string>; ids: Array<string> }) => {
const label = `Search for papers that mention this feature`;
const usgsLabel = `Go to the USGS page for this feature`;
Expand All @@ -323,7 +367,7 @@ const PlanetaryFeatures = memo(({ features, ids }: { features: Array<string>; id
newTab
_hover={{ textDecor: 'underline' }}
>
{feature}
{feature.replaceAll('/', ' > ')}
</SimpleLink>
<HStack spacing="1">
<SearchQueryLink
Expand Down Expand Up @@ -411,3 +455,12 @@ export const getServerSideProps: GetServerSideProps = composeNextGSSP(async (ctx
};
}
});

const shortenKeyword = (keyword: string) => {
const words = keyword.split('/');
if (words.length <= 2) {
return words.join(' > ');
} else {
return `${words[0]} > ... > ${words[words.length - 1]}`;
}
};
2 changes: 2 additions & 0 deletions src/store/slices/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const defaultSettings: ISettingsState['settings'] = {
'vizier',
'pubtype',
'planetary',
'uat',
],
state: {
['author']: { hidden: false, expanded: true },
Expand All @@ -69,6 +70,7 @@ export const defaultSettings: ISettingsState['settings'] = {
['vizier']: { hidden: false, expanded: false },
['pubtype']: { hidden: false, expanded: false },
['planetary']: { hidden: false, expanded: false },
['uat']: { hidden: false, expanded: false },
},
open: true,
ignored: [],
Expand Down

0 comments on commit f9598b8

Please sign in to comment.