Skip to content

Commit 3ff4435

Browse files
authored
Fix menu flickering, show circuits only in models section (#254)
1 parent b74cf37 commit 3ff4435

File tree

1 file changed

+36
-22
lines changed
  • src/components/explore-section/ExploreListingLayout

1 file changed

+36
-22
lines changed

src/components/explore-section/ExploreListingLayout/index.tsx

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import { ExploreDataScope } from '@/types/explore-section/application';
2525
import { VirtualLabInfo } from '@/types/virtual-lab/common';
2626
import { ensureString } from '@/util/type-guards';
2727
import { classNames } from '@/util/utils';
28-
29-
const menuItemWidth = `${Math.floor(100 / Object.keys(EXPERIMENT_DATA_TYPES).length) - 0.01}%`;
28+
import { DataTypeGroup } from '@/types/explore-section/data-types';
3029

3130
const dataScope = ExploreDataScope.SelectedBrainRegion;
3231

@@ -60,14 +59,24 @@ export default function ExploreListingLayout({
6059
children: ReactNode;
6160
virtualLabInfo?: VirtualLabInfo;
6261
}) {
63-
const [, setCurrentExplorerArtifact] = useCurrentExplorerArtifact();
64-
const pathname = usePathname();
65-
const splittedPathname = pathname.split('/');
66-
const interactivePageHref = splittedPathname.slice(0, splittedPathname.length - 2).join('/');
6762
const router = useRouter();
6863
const params = useParams();
69-
const config = pathname.includes('experimental') ? EXPERIMENT_DATA_TYPES : MODEL_DATA_TYPES;
64+
const pathname = usePathname();
65+
7066
const selectedBrainRegion = useAtomValue(selectedBrainRegionAtom);
67+
const [, setCurrentExplorerArtifact] = useCurrentExplorerArtifact();
68+
69+
const splittedPathname = pathname.split('/');
70+
const interactivePageHref = splittedPathname.slice(0, splittedPathname.length - 2).join('/');
71+
72+
const dataTypeGroup = pathname.includes('experimental')
73+
? DataTypeGroup.ExperimentalData
74+
: DataTypeGroup.ModelData;
75+
76+
const config =
77+
dataTypeGroup === DataTypeGroup.ExperimentalData ? EXPERIMENT_DATA_TYPES : MODEL_DATA_TYPES;
78+
79+
const showCircuitMenu = dataTypeGroup === DataTypeGroup.ModelData;
7180
const activePath = pathname?.split('/').pop() || 'morphology';
7281

7382
const onClick: MenuProps['onClick'] = async (info) => {
@@ -84,6 +93,9 @@ export default function ExploreListingLayout({
8493
router.push(key);
8594
};
8695

96+
const nMenuItems = Object.keys(config).length + (showCircuitMenu ? 1 : 0);
97+
const menuItemWidth = `${Math.floor(100 / nMenuItems) - 0.04}%`;
98+
8799
const items: {
88100
key: string;
89101
title: string;
@@ -114,19 +126,21 @@ export default function ExploreListingLayout({
114126
};
115127
});
116128

117-
const circuitActive = activePath === 'circuit';
118-
119-
items.push({
120-
key: 'circuit',
121-
title: 'Circuit',
122-
label: `Circuit (${circuitsFlat.length})`,
123-
className: 'text-center font-semibold',
124-
style: {
125-
backgroundColor: circuitActive ? 'white' : '#002766',
126-
color: circuitActive ? '#002766' : 'white',
127-
flexBasis: menuItemWidth,
128-
},
129-
});
129+
if (showCircuitMenu) {
130+
const circuitActive = activePath === 'circuit';
131+
132+
items.push({
133+
key: 'circuit',
134+
title: 'Circuit',
135+
label: `Circuit (${circuitsFlat.length})`,
136+
className: 'text-center font-semibold',
137+
style: {
138+
backgroundColor: circuitActive ? 'white' : '#002766',
139+
color: circuitActive ? '#002766' : 'white',
140+
flexBasis: menuItemWidth,
141+
},
142+
});
143+
}
130144

131145
if (params?.id)
132146
return <ErrorBoundary FallbackComponent={SimpleErrorComponent}>{children}</ErrorBoundary>;
@@ -136,14 +150,14 @@ export default function ExploreListingLayout({
136150
<ErrorBoundary FallbackComponent={SimpleErrorComponent}>
137151
<BackToInteractiveExplorationBtn href={interactivePageHref} />
138152

139-
<div className={classNames('flex-1 overflow-hidden')}>
153+
<div className="overflow-x-hidden">
140154
<Menu
141155
onClick={onClick}
142156
selectedKeys={[activePath]}
143157
mode="horizontal"
144158
theme="dark"
145159
style={{ backgroundColor: '#002766' }}
146-
className="flex w-full justify-start"
160+
className="flex w-[calc(100%+6px)] justify-start"
147161
items={items}
148162
/>
149163

0 commit comments

Comments
 (0)