Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: keep prediction in UI #285

Merged
merged 10 commits into from
Jun 6, 2020
17 changes: 12 additions & 5 deletions src/react/components/pages/predict/predictPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,24 @@ export default class PredictPage extends React.Component<IPredictPageProps, IPre
const urlInputDisabled: boolean = !this.state.predictionLoaded || this.state.isFetching;
const predictDisabled: boolean = !this.state.predictionLoaded || !this.state.file;
const predictions = this.getPredictionsFromAnalyzeResult(this.state.analyzeResult);
const fetchDisabled: boolean = !this.state.predictionLoaded || this.state.isFetching ||
this.state.inputedFileURL.length === 0 ||
this.state.inputedFileURL === strings.predict.defaultURLInput;
const fetchDisabled: boolean =
!this.state.predictionLoaded ||
this.state.isFetching ||
this.state.inputedFileURL.length === 0 ||
this.state.inputedFileURL === strings.predict.defaultURLInput;

const sourceOptions: IDropdownOption[] = [
{ key: "localFile", text: "Local file" },
{ key: "url", text: "URL" },
];

const onPredictionPath: boolean = this.props.match.path.includes("predict");

return (
<div className="predict skipToMainContent" id="pagePredict">
<div
className={`predict skipToMainContent ${onPredictionPath ? "" : "hidden"} `}
id="pagePredict"
style={{ display: `${onPredictionPath ? "flex" : "none"}` }} >
<div className="predict-main">
{this.state.file && this.state.imageUri && this.renderImageMap()}
{this.renderPrevPageButton()}
Expand Down Expand Up @@ -296,7 +303,7 @@ export default class PredictPage extends React.Component<IPredictPageProps, IPre
/>
</div>
}
{Object.keys(predictions).length > 0 &&
{Object.keys(predictions).length > 0 && this.props.project &&
<PredictResult
predictions={predictions}
analyzeResult={this.state.analyzeResult}
Expand Down
7 changes: 5 additions & 2 deletions src/react/components/shell/mainContentRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import AppSettingsPage from "../pages/appSettings/appSettingsPage";
import TrainPage from "../pages/train/trainPage";
import ConnectionPage from "../pages/connections/connectionsPage";
import EditorPage from "../pages/editorPage/editorPage";
import PredictPage from "../pages/predict/predictPage";
import ProjectSettingsPage from "../pages/projectSettings/projectSettingsPage";
import { PredictPageRoute } from './preditcPageRoute';


/**
* @name - Main Content Router
* @description - Controls main content pane based on route
*/

export function MainContentRouter() {
return (
<div className="app-content text-light">
Expand All @@ -26,10 +28,11 @@ export function MainContentRouter() {
<Route path="/projects/:projectId/edit" component={EditorPage} />
<Route path="/projects/create" component={ProjectSettingsPage} />
<Route path="/projects/:projectId/train" component={TrainPage} />
<Route path="/projects/:projectId/predict" component={PredictPage} />
<Route path="/projects/:projectId/predict" />
<Route path="/projects/:projectId/settings" component={ProjectSettingsPage} />
<Route component={HomePage} />
</Switch>
<PredictPageRoute />
</div>
);
}
50 changes: 50 additions & 0 deletions src/react/components/shell/preditcPageRoute.tsx
Original file line number Diff line number Diff line change
@@ -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 });
stew-ro marked this conversation as resolved.
Show resolved Hide resolved
}
});

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 &&
<Route
path={[
"/projects/:projectId/predict",
"/projects/:projectId/train",
"/projects/:projectId/edit",
"/projects/:projectId/settings",
"/"]}
component={PredictPage} />
);
}
6 changes: 4 additions & 2 deletions src/react/components/shell/skipButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export class SkipButton extends React.Component<ISkipButtonProps> {
private skipToId = (event: React.MouseEvent<HTMLAnchorElement>) => {
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;
Expand Down