Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several small issues on the cohort overiew #1123

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
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
20 changes: 2 additions & 18 deletions ui/src/components/hintDataSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ export function HintDataSelect(props: HintDataSelectProps) {
};

return (
<FormControl
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
onMouseUp={(e) => {
e.stopPropagation();
}}
>
<FormControl>
<Select
multiple
displayEmpty
Expand All @@ -81,15 +73,7 @@ export function HintDataSelect(props: HintDataSelectProps) {
<Chip
key={s}
label={s}
onMouseDown={(e) => {
e.stopPropagation();
e.preventDefault();
}}
onMouseUp={(e) => {
e.stopPropagation();
}}
onDelete={(e) => {
e.stopPropagation();
onDelete={() => {
onDelete(s);
}}
/>
Expand Down
4 changes: 0 additions & 4 deletions ui/src/components/rangeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export function RangeSlider(props: RangeSliderProps) {
height: "auto",
mt: 0.5,
}}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
>
<GridLayout cols fillCol={1} spacing={3} height="auto">
<Input
Expand Down
17 changes: 17 additions & 0 deletions ui/src/components/select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Theme } from "@mui/material/styles";

export function uncontainedSelectSx() {
return {
color: (theme: Theme) => theme.palette.primary.main,
"& .MuiOutlinedInput-input": {
px: 0,
py: "2px",
},
"& .MuiSelect-select": (theme: Theme) => ({
...theme.typography.body2,
}),
"& .MuiOutlinedInput-notchedOutline": {
borderStyle: "none",
},
};
}
21 changes: 2 additions & 19 deletions ui/src/criteria/textSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,7 @@ function TextSearchInline(props: TextSearchInlineProps) {
return (
<Loading status={hintDataState}>
{!!hintDataState.data?.hintData?.enumHintOptions ? (
<FormControl
sx={{ maxWidth: 500 }}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
onMouseUp={(e) => {
e.stopPropagation();
}}
>
<FormControl sx={{ maxWidth: 500 }}>
<GridLayout rows spacing={1} height="auto">
<TextField
label="Search text"
Expand All @@ -224,15 +215,7 @@ function TextSearchInline(props: TextSearchInlineProps) {
<Chip
key={c}
label={c}
onMouseDown={(e) => {
e.stopPropagation();
e.preventDefault();
}}
onMouseUp={(e) => {
e.stopPropagation();
}}
onDelete={(e) => {
e.stopPropagation();
onDelete={() => {
onDelete(c);
}}
/>
Expand Down
12 changes: 1 addition & 11 deletions ui/src/criteria/unhintedValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,7 @@ function UnhintedValueInline(props: UnhintedValueInlineProps) {

return (
<GridLayout rows height="auto">
<FormControl
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
onMouseUp={(e) => {
e.stopPropagation();
}}
>
<FormControl>
<Select
value={decodedData.operator}
input={<OutlinedInput />}
Expand All @@ -195,7 +187,6 @@ function UnhintedValueInline(props: UnhintedValueInlineProps) {
size="medium"
onChange={handleMinInputChange}
onBlur={handleMinInputBlur}
onClick={(e) => e.stopPropagation()}
inputProps={{
type: "number",
}}
Expand All @@ -208,7 +199,6 @@ function UnhintedValueInline(props: UnhintedValueInlineProps) {
size="medium"
onChange={handleMaxInputChange}
onBlur={handleMaxInputBlur}
onClick={(e) => e.stopPropagation()}
inputProps={{
type: "number",
}}
Expand Down
20 changes: 2 additions & 18 deletions ui/src/criteria/valueData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,7 @@ export function ValueDataEdit(props: ValueDataEditProps) {
<Typography variant="body2">{props.title}</Typography>
<Loading status={hintDataState} size="small">
{hasHints ? (
<GridBox
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
onMouseUp={(e) => {
e.stopPropagation();
}}
>
<GridBox>
<Typography variant="body2">
<IconButton
sx={
Expand All @@ -289,15 +281,7 @@ export function ValueDataEdit(props: ValueDataEditProps) {
{hasHints && (!props.title || isValid(props.valueData)) ? (
<GridLayout rows height="auto">
{!!valueDataList.length && props.singleValue ? (
<FormControl
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
onMouseUp={(e) => {
e.stopPropagation();
}}
>
<FormControl>
<Select
value={valueDataList[0].attribute}
input={<OutlinedInput />}
Expand Down
101 changes: 95 additions & 6 deletions ui/src/demographicCharts.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import MenuItem from "@mui/material/MenuItem";
import OutlinedInput from "@mui/material/OutlinedInput";
import Select, { SelectChangeEvent } from "@mui/material/Select";
import FormControl from "@mui/material/FormControl";
import Paper from "@mui/material/Paper";
import Typography from "@mui/material/Typography";
import { uncontainedSelectSx } from "components/select";
import { Cohort } from "data/source";
import { useUnderlay } from "hooks";
import { GridBox } from "layout/gridBox";
import GridLayout from "layout/gridLayout";
import { ReactNode } from "react";
import { VizContainer } from "viz/vizContainer";
import { useState } from "react";
import Empty from "components/empty";
import { Underlay } from "underlaysSlice";

export type DemographicChartsProps = {
cohort?: Cohort;
Expand All @@ -15,6 +23,23 @@ export type DemographicChartsProps = {
export function DemographicCharts(props: DemographicChartsProps) {
const underlay = useUnderlay();

const [selectedVisualizations, setSelectedVisualizations] = useState(
getInitialVisualizations(underlay)
);

const onSelect = (event: SelectChangeEvent<string[]>) => {
const {
target: { value: sel },
} = event;
if (typeof sel === "string") {
// This case is only for selects with text input.
return;
}

setSelectedVisualizations(sel);
storeSelectedVisualizations(underlay.name, sel);
};

return (
<Paper
sx={{
Expand All @@ -23,9 +48,30 @@ export function DemographicCharts(props: DemographicChartsProps) {
}}
>
<GridLayout rows spacing={2}>
<GridLayout cols fillCol={1} rowAlign="middle">
<GridLayout cols fillCol={0} spacing={1} rowAlign="middle">
<Typography variant="h6">Cohort visualizations</Typography>
<GridBox />
<FormControl>
<Select
fullWidth
multiple
displayEmpty
value={selectedVisualizations}
input={<OutlinedInput />}
renderValue={(sel) => (
<Typography variant="body2">{`${sel.length} visualizations selected`}</Typography>
)}
onChange={onSelect}
sx={uncontainedSelectSx()}
>
{underlay.visualizations.map((viz) => {
return (
<MenuItem key={viz.name} value={viz.name}>
{viz.title ?? "Unknown"}
</MenuItem>
);
})}
</Select>
</FormControl>
{props.extraControls}
</GridLayout>
<GridBox
Expand All @@ -38,13 +84,56 @@ export function DemographicCharts(props: DemographicChartsProps) {
gridGap: (theme) => theme.spacing(3),
}}
>
{underlay.visualizations.map((v) =>
props.cohort ? (
<VizContainer key={v.name} config={v} cohort={props.cohort} />
) : null
{selectedVisualizations.length > 0 ? (
underlay.visualizations.map((v) =>
selectedVisualizations.find((sv) => sv === v.name) &&
props.cohort ? (
<VizContainer key={v.name} config={v} cohort={props.cohort} />
) : null
)
) : (
<Empty
maxWidth="90%"
minHeight="200px"
title="No visualizations selected"
/>
)}
</GridBox>
</GridLayout>
</Paper>
);
}

// TODO(tjennison): Store the selected visualizations in local storage per
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: jira tracking id

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not a fan of creating tickets for TODOs unless they're bugs or part of ongoing work. Too often they just end up cluttering up the backlog because plans change and then you have to actually change the code to get rid of them.

// underlay for now. Longer term, these should be stored on the backend but
// there a few options about whether they should be stored attached to the
// cohort, study, user, etc. as part of the visualiation changes.
function storageKey(underlay: string) {
return `tanagra-selected-visualizations-${underlay}`;
}

function loadSelectedVisualizations(underlay: string): string[] | undefined {
const stored = localStorage.getItem(storageKey(underlay));
if (!stored) {
return undefined;
}
return JSON.parse(stored);
}

function storeSelectedVisualizations(underlay: string, sel: string[]) {
localStorage.setItem(storageKey(underlay), JSON.stringify(sel));
}

function getInitialVisualizations(underlay: Underlay) {
const stored = loadSelectedVisualizations(underlay.name);
if (!stored) {
return (
underlay.uiConfiguration.defaultVisualizations ??
underlay.visualizations.map((viz) => viz.name)
);
}

return stored.filter((v) =>
underlay.visualizations.find((viz) => viz.name === v)
);
}
Loading
Loading