fix: keep analysis results download in sync with api results (#758)
* fix: keep analysis results download in sync with api results * refactor: remove extra files * fix: handle prebuilt predict page * refactor: remove extra lines * fix: include missing props
This commit is contained in:
Родитель
cd782e2a17
Коммит
4b6e3a52ee
|
@ -127,6 +127,7 @@ export class PrebuiltPredictPage extends React.Component<IPrebuiltPredictPagePro
|
|||
tableToViewId: null,
|
||||
};
|
||||
|
||||
private analyzeResults: any;
|
||||
private fileHelper: ILoadFileHelper = new LoadFileHelper();
|
||||
|
||||
private tableHelper: ITableHelper = new TableHelper(this);
|
||||
|
@ -144,6 +145,7 @@ export class PrebuiltPredictPage extends React.Component<IPrebuiltPredictPagePro
|
|||
if (this.state.file) {
|
||||
if (this.state.fileChanged && !this.state.isFetching) {
|
||||
this.loadFile(this.state.file);
|
||||
this.analyzeResults = undefined;
|
||||
} else if (prevState.currentPage !== this.state.currentPage) {
|
||||
this.fileHelper.loadPage(this.state.currentPage).then((res: any) => {
|
||||
if (res) {
|
||||
|
@ -261,7 +263,7 @@ export class PrebuiltPredictPage extends React.Component<IPrebuiltPredictPagePro
|
|||
{Object.keys(predictions).length > 0 &&
|
||||
<PredictResult
|
||||
predictions={predictions}
|
||||
analyzeResult={this.state.analyzeResult}
|
||||
analyzeResult={this.analyzeResults}
|
||||
page={this.state.currentPage}
|
||||
tags={this.state.tags}
|
||||
downloadPrefix={this.state.currentPrebuiltType.name}
|
||||
|
@ -525,6 +527,7 @@ export class PrebuiltPredictPage extends React.Component<IPrebuiltPredictPagePro
|
|||
this.setState({predictionLoaded: false, isPredicting: true});
|
||||
this.getPrediction()
|
||||
.then((result) => {
|
||||
this.analyzeResults = _.cloneDeep(result);
|
||||
this.tableHelper.setAnalyzeResult(result?.analyzeResult);
|
||||
const tags = this.getTagsForPredictResults(this.getPredictionsFromAnalyzeResult(result?.analyzeResult));
|
||||
this.setState({
|
||||
|
|
|
@ -153,6 +153,7 @@ export default class PredictPage extends React.Component<IPredictPageProps, IPre
|
|||
tableToViewId: null,
|
||||
};
|
||||
|
||||
private analyzeResults: any;
|
||||
private selectionHandler: ISelection;
|
||||
private imageMap: ImageMap;
|
||||
private uploadToTrainingSetView: React.RefObject<UploadToTrainingSetView> = React.createRef();
|
||||
|
@ -194,6 +195,7 @@ export default class PredictPage extends React.Component<IPredictPageProps, IPre
|
|||
if (this.state.file) {
|
||||
if (this.state.fileChanged && !this.state.isFetching) {
|
||||
this.loadFile(this.state.file);
|
||||
this.analyzeResults = undefined;
|
||||
} else if (prevState.currentPage !== this.state.currentPage) {
|
||||
|
||||
this.fileHelper.loadPage(this.state.currentPage).then((res: any) => {
|
||||
|
@ -349,7 +351,7 @@ export default class PredictPage extends React.Component<IPredictPageProps, IPre
|
|||
{Object.keys(predictions).length > 0 && this.props.project &&
|
||||
<PredictResult
|
||||
predictions={predictions}
|
||||
analyzeResult={this.state.analyzeResult}
|
||||
analyzeResult={this.analyzeResults}
|
||||
page={this.state.currentPage}
|
||||
tags={this.props.project.tags}
|
||||
downloadResultLabel={this.state.fileLabel}
|
||||
|
@ -622,6 +624,7 @@ export default class PredictPage extends React.Component<IPredictPageProps, IPre
|
|||
this.setState({predictionLoaded: false, isPredicting: true});
|
||||
this.getPrediction()
|
||||
.then((result) => {
|
||||
this.analyzeResults = _.cloneDeep(result);
|
||||
this.tableHelper.setAnalyzeResult(result?.analyzeResult);
|
||||
this.setState({
|
||||
predictionResult: result,
|
||||
|
|
|
@ -145,24 +145,6 @@ export default class PredictResult extends React.Component<IPredictResultProps,
|
|||
);
|
||||
}
|
||||
|
||||
// Helper: Sanitizes the results of prediction in order to align it with API from the service
|
||||
private sanitizeData = (data: any): void => {
|
||||
if (data.hasOwnProperty("analyzeResult")) {
|
||||
const fields: {} = data.analyzeResult.documentResults[0].fields;
|
||||
for (const key in fields) {
|
||||
if (fields[key] !== null) {
|
||||
if (fields[key].hasOwnProperty("displayOrder")) {
|
||||
delete fields[key].displayOrder;
|
||||
}
|
||||
if (fields[key].hasOwnProperty("fieldName")) {
|
||||
delete fields[key].fieldName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private onAddAssetToProject = async () => {
|
||||
if (this.props.onAddAssetToProject) {
|
||||
this.props.onAddAssetToProject();
|
||||
|
@ -170,7 +152,7 @@ export default class PredictResult extends React.Component<IPredictResultProps,
|
|||
}
|
||||
private triggerDownload = (): void => {
|
||||
const { analyzeResult } = this.props;
|
||||
const predictionData = JSON.stringify(this.sanitizeData(analyzeResult));
|
||||
const predictionData = JSON.stringify(analyzeResult);
|
||||
const fileURL = window.URL.createObjectURL(new Blob([predictionData]));
|
||||
const fileLink = document.createElement("a");
|
||||
const fileBaseName = this.props.downloadResultLabel.split(".")[0];
|
||||
|
|
Загрузка…
Ссылка в новой задаче