generated from allen-cell-animated/github-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #435 from allen-cell-animated/feature/feature-tool…
…tips - Adds the `GlossaryPanel` component, which renders the list of features in an Ant `Drawer`. - Adds support for the `descriptions` feature metadata added in `colorizer-data v.1.4.2`. - Bonus: refactors the `LandingPage` to use the `ExternalLink` convenience component.
- Loading branch information
Showing
6 changed files
with
155 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { ReadOutlined } from "@ant-design/icons"; | ||
import { Divider, Drawer, Radio, RadioChangeEvent, Tooltip } from "antd"; | ||
import React, { ReactElement, useContext, useMemo, useState } from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { Dataset } from "../colorizer"; | ||
import { FlexColumn, FlexRowAlignCenter } from "../styles/utils"; | ||
|
||
import { AppThemeContext } from "./AppStyle"; | ||
import IconButton from "./IconButton"; | ||
|
||
type GlossaryPanelProps = { | ||
dataset: Dataset | null; | ||
}; | ||
|
||
const StyledDrawer = styled(Drawer)` | ||
.ant-drawer-body { | ||
padding-top: 16px; | ||
} | ||
.ant-drawer-header-title { | ||
// Move the close button to the right corner of the header | ||
display: flex; | ||
flex-direction: row-reverse; | ||
} | ||
p { | ||
margin: 0; | ||
} | ||
`; | ||
|
||
export default function GlossaryPanel(props: GlossaryPanelProps): ReactElement { | ||
const [showPanel, setShowPanel] = useState(false); | ||
const [alphabetizeFeatures, setAlphabetizeFeatures] = useState(false); | ||
|
||
const theme = useContext(AppThemeContext); | ||
|
||
const drawerContent = useMemo(() => { | ||
const dataset = props.dataset; | ||
if (dataset === null) { | ||
return null; | ||
} | ||
const allFeatureData = dataset.featureKeys.map((featureKey) => dataset.getFeatureData(featureKey)!); | ||
if (alphabetizeFeatures) { | ||
allFeatureData.sort((a, b) => a.name.localeCompare(b.name)); | ||
} | ||
|
||
return ( | ||
<FlexColumn $gap={15}> | ||
{allFeatureData.map((featureData) => { | ||
const hasDescription = featureData.description && featureData.description !== ""; | ||
const key = featureData.key; | ||
return ( | ||
<p style={{ lineHeight: "1.5", margin: "0" }} key={key}> | ||
<Tooltip title={hasDescription ? null : "No description provided"} placement="right"> | ||
<span style={{ fontWeight: "bold" }}>{dataset.getFeatureNameWithUnits(key)}</span> | ||
</Tooltip> | ||
<br /> | ||
{featureData.description} | ||
</p> | ||
); | ||
})} | ||
</FlexColumn> | ||
); | ||
}, [props.dataset, alphabetizeFeatures]); | ||
|
||
return ( | ||
<> | ||
<Tooltip placement="top" title="Open feature glossary" trigger={["hover", "focus"]}> | ||
<IconButton | ||
type="link" | ||
onClick={() => { | ||
setShowPanel(true); | ||
}} | ||
disabled={!props.dataset} | ||
> | ||
<ReadOutlined style={{ marginTop: "1px" }} /* Visually align with other elements*/ /> | ||
</IconButton> | ||
</Tooltip> | ||
<StyledDrawer | ||
zIndex={2000} | ||
width={"calc(min(75vw, 1000px))"} | ||
onClose={() => { | ||
setShowPanel(false); | ||
}} | ||
title={<span style={{ fontSize: "20px" }}>Feature glossary</span>} | ||
open={showPanel} | ||
size="large" | ||
style={{ color: theme.color.text.primary }} | ||
> | ||
<FlexColumn $gap={16}> | ||
<FlexRowAlignCenter $gap={8}> | ||
<h3 style={{ margin: 0, fontWeight: "normal" }} id="glossary-sortby-label"> | ||
Sort by | ||
</h3> | ||
<Radio.Group | ||
buttonStyle="solid" | ||
// TODO: Why does Ant not support aria-label on Radio.Group? | ||
// "aria-label"="glossary-sortby-label" | ||
value={alphabetizeFeatures} | ||
onChange={(e: RadioChangeEvent) => setAlphabetizeFeatures(e.target.value)} | ||
> | ||
<Radio.Button value={false}>Feature order</Radio.Button> | ||
<Radio.Button value={true}>Alphabetical</Radio.Button> | ||
</Radio.Group> | ||
</FlexRowAlignCenter> | ||
<Divider /> | ||
{drawerContent} | ||
</FlexColumn> | ||
</StyledDrawer> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters