Skip to content

Commit 1c5a2a7

Browse files
shinyichenthostetler
authored andcommitted
Abstract UAT keywords feedback
1 parent 268a15d commit 1c5a2a7

File tree

3 files changed

+91
-59
lines changed

3 files changed

+91
-59
lines changed

src/api/feedback/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { ADSQuery } from '@/api/types';
22

33
export type FeedbackBaseParams = {
44
name: string;
5-
_subject: 'Updated Record' | 'New Record' | 'Nectar Feedback' | 'Associated Articles' | 'Missing References';
5+
_subject:
6+
| 'Updated Record'
7+
| 'New Record'
8+
| 'Nectar Feedback'
9+
| 'Associated Articles'
10+
| 'Missing References'
11+
| 'UAT keywords feedback'
12+
| string;
613
'g-recaptcha-response': string;
714
origin: 'bbb_feedback' | 'user_submission';
815
_replyto?: string;

src/components/AbstractDetails/AbstractDetails.tsx

Lines changed: 77 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IDocsEntity } from '@/api/search/types';
22
import { EXTERNAL_URLS } from '@/config';
33
import { getReadablePublDate, pluralize } from '@/utils/common/formatters';
4-
import { ExternalLinkIcon, QuestionIcon } from '@chakra-ui/icons';
4+
import { ChatIcon, ExternalLinkIcon, QuestionIcon } from '@chakra-ui/icons';
55
import {
66
Badge,
77
Box,
@@ -10,6 +10,7 @@ import {
1010
Flex,
1111
HStack,
1212
Icon,
13+
Spacer,
1314
Stack,
1415
Table,
1516
Tag,
@@ -33,6 +34,8 @@ import { SearchQueryLink } from '../SearchQueryLink';
3334
import { SimpleLink } from '../SimpleLink';
3435
import { AbstractCitationModal } from './AbstractCitationModal';
3536
import { UATDropdown } from './UATDropdown';
37+
import { useRouter } from 'next/router';
38+
import { feedbackItems } from '../NavBar';
3639

3740
interface IDetailsProps {
3841
doc: IDocsEntity;
@@ -62,6 +65,15 @@ export const AbstractDetails = ({ doc }: IDetailsProps): ReactElement => {
6265

6366
const { isOpen: isCitationOpen, onOpen: onCitationOpen, onClose: onCitationClose } = useDisclosure();
6467

68+
const router = useRouter();
69+
70+
const handleUATFeedback = () => {
71+
void router.push({
72+
pathname: feedbackItems.general.path,
73+
query: { id: doc.bibcode ? doc.bibcode : doc.identifier?.[0], subject: 'UAT keywords feedback' },
74+
});
75+
};
76+
6577
return (
6678
<Box as="section" border="1px" borderColor="gray.50" borderRadius="md" shadow="sm" aria-labelledby="details">
6779
<VisuallyHidden as="h3" id="details">
@@ -103,7 +115,7 @@ export const AbstractDetails = ({ doc }: IDetailsProps): ReactElement => {
103115
<Detail label="Bibcode" value={doc.bibcode} copiable />
104116
<Collections collections={doc.database ?? []} />
105117
<Keywords keywords={doc.keyword} />
106-
<UATKeywords keywords={doc.uat} ids={doc.uat_id} />
118+
<UATKeywords keywords={doc.uat} ids={doc.uat_id} feedback={handleUATFeedback} />
107119
<Bibgroups bibgroups={doc.bibgroup ?? []} />
108120
<PlanetaryFeatures features={doc.planetary_feature} ids={doc.planetary_feature_id} />
109121
<Detail label="Comment(s)" value={doc.comment} />
@@ -214,58 +226,69 @@ const Keywords = memo(({ keywords }: { keywords: Array<string> }) => {
214226
}, equals);
215227
Keywords.displayName = 'Keywords';
216228

217-
const UATKeywords = memo(({ keywords, ids }: { keywords: Array<string>; ids: Array<number> }) => {
218-
const desc = `Search for papers that mention this keyword`;
219-
const label = (
220-
<>
221-
{`UAT ${pluralize('Keyword', keywords?.length ?? 0)} (generated)`}
222-
<Badge colorScheme="blue" mx={1}>
223-
BETA
224-
</Badge>
225-
</>
226-
);
227-
return (
228-
<Detail label={label} value={keywords}>
229-
{(keywords) => (
230-
<Flex flexWrap={'wrap'}>
231-
{keywords.map((keyword, index) => (
232-
<Tag size="md" variant="subtle" whiteSpace="nowrap" m="1" px={2} py={1} key={keyword}>
233-
<HStack spacing="1">
234-
<Tooltip
235-
label={
236-
<>
237-
{keyword} <ExternalLinkIcon aria-label="external link" />
238-
</>
239-
}
240-
>
241-
<SimpleLink href={`https://astrothesaurus.org/uat/${encodeURIComponent(ids[index])}`} newTab>
242-
{shortenKeyword(keyword)}
243-
</SimpleLink>
244-
</Tooltip>
245-
<SearchQueryLink
246-
params={{ q: `uat:"${keyword.split('/').pop()}"` }}
247-
textDecoration="none"
248-
_hover={{
249-
color: 'gray.900',
250-
}}
251-
aria-label={desc}
252-
fontSize="md"
253-
>
254-
<Tooltip label={desc}>
255-
<Center>
256-
<Icon as={MagnifyingGlassIcon} transform="rotate(90deg)" ml={2} mr={1} />
257-
</Center>
258-
</Tooltip>
259-
</SearchQueryLink>
260-
<UATDropdown keyword={keyword} />
261-
</HStack>
262-
</Tag>
263-
))}
264-
</Flex>
265-
)}
266-
</Detail>
267-
);
268-
}, equals);
229+
const UATKeywords = memo(
230+
({ keywords, ids, feedback }: { keywords: Array<string>; ids: Array<number>; feedback: () => void }) => {
231+
const desc = `Search for papers that mention this keyword`;
232+
const label = (
233+
<>
234+
{`UAT ${pluralize('Keyword', keywords?.length ?? 0)} (generated)`}
235+
<Badge colorScheme="blue" mx={1}>
236+
BETA
237+
</Badge>
238+
</>
239+
);
240+
return (
241+
<Detail label={label} value={keywords}>
242+
{(keywords) => (
243+
<>
244+
<Flex flexWrap={'wrap'}>
245+
{keywords.map((keyword, index) => (
246+
<Tag size="md" variant="subtle" whiteSpace="nowrap" m="1" px={2} py={1} key={keyword}>
247+
<HStack spacing="1">
248+
<Tooltip
249+
label={
250+
<>
251+
{keyword} <ExternalLinkIcon aria-label="external link" />
252+
</>
253+
}
254+
>
255+
<SimpleLink href={`https://astrothesaurus.org/uat/${encodeURIComponent(ids[index])}`} newTab>
256+
{shortenKeyword(keyword)}
257+
</SimpleLink>
258+
</Tooltip>
259+
<SearchQueryLink
260+
params={{ q: `uat:"${keyword.split('/').pop()}"` }}
261+
textDecoration="none"
262+
_hover={{
263+
color: 'gray.900',
264+
}}
265+
aria-label={desc}
266+
fontSize="md"
267+
>
268+
<Tooltip label={desc}>
269+
<Center>
270+
<Icon as={MagnifyingGlassIcon} transform="rotate(90deg)" ml={2} mr={1} />
271+
</Center>
272+
</Tooltip>
273+
</SearchQueryLink>
274+
<UATDropdown keyword={keyword} />
275+
</HStack>
276+
</Tag>
277+
))}
278+
<Spacer />
279+
<Flex justifyContent="end" mt={2}>
280+
<Button variant="link" size="sm" onClick={feedback}>
281+
<ChatIcon mr={2} /> Feedback
282+
</Button>
283+
</Flex>
284+
</Flex>
285+
</>
286+
)}
287+
</Detail>
288+
);
289+
},
290+
equals,
291+
);
269292
UATKeywords.displayName = 'UATKeywords';
270293

271294
const Collections = memo(({ collections }: { collections: Array<string> }) => {

src/pages/feedback/general.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ const General: NextPage = () => {
6969
const { executeRecaptcha } = useGoogleReCaptcha();
7070
const { isOpen: isAlertOpen, onClose: onAlertClose, onOpen: onAlertOpen } = useDisclosure();
7171

72+
const router = useRouter();
73+
74+
const { subject, id } = router.query;
75+
7276
const initialFormValues: FormValues = {
7377
name: '',
7478
email: userEmail ?? '',
75-
comments: '',
79+
comments: !!subject && subject === 'UAT keywords feedback' ? `UAT Keywords feedback on record: ${id}\n\n` : '',
7680
};
7781

7882
const formMethods = useForm<FormValues>({
@@ -92,8 +96,6 @@ const General: NextPage = () => {
9296

9397
const { mutate, isLoading } = useFeedback();
9498

95-
const router = useRouter();
96-
9799
const onSubmit = useCallback<SubmitHandler<FormValues>>(
98100
async (params) => {
99101
if (params === null) {
@@ -116,7 +118,7 @@ const General: NextPage = () => {
116118
{
117119
name,
118120
_replyto: email,
119-
_subject: 'Nectar Feedback',
121+
_subject: !!subject ? subject : 'Nectar Feedback',
120122
'feedback-type': 'feedback',
121123
'user-agent-string': globalThis?.navigator?.userAgent,
122124
origin: 'bbb_feedback', // indicate general feedback

0 commit comments

Comments
 (0)