Add selected dataset ID to URL for sharing#19142
Conversation
|
Documentation preview for fd94a22 is available at: More info
|
| import type { EvaluationDataset } from './types'; | ||
| import { ExperimentEvaluationDatasetsPageWrapper } from './ExperimentEvaluationDatasetsPageWrapper'; | ||
| import { ExperimentEvaluationDatasetsEmptyState } from './components/ExperimentEvaluationDatasetsEmptyState'; | ||
| import { useSelectedDatasetBySearchParam } from './hooks/useSelectedDatasetBySearchParam'; |
There was a problem hiding this comment.
is this defined somewhere?
There was a problem hiding this comment.
Sorry, forgot to commit it - pushed!
| // Set the selected dataset if we don't already have one, | ||
| // or if the selected dataset went out of scope (e.g. was deleted / not in search) | ||
| if (!selectedDataset || !datasets.some((d) => d.dataset_id === selectedDataset.dataset_id)) { | ||
| if (datasets?.length && (!selectedDatasetId || !datasetIds.includes(selectedDatasetId))) { |
There was a problem hiding this comment.
not technically a problem with this PR, but can we put this whole state-setting block in an useeffect? otherwise this has risk of very easily causing infinite render loops
useEffect(() => {
// No datasets -> clear selection
if (!datasets?.length) {
setSelectedDataset(undefined);
setSelectedDatasetId(undefined);
return;
}
// Valid selectedDatasetId from URL -> use it
if (selectedDatasetId) {
const matchingDataset = datasets.find((d) => d.dataset_id === selectedDatasetId);
if (matchingDataset) {
setSelectedDataset(matchingDataset);
return;
}
}
// No valid selection -> auto-select first
const sortedRows = table.getRowModel().rows;
if (sortedRows.length > 0) {
const firstDataset = sortedRows[0].original;
setSelectedDataset(firstDataset);
setSelectedDatasetId(firstDataset.dataset_id);
}
}, [datasets, selectedDatasetId, setSelectedDataset, setSelectedDatasetId, table]);
There was a problem hiding this comment.
Totally - done.
otherwise this has risk of very easily causing infinite render loops
I actually observed this while iterating on the PR - glad there's a better way :)
| import { useCallback } from 'react'; | ||
| import { useSearchParams } from '@mlflow/mlflow/src/common/utils/RoutingUtils'; | ||
|
|
||
| const QUERY_PARAM_KEY = 'selectedDataset'; |
There was a problem hiding this comment.
nit: add Id to make it clear + align with the name in code?
| const QUERY_PARAM_KEY = 'selectedDataset'; | |
| const QUERY_PARAM_KEY = 'selectedDatasetId'; |
| const [datasetListHidden, setDatasetListHidden] = useState(false); | ||
| const [selectedDataset, setSelectedDataset] = useState<EvaluationDataset | undefined>(undefined); | ||
| const [isDatasetsLoading, setIsDatasetsLoading] = useState(false); | ||
| const [selectedDatasetId, setSelectedDatasetId] = useSelectedDatasetBySearchParam(); |
There was a problem hiding this comment.
rather than using the hook here and passing it down to ExperimentEvaluationDatasetsListTable, can we just use it in ExperimentEvaluationDatasetsListTable directly?
There was a problem hiding this comment.
oh i think i see what the intention was. can we define a callback that combines setSelectedDataset and setSelectedDatasetId and pass that in instead (similar to what we did in https://github.com/mlflow/mlflow/pull/19142/files#diff-e2232542c52cc97ec1dd208f20ebfc9ded43289282fa3c8f378b8aa1a318445bR109:
| const [selectedDatasetId, setSelectedDatasetId] = useSelectedDatasetBySearchParam(); | |
| const [selectedDatasetId, setSelectedDatasetId] = useSelectedDatasetBySearchParam(); | |
| const onSelectDataset = useCallback((dataset) => { | |
| setSelectedDataset(dataset); | |
| setSelectedDatasetId(dataset.dataset_id); | |
| }); |
There was a problem hiding this comment.
ignore the above comments! once we address https://github.com/mlflow/mlflow/pull/19142/files#r2579393406 it should be taken care of.
| // Sync dataset selection state with URL and available datasets | ||
| useEffect(() => { |
There was a problem hiding this comment.
nit: not sure if this needs to be an effect: https://react.dev/learn/you-might-not-need-an-effect
the original was not written with an effect
There was a problem hiding this comment.
Yeah, this was guidance from @danielseong1 - I reverted to not use an effect
| // Sync selectedDataset object when selectedDatasetId changes (e.g., from URL) | ||
| if (selectedDataset?.dataset_id !== selectedDatasetId) { | ||
| const datasetFromId = datasets?.find((d) => d.dataset_id === selectedDatasetId); | ||
| if (datasetFromId) { | ||
| setSelectedDataset(datasetFromId); | ||
| } | ||
| } |
There was a problem hiding this comment.
actually thinking about it further, i think we should just remove selectedDataset as a state field entirely. it should just purely be derived from datasets + selectedDatasetId. it's weird to have two sources of truth here and have to keep them in sync.
can we lift the useSearchEvaluationDatasets call (lines 177 - 185 above) to the parent component, and pass datasets in here? then we can do something like const selectedDataset = datasets.find(dataset => dataset.dataset_id === selectedDatasetId) rather than having it be in state
- Rename query param key to 'selectedDatasetId' for clarity - Lift useSearchEvaluationDatasets to parent component - Derive selectedDataset from datasets + selectedDatasetId - Remove duplicate state, simplify auto-selection logic Signed-off-by: dbczumar <corey.zumar@databricks.com>
Address review comment to make child component purely presentational by moving the auto-selection useEffect to the parent component. Signed-off-by: dbczumar <corey.zumar@databricks.com>
Signed-off-by: dbczumar <corey.zumar@databricks.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
Add selected dataset ID to URL for sharing
How is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.