diff --git a/src/react/components/pages/predict/predictPage.tsx b/src/react/components/pages/predict/predictPage.tsx index 19d9a407a..ce605430a 100644 --- a/src/react/components/pages/predict/predictPage.tsx +++ b/src/react/components/pages/predict/predictPage.tsx @@ -156,17 +156,24 @@ export default class PredictPage extends React.Component +
{this.state.file && this.state.imageUri && this.renderImageMap()} {this.renderPrevPageButton()} @@ -296,7 +303,7 @@ export default class PredictPage extends React.Component
} - {Object.keys(predictions).length > 0 && + {Object.keys(predictions).length > 0 && this.props.project && @@ -26,10 +28,11 @@ export function MainContentRouter() { - + +
); } diff --git a/src/react/components/shell/preditcPageRoute.tsx b/src/react/components/shell/preditcPageRoute.tsx new file mode 100644 index 000000000..73a3e3014 --- /dev/null +++ b/src/react/components/shell/preditcPageRoute.tsx @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import React, { useEffect, useState } from "react"; +import { Route } from "react-router-dom"; +import { useSelector } from 'react-redux' + +import PredictPage from "../pages/predict/predictPage"; +import { IApplicationState } from '../../../models/applicationState'; + + +/** + * @name - Predict page Route + * @description - Controls rendering of predict page + */ + +export function PredictPageRoute() { + const projectProperties = useSelector((state: IApplicationState) => { + if (state && state.currentProject) { + const { apiKey, folderPath, apiUriBase, id, trainRecord } = state.currentProject; + let modelId: string; + if (trainRecord) { + modelId = trainRecord.modelInfo.modelId; + } + return JSON.stringify({ id, apiKey, apiUriBase, folderPath, modelId }); + } + }); + + const [prevProjectProperties, setPrevProjectProperties] = useState(projectProperties) + const [renderPrediction, setRenderPrediction] = useState(true); + + useEffect(() => { + if (projectProperties !== prevProjectProperties) { + setRenderPrediction(false) // unmounts predictionPageRoute component on projectId or train ModelId change + setPrevProjectProperties(projectProperties); + } + return () => setRenderPrediction(true); + }, [renderPrediction, prevProjectProperties, projectProperties]); + + return (renderPrediction && + + ); +} diff --git a/src/react/components/shell/skipButton.tsx b/src/react/components/shell/skipButton.tsx index b8fc3c26e..810829ef3 100644 --- a/src/react/components/shell/skipButton.tsx +++ b/src/react/components/shell/skipButton.tsx @@ -19,8 +19,10 @@ export class SkipButton extends React.Component { private skipToId = (event: React.MouseEvent) => { event.preventDefault(); - const collection = document.getElementsByClassName(this.props.skipTo); - const element = collection.length > 0 ? collection[0] as HTMLElement : null; + const collection: HTMLCollection = document.getElementsByClassName(this.props.skipTo); + const collectionWithoutHiddenElements = Array.prototype.filter.call(collection, (el: HTMLElement) => !el.classList.contains("hidden")) + + const element = collection.length > 0 ? collectionWithoutHiddenElements[0] as HTMLElement : null; if (!element) { return;