Skip to content

Commit

Permalink
Add showExperimentalFeature toggle in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
hrntsm committed Dec 6, 2024
1 parent 0973d05 commit cbe6057
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
44 changes: 24 additions & 20 deletions optuna_dashboard/ts/components/AppDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { useRecoilState, useRecoilValue } from "recoil"
import {
drawerOpenState,
reloadIntervalState,
useShowExperimentalFeature,
useStudyIsPreferential,
} from "../state"
import { Settings } from "./Settings"
Expand Down Expand Up @@ -147,6 +148,7 @@ export const AppDrawer: FC<{
const reloadInterval = useRecoilValue<number>(reloadIntervalState)
const isPreferential =
studyId !== undefined ? useStudyIsPreferential(studyId) : null
const [showExperimentalFeatures] = useShowExperimentalFeature()

const styleListItem = {
display: "block",
Expand Down Expand Up @@ -347,27 +349,29 @@ export const AppDrawer: FC<{
<ListItemText primary="Trials (Table)" sx={styleListItemText} />
</ListItemButton>
</ListItem>
<ListItem
key="TrialCompare"
disablePadding
sx={styleListItem}
title="Trials (Compare)"
>
<ListItemButton
component={Link}
to={`${url_prefix}/studies/${studyId}/trialCompare`}
sx={styleListItemButton}
selected={page === "trialTable"}
{showExperimentalFeatures === true ? (
<ListItem
key="TrialCompare"
disablePadding
sx={styleListItem}
title="Trials (Compare)"
>
<ListItemIcon sx={styleListItemIcon}>
<CompareIcon />
</ListItemIcon>
<ListItemText
primary="Trials (Compare)"
sx={styleListItemText}
/>
</ListItemButton>
</ListItem>
<ListItemButton
component={Link}
to={`${url_prefix}/studies/${studyId}/trialCompare`}
sx={styleListItemButton}
selected={page === "trialTable"}
>
<ListItemIcon sx={styleListItemIcon}>
<CompareIcon />
</ListItemIcon>
<ListItemText
primary="Trials (Compare)"
sx={styleListItemText}
/>
</ListItemButton>
</ListItem>
) : null}
<ListItem key="Note" disablePadding sx={styleListItem} title="Note">
<ListItemButton
component={Link}
Expand Down
26 changes: 26 additions & 0 deletions optuna_dashboard/ts/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
plotlypyIsAvailableState,
usePlotBackendRendering,
usePlotlyColorThemeState,
useShowExperimentalFeature,
} from "../state"

interface SettingsProps {
Expand All @@ -30,6 +31,8 @@ export const Settings = ({ handleClose }: SettingsProps) => {
const [plotBackendRendering, setPlotBackendRendering] =
usePlotBackendRendering()
const plotlypyIsAvailable = useRecoilValue(plotlypyIsAvailableState)
const [showExperimentalFeature, setShowExperimentalFeature] =
useShowExperimentalFeature()

const handleDarkModeColorChange = (event: SelectChangeEvent) => {
const dark = event.target.value as PlotlyColorThemeDark
Expand All @@ -45,6 +48,10 @@ export const Settings = ({ handleClose }: SettingsProps) => {
setPlotBackendRendering((cur) => !cur)
}

const toggleShowExperimentalFeature = () => {
setShowExperimentalFeature((cur) => !cur)
}

return (
<Box component="div" sx={{ position: "relative" }}>
<Stack
Expand Down Expand Up @@ -138,6 +145,25 @@ export const Settings = ({ handleClose }: SettingsProps) => {
disabled={!plotlypyIsAvailable}
/>
</Stack>

<Stack>
<Typography
variant="h5"
sx={{ fontWeight: theme.typography.fontWeightBold }}
>
Show Experimental Feature
</Typography>
<Typography color="textSecondary">
{
'If enabled, show experimental features "Trial (Selection)" in the UI.'
}
</Typography>
<Switch
checked={showExperimentalFeature}
onChange={toggleShowExperimentalFeature}
value="enable"
/>
</Stack>
</Stack>

<IconButton
Expand Down
4 changes: 4 additions & 0 deletions optuna_dashboard/ts/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export const usePlotBackendRendering = () => {
return useLocalStorage<boolean>("plotBackendRendering", false)
}

export const useShowExperimentalFeature = () => {
return useLocalStorage<boolean>("showExperimentalFeature", false)
}

export const usePlotlyColorThemeState = () => {
return useLocalStorage<PlotlyColorTheme>("plotlyColorTheme", {
dark: "default",
Expand Down

0 comments on commit cbe6057

Please sign in to comment.