diff --git a/DashAI/front/src/components/models/ModelCenterContent.jsx b/DashAI/front/src/components/models/ModelCenterContent.jsx index f3c27fa53..c6dc0bd04 100644 --- a/DashAI/front/src/components/models/ModelCenterContent.jsx +++ b/DashAI/front/src/components/models/ModelCenterContent.jsx @@ -20,6 +20,7 @@ export default function ModelsCenterContent() { tasks, loadingTasks, datasets, + datasetsLoaded, selectedDatasetId, step, } = useModels(); @@ -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" diff --git a/DashAI/front/src/components/models/ModelsContext.jsx b/DashAI/front/src/components/models/ModelsContext.jsx index 7183ab34f..bc76c6b41 100644 --- a/DashAI/front/src/components/models/ModelsContext.jsx +++ b/DashAI/front/src/components/models/ModelsContext.jsx @@ -26,6 +26,7 @@ export function ModelsProvider({ children }) { const { datasets, + datasetsLoaded, createDataset, selectedDatasetId, fetchDatasets, @@ -197,6 +198,7 @@ export function ModelsProvider({ children }) { setSelectedModel, setConfigOpen, datasets, + datasetsLoaded, createDataset, selectedDatasetId, fetchDatasets, @@ -290,6 +292,7 @@ export function ModelsProvider({ children }) { selectModel, closeConfig, datasets, + datasetsLoaded, createDataset, selectedDatasetId, fetchDatasets, diff --git a/DashAI/front/src/components/threeSectionLayout/OptionBox.jsx b/DashAI/front/src/components/threeSectionLayout/OptionBox.jsx index eccbf9cb1..3b1f0f0c4 100644 --- a/DashAI/front/src/components/threeSectionLayout/OptionBox.jsx +++ b/DashAI/front/src/components/threeSectionLayout/OptionBox.jsx @@ -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, @@ -15,8 +10,6 @@ const OptionBox = forwardRef(function OptionBox( chips = [], badge = null, dataTour, - minHeight, - onMeasure, ...otherProps }, ref, @@ -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 ( - + {/* Header: icon + badge */} {(Icon || badge) && ( { - 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"; @@ -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 ( @@ -71,6 +32,7 @@ export default function SelectOptionMenu({ width={"100%"} flexDirection={"column"} justifyContent={"flex-start"} + sx={{ containerType: "inline-size" }} > {showNoDatasetAlert && ( @@ -100,19 +62,22 @@ export default function SelectOptionMenu({ )} - {loading ? Array.from({ length: 6 }).map((_, index) => ( - - - + )) : null} {!loading && @@ -121,27 +86,24 @@ export default function SelectOptionMenu({ option; return ( - - goToNextStep(option.name)} - Icon={Icon} - minHeight={cardHeight} - onMeasure={(height) => handleMeasure(option.name, height)} - dataTour={ - dataTour && dataTourTarget && name === dataTourTarget + goToNextStep(option.name)} + Icon={Icon} + dataTour={ + dataTour && dataTourTarget && name === dataTourTarget + ? dataTour + : dataTour && !dataTourTarget ? dataTour - : dataTour && !dataTourTarget - ? dataTour - : undefined - } - {...otherProps} - /> - + : undefined + } + {...otherProps} + /> ); })} - + ({ datasets, + datasetsLoaded, createDataset, selectedDatasetId, fetchDatasets, @@ -96,6 +98,7 @@ export function DatasetsProvider({ children }) { }), [ datasets, + datasetsLoaded, createDataset, selectedDatasetId, fetchDatasets, diff --git a/DashAI/front/src/hooks/datasets/useDatasets.js b/DashAI/front/src/hooks/datasets/useDatasets.js index 001f49913..e05a09311 100644 --- a/DashAI/front/src/hooks/datasets/useDatasets.js +++ b/DashAI/front/src/hooks/datasets/useDatasets.js @@ -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 ---------------- @@ -198,6 +199,7 @@ export function useDatasets({ t }) { return { datasets, + datasetsLoaded, selectedDatasetId, createDataset, fetchDatasets,