Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { ReactNode, useState } from "react";
import {
List,
ListItem,
Expand All @@ -9,24 +9,24 @@ import {
Box,
Paper,
IconButton,
Link as MUILink,
Typography,
ButtonBase,
Theme,
} from "@mui/material";
import { makeStyles } from "@mui/styles";
import { CSSProperties, makeStyles } from "@mui/styles";
import { faChevronDown, faXmark } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import _ from "lodash";

import { Link } from "ui";

const sourceDrawerStyles = makeStyles(theme => ({
const sourceDrawerStyles = makeStyles((theme: Theme) => ({
drawerLink: {
color: `${theme.palette.primary.main} !important`,
},
drawerBody: {
overflowY: "overlay",
},
} as unknown as CSSProperties,
Copy link
Contributor Author

@raskolnikov-rodion raskolnikov-rodion Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit unusual but I'm following the recommendation from the compiler as I'm assuming the code is correct even though it doesn't fit the type

image

drawerModal: {
"& .MuiBackdrop-root": {
opacity: "0 !important",
Expand Down Expand Up @@ -70,18 +70,18 @@ const sourceDrawerStyles = makeStyles(theme => ({
},
}));

const tableSourceLabel = name =>
const tableSourceLabel = (name: string) =>
({
ATC: "ATC",
ClinicalTrials: "ClinicalTrials.gov",
DailyMed: "DailyMed",
FDA: "FDA",
EMA: "European Medicines Agency",
INN: "International Nonproprietary Names",
USAN: "United States Adopted Name",
}[name]);

const drawerSourceLabel = (name, url) => {
ATC: "ATC",
ClinicalTrials: "ClinicalTrials.gov",
DailyMed: "DailyMed",
FDA: "FDA",
EMA: "European Medicines Agency",
INN: "International Nonproprietary Names",
USAN: "United States Adopted Name",
}[name]);

const drawerSourceLabel = (name: string, url: string) => {
if (name === "ClinicalTrials") {
return url.split("%22")[1] || `${tableSourceLabel(name)} reference`;
}
Expand All @@ -97,7 +97,17 @@ const drawerSourceLabel = (name, url) => {
return `${name} entry`;
};

function KnownDrugsSourceDrawer({ references }) {
type Reference = {
__typename: string;
name: string;
url: string;
}

type KnownDrugsSourceDrawerProps = {
references: Reference[];
}

function KnownDrugsSourceDrawer({ references }: KnownDrugsSourceDrawerProps): ReactNode {
const [open, setOpen] = useState(false);
const classes = sourceDrawerStyles();

Expand All @@ -113,10 +123,10 @@ function KnownDrugsSourceDrawer({ references }) {
);
}

const groupedReferences = _.groupBy(references, "name");
const groupedReferences: Record<string, Reference[]> = _.groupBy(references, "name");

const toggleDrawer = event => {
if (event.type === "keydown" && (event.key === "Tab" || event.key === "Shift")) {
const toggleDrawer: React.MouseEventHandler = event => {
if (event.type === "keydown" && ((event as unknown as KeyboardEvent).key === "Tab" || (event as unknown as KeyboardEvent).key === "Shift")) {
return;
}

Expand Down Expand Up @@ -163,7 +173,7 @@ function KnownDrugsSourceDrawer({ references }) {
</AccordionSummary>
<AccordionDetails>
<List>
{groupedReferences[group].map(item => (
{groupedReferences[group].map((item: Reference) => (
<ListItem key={item.url}>
<Link external to={item.url}>
{drawerSourceLabel(item.name, item.url)}
Expand Down