Skip to content
Open
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
5 changes: 4 additions & 1 deletion DashAI/front/src/components/models/ModelCenterContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function ModelsCenterContent() {
tasks,
loadingTasks,
datasets,
datasetsLoaded,
selectedDatasetId,
step,
} = useModels();
Expand Down Expand Up @@ -136,7 +137,9 @@ export default function ModelsCenterContent() {
}))}
searchBar={false}
goToPrevStep={selectedDatasetId ? handleBackToDataset : null}
showNoDatasetAlert={!selectedDatasetId && datasets.length === 0}
showNoDatasetAlert={
!selectedDatasetId && datasetsLoaded && datasets.length === 0
}
onGoToDatasets={handleGoToDatasets}
goToNextStep={goToNextStep}
dataTour="task-selection"
Expand Down
3 changes: 3 additions & 0 deletions DashAI/front/src/components/models/ModelsContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function ModelsProvider({ children }) {

const {
datasets,
datasetsLoaded,
createDataset,
selectedDatasetId,
fetchDatasets,
Expand Down Expand Up @@ -197,6 +198,7 @@ export function ModelsProvider({ children }) {
setSelectedModel,
setConfigOpen,
datasets,
datasetsLoaded,
createDataset,
selectedDatasetId,
fetchDatasets,
Expand Down Expand Up @@ -290,6 +292,7 @@ export function ModelsProvider({ children }) {
selectModel,
closeConfig,
datasets,
datasetsLoaded,
createDataset,
selectedDatasetId,
fetchDatasets,
Expand Down
45 changes: 2 additions & 43 deletions DashAI/front/src/components/threeSectionLayout/OptionBox.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { forwardRef, useRef, useLayoutEffect } from "react";
import { forwardRef } from "react";
import { Box, Typography, ButtonBase, useTheme } from "@mui/material";

// Must match the top+bottom padding set below ("22px 24px").
const VERTICAL_PADDING = 44;
// Must match the footer's mt below.
const FOOTER_GAP = 16;

const OptionBox = forwardRef(function OptionBox(
{
optionName,
Expand All @@ -15,8 +10,6 @@ const OptionBox = forwardRef(function OptionBox(
chips = [],
badge = null,
dataTour,
minHeight,
onMeasure,
...otherProps
},
ref,
Expand All @@ -27,38 +20,6 @@ const OptionBox = forwardRef(function OptionBox(
const accentBorder = `${theme.palette.primary.main}38`;
const accentGlow = `${theme.palette.primary.main}0A`;

const contentRef = useRef(null);
const footerRef = useRef(null);
// Kept in a ref so the observer effect below doesn't need to reconnect
// every time the parent re-renders and hands us a new function identity.
const onMeasureRef = useRef(onMeasure);
onMeasureRef.current = onMeasure;

// Reports this card's own natural (unconstrained) required height, so the
// parent can size every card to whichever one needs the most space.
// contentRef/footerRef never stretch (the spacer between them absorbs any
// extra space from an applied minHeight), so this reading is always the
// card's true minimum, regardless of what minHeight is currently applied.
// The observer itself is only (re)created when the card's own content
// changes, not on every parent re-render, to avoid amplifying updates
// during a live resize into a runaway render cascade.
useLayoutEffect(() => {
if (!contentRef.current || !footerRef.current) return;
const report = () => {
onMeasureRef.current?.(
contentRef.current.offsetHeight +
footerRef.current.offsetHeight +
FOOTER_GAP +
VERTICAL_PADDING,
);
};
report();
const observer = new ResizeObserver(report);
observer.observe(contentRef.current);
observer.observe(footerRef.current);
return () => observer.disconnect();
}, [optionName, description]);

return (
<ButtonBase
ref={ref}
Expand All @@ -67,7 +28,6 @@ const OptionBox = forwardRef(function OptionBox(
sx={{
width: "100%",
height: "auto",
minHeight: minHeight ? `${minHeight}px` : "auto",
textAlign: "left",
display: "flex",
flexDirection: "column",
Expand Down Expand Up @@ -105,7 +65,7 @@ const OptionBox = forwardRef(function OptionBox(
}}
{...otherProps}
>
<Box ref={contentRef} sx={{ width: "100%", flexShrink: 0 }}>
<Box sx={{ width: "100%", flexShrink: 0 }}>
{/* Header: icon + badge */}
{(Icon || badge) && (
<Box
Expand Down Expand Up @@ -184,7 +144,6 @@ const OptionBox = forwardRef(function OptionBox(

{/* Footer: chips + arrow */}
<Box
ref={footerRef}
sx={{
mt: "16px",
pt: "14px",
Expand Down
100 changes: 31 additions & 69 deletions DashAI/front/src/components/threeSectionLayout/SelectOptionMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import { useState, useRef, useEffect, useMemo, useCallback } from "react";
import { Box, Grid, Button, Alert, AlertTitle, Skeleton } from "@mui/material";

function useContainerColumns(ref) {
const [size, setSize] = useState(4);
useEffect(() => {
if (!ref.current) return;
const observer = new ResizeObserver(([entry]) => {
const w = entry.contentRect.width;
if (w >= 800) setSize(4);
else if (w >= 500) setSize(6);
else setSize(12);
});
observer.observe(ref.current);
return () => observer.disconnect();
}, [ref]);
return size;
}
import { useState } from "react";
import { Box, Button, Alert, AlertTitle, Skeleton } from "@mui/material";
import SearchBar from "./SearchBar";
import CustomLayout from "../custom/CustomLayout";
import OptionBox from "./OptionBox";
Expand All @@ -39,29 +23,6 @@ export default function SelectOptionMenu({
option.name.toLowerCase().includes(search.toLowerCase()),
);
const { t } = useTranslation(["common", "datasets"]);
const gridRef = useRef(null);
const colSize = useContainerColumns(gridRef);

// Cards share a single dynamic height, sized to fit whichever card's
// content needs the most space, so text never gets cut off. Each OptionBox
// measures its own natural (unconstrained) height and reports it here.
const [cardHeights, setCardHeights] = useState({});
const visibleNames = useMemo(
() => filteredOptions.map((option) => option.name).join("|"),
[filteredOptions],
);
useEffect(() => {
setCardHeights({});
}, [visibleNames]);
const handleMeasure = useCallback((name, height) => {
setCardHeights((prev) =>
prev[name] === height ? prev : { ...prev, [name]: height },
);
}, []);
const cardHeightValues = Object.values(cardHeights);
const cardHeight = cardHeightValues.length
? Math.max(...cardHeightValues)
: null;

return (
<CustomLayout title={title} subtitle={subtitle} padding={0}>
Expand All @@ -71,6 +32,7 @@ export default function SelectOptionMenu({
width={"100%"}
flexDirection={"column"}
justifyContent={"flex-start"}
sx={{ containerType: "inline-size" }}
>
{showNoDatasetAlert && (
<Alert severity="warning" sx={{ mb: 4 }}>
Expand Down Expand Up @@ -100,19 +62,22 @@ export default function SelectOptionMenu({
</Box>
)}

<Grid
ref={gridRef}
container
direction="row"
alignItems="stretch"
spacing={2}
sx={{ mt: 4, mx: 0, maxWidth: "100%" }}
<Box
sx={{
display: "grid",
gridTemplateColumns: {
"@": "repeat(1, minmax(0, 1fr))",
"@500": "repeat(2, minmax(0, 1fr))",
"@800": "repeat(3, minmax(0, 1fr))",
},
gridAutoRows: "1fr",
gap: 2,
mt: 4,
}}
>
{loading
? Array.from({ length: 6 }).map((_, index) => (
<Grid size={colSize} key={index}>
<Skeleton variant="rounded" height={100} />
</Grid>
<Skeleton key={index} variant="rounded" height={100} />
))
: null}
{!loading &&
Expand All @@ -121,27 +86,24 @@ export default function SelectOptionMenu({
option;

return (
<Grid size={colSize} key={index}>
<OptionBox
optionName={display_name}
description={description}
onClick={() => goToNextStep(option.name)}
Icon={Icon}
minHeight={cardHeight}
onMeasure={(height) => handleMeasure(option.name, height)}
dataTour={
dataTour && dataTourTarget && name === dataTourTarget
<OptionBox
key={index}
optionName={display_name}
description={description}
onClick={() => goToNextStep(option.name)}
Icon={Icon}
dataTour={
dataTour && dataTourTarget && name === dataTourTarget
? dataTour
: dataTour && !dataTourTarget
? dataTour
: dataTour && !dataTourTarget
? dataTour
: undefined
}
{...otherProps}
/>
</Grid>
: undefined
}
{...otherProps}
/>
);
})}
</Grid>
</Box>
</Box>

<Box
Expand Down
3 changes: 3 additions & 0 deletions DashAI/front/src/contexts/DatasetsContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function DatasetsProvider({ children }) {

const {
datasets,
datasetsLoaded,
createDataset,
selectedDatasetId,
fetchDatasets,
Expand Down Expand Up @@ -73,6 +74,7 @@ export function DatasetsProvider({ children }) {
const value = useMemo(
() => ({
datasets,
datasetsLoaded,
createDataset,
selectedDatasetId,
fetchDatasets,
Expand All @@ -96,6 +98,7 @@ export function DatasetsProvider({ children }) {
}),
[
datasets,
datasetsLoaded,
createDataset,
selectedDatasetId,
fetchDatasets,
Expand Down
4 changes: 3 additions & 1 deletion DashAI/front/src/hooks/datasets/useDatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import {
export function useDatasets({ t }) {
const { enqueueSnackbar } = useSnackbar();
const [datasets, setDatasets] = useState([]);
const [datasetsLoaded, setDatasetsLoaded] = useState(false);
const [selectedDatasetId, setSelectedDatasetId] = useState(null);
const [datasetRowCount, setDatasetRowCount] = useState(null);

useEffect(() => {
fetchDatasets();
fetchDatasets().finally(() => setDatasetsLoaded(true));
}, []);

// ---------------- actions ----------------
Expand Down Expand Up @@ -198,6 +199,7 @@ export function useDatasets({ t }) {

return {
datasets,
datasetsLoaded,
selectedDatasetId,
createDataset,
fetchDatasets,
Expand Down
Loading