From ca4db1652e761be673f216d253f5a4f467ba37fa Mon Sep 17 00:00:00 2001 From: Irozuku Date: Wed, 2 Dec 2026 17:12:00 -0300 Subject: [PATCH 1/3] fix: set option card columns with container queries --- .../threeSectionLayout/SelectOptionMenu.jsx | 51 +++++++------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/DashAI/front/src/components/threeSectionLayout/SelectOptionMenu.jsx b/DashAI/front/src/components/threeSectionLayout/SelectOptionMenu.jsx index fd2a800581..d35b297c7c 100644 --- a/DashAI/front/src/components/threeSectionLayout/SelectOptionMenu.jsx +++ b/DashAI/front/src/components/threeSectionLayout/SelectOptionMenu.jsx @@ -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, useEffect, useMemo, useCallback } 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,8 +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 @@ -71,6 +53,7 @@ export default function SelectOptionMenu({ width={"100%"} flexDirection={"column"} justifyContent={"flex-start"} + sx={{ containerType: "inline-size" }} > {showNoDatasetAlert && ( @@ -100,19 +83,21 @@ export default function SelectOptionMenu({ )} - {loading ? Array.from({ length: 6 }).map((_, index) => ( - - - + )) : null} {!loading && @@ -121,7 +106,7 @@ export default function SelectOptionMenu({ option; return ( - + - + ); })} - + Date: Wed, 2 Dec 2026 17:16:23 -0300 Subject: [PATCH 2/3] fix: size option cards with grid rows instead of measuring them --- .../threeSectionLayout/OptionBox.jsx | 45 +-------------- .../threeSectionLayout/SelectOptionMenu.jsx | 55 ++++++------------- 2 files changed, 18 insertions(+), 82 deletions(-) diff --git a/DashAI/front/src/components/threeSectionLayout/OptionBox.jsx b/DashAI/front/src/components/threeSectionLayout/OptionBox.jsx index eccbf9cb1e..3b1f0f0c41 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) && ( 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 ( - 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} + /> ); })} From 0f01275dfb89aedc630a1f930a2b70f68287530d Mon Sep 17 00:00:00 2001 From: Irozuku Date: Wed, 2 Dec 2026 17:19:35 -0300 Subject: [PATCH 3/3] fix: show the no datasets alert only after datasets load --- DashAI/front/src/components/models/ModelCenterContent.jsx | 5 ++++- DashAI/front/src/components/models/ModelsContext.jsx | 3 +++ DashAI/front/src/contexts/DatasetsContext.jsx | 3 +++ DashAI/front/src/hooks/datasets/useDatasets.js | 4 +++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/DashAI/front/src/components/models/ModelCenterContent.jsx b/DashAI/front/src/components/models/ModelCenterContent.jsx index f3c27fa535..c6dc0bd049 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 7183ab34f6..bc76c6b41e 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/contexts/DatasetsContext.jsx b/DashAI/front/src/contexts/DatasetsContext.jsx index 164b5c2bb6..e4581c4200 100644 --- a/DashAI/front/src/contexts/DatasetsContext.jsx +++ b/DashAI/front/src/contexts/DatasetsContext.jsx @@ -18,6 +18,7 @@ export function DatasetsProvider({ children }) { const { datasets, + datasetsLoaded, createDataset, selectedDatasetId, fetchDatasets, @@ -73,6 +74,7 @@ export function DatasetsProvider({ children }) { const value = useMemo( () => ({ 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 001f49913d..e05a093110 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,