Skip to content

Commit

Permalink
feat: update "organisms" list action ui (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fran McDade authored and NoopDog committed Nov 5, 2024
1 parent 85124db commit 3b70426
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ButtonProps } from "@mui/material";

export const BUTTON_PROPS: Partial<ButtonProps> = {
color: "primary",
size: "large",
variant: "contained",
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ROUTES } from "../../../../../../../routes/constants";
import { calculateGridSize } from "../../../../../Layout/components/Hero/common/utils";
import { Carousel } from "./components/Carousel/carousel";
import { Hero } from "./components/Hero/hero";
import { BUTTON_PROPS } from "./constants";
import {
Head,
Headline,
Expand Down Expand Up @@ -31,11 +32,7 @@ export const SectionHero = (): JSX.Element => {
annotations and functional insights into disease-causing
organisms and their carriers
</Subhead>
<Button
color="hero"
href={ROUTES.ORGANISMS}
variant="contained"
>
<Button {...BUTTON_PROPS} href={ROUTES.ORGANISMS}>
Get started
</Button>
</SubHeadline>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,76 +1,57 @@
import { DropdownButton } from "@databiosphere/findable-ui/lib/components/common/Button/components/DropdownButton/dropdownButton";
import { DropdownMenuButtonProps } from "@databiosphere/findable-ui/lib/components/common/DropdownMenu/common/entities";
import { DropdownMenu } from "@databiosphere/findable-ui/lib/components/common/DropdownMenu/dropdownMenu";
import {
ANCHOR_TARGET,
REL_ATTRIBUTE,
} from "@databiosphere/findable-ui/lib/components/Links/common/entities";
import { Button, Tooltip } from "@mui/material";
import Router from "next/router";
import { ROUTES } from "../../../../../../../routes/constants";
import { AnalyzeGenomeIcon } from "../../../../../common/CustomIcon/components/AnalyzeGenomeIcon/analyzeGenomeIcon";
import { ViewGenomeIcon } from "../../../../../common/CustomIcon/components/ViewGenomeIcon/viewGenomeIcon";
import { StyledButtonGroup } from "./analyzeGenome.styles";
import {
BUTTON_GROUP_PROPS,
BUTTON_PROPS,
ICON_PROPS,
} from "./common/constants";

export interface AnalyzeGenomeProps {
genomeVersionAssemblyId: string;
rowId?: string;
ucscBrowserUrl: string;
}
import { Button, Grid2, MenuItem } from "@mui/material";
import NLink from "next/link";
import { BUTTON_PROPS, GRID2_PROPS, MENU_PROPS } from "./constants";
import { AnalyzeGenomeProps } from "./types";

export const AnalyzeGenome = ({
genomeVersionAssemblyId,
rowId,
ucscBrowserUrl,
analyze,
views,
}: AnalyzeGenomeProps): JSX.Element => {
const onAnalyze = (rowId?: string): void => {
if (!rowId) return;
Router.push(`${ROUTES.ORGANISMS}/${rowId}`);
};

const onView = (url: string | null): void => {
if (!url) return;
window.open(url, ANCHOR_TARGET.BLANK, REL_ATTRIBUTE.NO_OPENER_NO_REFERRER);
};

return (
<StyledButtonGroup
{...BUTTON_GROUP_PROPS}
Buttons={[
<Tooltip key="analyze" title="Analyze">
<Button
{...BUTTON_PROPS}
disabled={!rowId}
onClick={(): void => onAnalyze(rowId)}
>
<AnalyzeGenomeIcon {...ICON_PROPS} />
</Button>
</Tooltip>,
<Tooltip key="view-browser" title="UCSC Genome Browser">
<Button
{...BUTTON_PROPS}
disabled={!ucscBrowserUrl}
onClick={(): void => onView(ucscBrowserUrl)}
>
<ViewGenomeIcon {...ICON_PROPS} />
</Button>
</Tooltip>,
<Tooltip key="view-datasets" title="NCBI datasets">
<Button
{...BUTTON_PROPS}
disabled={!genomeVersionAssemblyId}
onClick={(): void =>
onView(
`https://www.ncbi.nlm.nih.gov/datasets/genome/${genomeVersionAssemblyId}`
)
}
>
NCBI
</Button>
</Tooltip>,
]}
/>
<Grid2 {...GRID2_PROPS}>
<Button
{...BUTTON_PROPS}
component={NLink}
disabled={!analyze.url}
href={analyze.url}
>
{analyze.label}
</Button>
<DropdownMenu {...MENU_PROPS} Button={renderButton}>
{({ closeMenu }): JSX.Element[] =>
views.map((view, i) => (
<MenuItem
key={i}
onClick={(): void => {
closeMenu();
window.open(
view.url,
ANCHOR_TARGET.BLANK,
REL_ATTRIBUTE.NO_OPENER_NO_REFERRER
);
}}
>
{view.label}
</MenuItem>
))
}
</DropdownMenu>
</Grid2>
);
};

/**
* Render the dropdown button.
* @param props - Button props e.g. "onClick".
* @returns button element.
*/
function renderButton(props: DropdownMenuButtonProps): JSX.Element {
return <DropdownButton {...props}>View</DropdownButton>;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ButtonOwnProps, Grid2Props, MenuProps } from "@mui/material";

export const BUTTON_PROPS: Partial<ButtonOwnProps> = {
color: "primary",
variant: "contained",
};

export const GRID2_PROPS: Partial<Grid2Props> = {
container: true,
direction: "row",
spacing: 2,
wrap: "nowrap",
};

export const MENU_PROPS: Partial<MenuProps> = {
anchorOrigin: { horizontal: "left", vertical: "bottom" },
transformOrigin: { horizontal: "left", vertical: "top" },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface ActionItem {
label: string;
url: string;
}

export interface AnalyzeGenomeProps {
analyze: ActionItem;
views: ActionItem[];
}
42 changes: 26 additions & 16 deletions app/theme/common/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,38 @@ import { Components, Theme } from "@mui/material";

/**
* MuiButton Component
* @param theme - Theme.
* @returns MuiButton component theme styles.
*/
export const MuiButton = (theme: Theme): Components["MuiButton"] => {
return {
styleOverrides: {
containedHero: {
export const MuiButton: Components["MuiButton"] = {
styleOverrides: {
containedPrimary: {
boxShadow: `0px 1px 0px 0px rgba(0, 0, 0, 0.08), 0px -1px 0px 0px rgba(0, 0, 0, 0.20) inset`,
// eslint-disable-next-line sort-keys -- disabling key order for readability
"&:hover": {
boxShadow: `0px 1px 0px 0px rgba(0, 0, 0, 0.08), 0px -1px 0px 0px rgba(0, 0, 0, 0.20) inset`,
},
// eslint-disable-next-line sort-keys -- disabling key order for readability
"&.Mui-disabled": {
boxShadow: `0px 1px 0px 0px rgba(0, 0, 0, 0.08), 0px -1px 0px 0px rgba(0, 0, 0, 0.20) inset`,
color: theme.palette.common.white,
// eslint-disable-next-line sort-keys -- disabling key order for readability
"&:hover": {
backgroundColor: theme.palette.hero.main,
boxShadow: `0px 1px 0px 0px rgba(0, 0, 0, 0.08), 0px -1px 0px 0px rgba(0, 0, 0, 0.20) inset`,
},
},
root: {
variants: [
{
props: { size: "large" },
style: {
padding: "10px 16px",
},
},
// eslint-disable-next-line sort-keys -- disabling key order for readability
"&:active": {
backgroundColor: theme.palette.hero.main,
boxShadow: "none",
{
props: { size: "medium" },
style: {
padding: "8px 16px",
},
},
},
],
},
};
},
};

export const MuiButtonGroup = (theme: Theme): Components["MuiButtonGroup"] => {
Expand Down
21 changes: 10 additions & 11 deletions app/theme/common/palette.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { PaletteColor } from "@mui/material";
import { PaletteColorOptions } from "@mui/material";

/**
* Palette "Hero"
* Palette "Primary"
*/
export const HERO = {
LIGHT: "#28285B",
const PRIMARY = {
DARK: "#1F1F47",
MAIN: "#28285B",
};

/**
* Color constants
*/
export const heroLight = HERO.LIGHT;
export const heroMain = HERO.MAIN;
const primaryDark = PRIMARY.DARK;
const primaryMain = PRIMARY.MAIN;

/**
* Palette Option "Hero"
* Palette Option "Primary"
*/
export const hero: PaletteColor = {
export const primary: PaletteColorOptions = {
contrastText: "#FFFFFF",
dark: heroMain,
light: heroLight,
main: heroMain,
dark: primaryDark,
main: primaryMain,
};
8 changes: 6 additions & 2 deletions app/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createAppTheme } from "@databiosphere/findable-ui/lib/theme/theme";
import { createTheme, Theme, ThemeOptions } from "@mui/material";
import { deepmerge } from "@mui/utils";
import * as C from "./common/components";
import { primary } from "./common/palette";

/**
* Returns BRC customized theme.
Expand All @@ -14,13 +15,16 @@ export function mergeAppTheme(
themeOptions?: ThemeOptions
): Theme {
// Merge custom options (palette, shadows, typography).
const customOptions = deepmerge(baseThemeOptions, { ...themeOptions });
const customOptions = deepmerge(baseThemeOptions, {
...themeOptions,
palette: { ...themeOptions?.palette, primary },
});
// Create base app theme with custom options.
const baseAppTheme = createAppTheme(customOptions);
// Merge app components with base app theme.
const appTheme = createTheme(baseAppTheme, {
components: {
MuiButton: C.MuiButton(baseAppTheme),
MuiButton: C.MuiButton,
MuiButtonGroup: C.MuiButtonGroup(baseAppTheme),
MuiCssBaseline: C.MuiCssBaseline(baseAppTheme),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const GENOME_BROWSER = "UCSC Genome Browser";
export const NCBI_DATASETS_URL = "https://www.ncbi.nlm.nih.gov/datasets";
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
BRCDataCatalogGenome,
} from "../../../../apis/catalog/brc-analytics-catalog/common/entities";
import * as C from "../../../../components";
import { GENOME_BROWSER } from "./constants";
import { GENOME_BROWSER, NCBI_DATASETS_URL } from "./constants";

/**
* Build props for the genome analysis cell.
Expand All @@ -24,12 +24,26 @@ export const buildAnalyzeGenome = (
genome: BRCDataCatalogGenome,
viewContext: ViewContext<BRCDataCatalogGenome>
): ComponentProps<typeof C.AnalyzeGenome> => {
const { cellContext } = viewContext;
const { row } = cellContext || {};
const { genomeVersionAssemblyId, ncbiTaxonomyId, ucscBrowserUrl } = genome;
const rowId = viewContext.cellContext?.row?.id;
return {
genomeVersionAssemblyId: genome.genomeVersionAssemblyId,
rowId: row?.id,
ucscBrowserUrl: genome.ucscBrowserUrl,
analyze: {
label: "Analyze",
url: rowId ? `${ROUTES.ORGANISMS}/${rowId}` : "",
},
views: [
{ label: "UCSC Genome Browser", url: ucscBrowserUrl },
{
label: "NCBI Genome Assembly",
url: `${NCBI_DATASETS_URL}/genome/${genomeVersionAssemblyId}`,
},
{
label: "NCBI Taxonomy",
url: `${NCBI_DATASETS_URL}/taxonomy/${encodeURIComponent(
ncbiTaxonomyId
)}`,
},
],
};
};

Expand Down Expand Up @@ -198,12 +212,9 @@ export const buildOrganismListHero = (): ComponentProps<
*/
export const buildSpecies = (
genome: BRCDataCatalogGenome
): ComponentProps<typeof C.Link> => {
): ComponentProps<typeof C.BasicCell> => {
return {
label: genome.species,
url: `https://www.ncbi.nlm.nih.gov/datasets/taxonomy/${encodeURIComponent(
genome.ncbiTaxonomyId
)}/`,
value: genome.species,
};
};

Expand Down
Loading

0 comments on commit 3b70426

Please sign in to comment.