Skip to content

Conversation

jpggvilaca
Copy link
Contributor

@jpggvilaca jpggvilaca commented Jul 8, 2025

📝 Description

  • Extract explanation query from prediction queries (usePredictionQuery and usePredictionROIQuery)
  • Update interfaces and unit tests

Follow up:

  • Merge usePredictionQuery with usePredictionROIQuery

✨ Type of Change

Select the type of change your PR introduces:

  • 🐞 Bug fix – Non-breaking change which fixes an issue
  • 🚀 New feature – Non-breaking change which adds functionality
  • 🔨 Refactor – Non-breaking change which refactors the code base
  • 💥 Breaking change – Changes that break existing functionality
  • 📚 Documentation update
  • 🔒 Security update
  • 🧪 Tests

🧪 Testing Scenarios

Describe how the changes were tested and how reviewers can test them too:

  • ✅ Tested manually
  • 🤖 Run automated end-to-end tests

✅ Checklist

Before submitting the PR, ensure the following:

  • 🔍 PR title is clear and descriptive
  • 📝 For internal contributors: If applicable, include the JIRA ticket number (e.g., ITEP-123456) in the PR title. Do not include full URLs
  • 💬 I have commented my code, especially in hard-to-understand areas
  • 📄 I have made corresponding changes to the documentation
  • ✅ I have added tests that prove my fix is effective or my feature works

@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 13:18
@jpggvilaca jpggvilaca added the UI label Jul 8, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors how explanation data is fetched by extracting it into its own React Query hook and updating relevant components, providers, interfaces, and tests to consume the new useExplanationsQuery hook instead of bundling explanations with prediction results.

  • Introduce a standalone useExplanationsQuery hook and add an EXPLANATIONS key to query-keys.
  • Remove inline explanation fetching from prediction hooks and providers, wiring in the new explanations query.
  • Update components (TestDetailsPreview, TrainingDatasetDetailsPreview, SelectedMediaItemProvider, PredictionProvider, AnnotatorProvider) and tests to use explanationsQuery and adjust interfaces.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
use-test-results-query.hook.ts Split out explanations query and updated predictionsQuery to only return annotations
test-details-preview.component.tsx Added explanationsQuery and updated explanations source
training-dataset-details-preview.component.tsx Introduced useExplanationsQuery and replaced old maps usage
use-predictions-query.hook.ts Removed inline explanation logic and returned only annotations
use-explanation-query.hook.ts New hook to fetch explanations separately
selected-media-item.interface.ts Extended interface to include optional explanations
selected-media-item-provider.component.tsx Aggregated explanations into selected item and context value
default-selected-media-item-provider.component.tsx Added stub for explanationsQuery in default provider
use-prediction-roi-query.hook.ts Removed explanations from ROI query, now only returns annotations
use-prediction-roi-query.hook.test.tsx Updated tests to reflect removed maps field
prediction-provider.component.tsx Removed setExplanations call in prediction success handler
use-initial-annotations.hook.test.tsx Adapted tests to new predictions-only shape and added explanations
annotator-provider.component.tsx Wired in explanationsQuery data instead of old maps
layers-factory.test.tsx Added explanationsQuery stub in test context
query-keys.ts Added EXPLANATIONS key for query caching
Comments suppressed due to low confidence (1)

web_ui/src/pages/annotator/providers/selected-media-item-provider/use-explanation-query.hook.ts:1

  • [nitpick] Consider renaming this file from use-explanation-query.hook.ts to use-explanations-query.hook.ts so the filename matches the useExplanationsQuery hook and follows the plural naming convention of other query hooks.
// Copyright (C) 2022-2025 Intel Corporation

@jpggvilaca jpggvilaca force-pushed the jvilaca/chore-extract-explanations branch from 4ad36cb to a838fc0 Compare July 8, 2025 13:41
@jpggvilaca jpggvilaca changed the title [DRAFT] :chore: Extract explanations from prediction queries :chore: Extract explanations from prediction queries Jul 8, 2025
image: getMockedImage(),
annotations,
predictions: { annotations: predictions, maps: [] },
predictions: { annotations: predictions },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think on a different PR we can also simplify this interface.


// If we are at task chain's second task, get prediction for the selected ROI input
const predictionsRoiQuery = usePredictionsRoiQuery({
selectedInput,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this file: I think we can refactor this provider so that we no longer need to keep track of the explanations inside of it. Instead it should be possible to retrieve the explanations directly from a query result.

selectedMediaItemQuery,
setSelectedMediaItem: noop,
predictionsQuery: { isLoading: false } as UseQueryResult<PredictionResult>,
explanationsQuery: { isLoading: false } as UseQueryResult<ExplanationResult>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to completely remove this and instead use the query directly?

});

const predictionsQuery = usePredictionsQueryBasedOnAnnotatorMode(mediaItem);
const explanationsQuery = useExplanationsQuery({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question/comment as above: I'd prefer if we can fully remove it from this provider.
The logic in here is already a bit too complex with trying to make a dependant query based on three other queries, adding one more could result in some more subtle bugs.

queryFn: async ({ signal }) => {
if (!mediaItem) throw new Error("Can't fetch undefined media item");

try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for later: we can remove this try catch and rely on the actual query's error after we remove it from our selected media item provider: If we use the query directly in the annotator's toolbar and canvas then we can deal with its error handling locally and inform the user that we weren't able to retrieve explanation maps.

EXPLANATIONS: (
datasetIdentifier: DatasetIdentifier,
mediaIdentifier: MediaIdentifier | undefined,
taskId?: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also depend on the roi? Iirc when we are in task chain we request the explanation map based on a given ROI.

userAnnotationScene={userAnnotationScene}
initPredictions={initialPredictionAnnotations}
explanations={selectedMediaItem?.predictions?.maps || EMPTY_EXPLANATION}
explanations={selectedMediaItem?.explanations || EMPTY_EXPLANATION}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to

Suggested change
explanations={selectedMediaItem?.explanations || EMPTY_EXPLANATION}
explanations={explanationQuery.data?.explanations || EMPTY_EXPLANATION}
// or
explanationsQuery={explanationsQuery}

where we can define the query inside of this function or possibly remove the argument and use this query directly inside of the prediction provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants