-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pagination control to datavisualizer failures to rendering all er…
…rors at a single time (#93839) (#94442) * Add pagination control to datavisualizer errors to avoid crashing browser * conditionally render pagination control * tslint Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
ce115b2
commit e319c29
Showing
2 changed files
with
76 additions
and
39 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...ns/ml/public/application/datavisualizer/file_based/components/import_summary/failures.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import React, { Component } from 'react'; | ||
|
||
import { EuiAccordion, EuiPagination } from '@elastic/eui'; | ||
|
||
const PAGE_SIZE = 100; | ||
|
||
export interface DocFailure { | ||
item: number; | ||
reason: string; | ||
doc: { | ||
message: string; | ||
}; | ||
} | ||
|
||
interface Props { | ||
failedDocs: DocFailure[]; | ||
} | ||
|
||
interface State { | ||
page: number; | ||
} | ||
|
||
export class Failures extends Component<Props, State> { | ||
state: State = { page: 0 }; | ||
|
||
_renderPaginationControl() { | ||
return this.props.failedDocs.length > PAGE_SIZE ? ( | ||
<EuiPagination | ||
pageCount={Math.floor(this.props.failedDocs.length / PAGE_SIZE)} | ||
activePage={this.state.page} | ||
onPageClick={(page) => this.setState({ page })} | ||
compressed | ||
/> | ||
) : null; | ||
} | ||
|
||
render() { | ||
const lastDocIndex = this.props.failedDocs.length - 1; | ||
const startIndex = this.state.page * PAGE_SIZE; | ||
const endIndex = startIndex + PAGE_SIZE > lastDocIndex ? lastDocIndex : startIndex + PAGE_SIZE; | ||
return ( | ||
<EuiAccordion | ||
id="failureList" | ||
buttonContent={ | ||
<FormattedMessage | ||
id="xpack.ml.fileDatavisualizer.importSummary.failedDocumentsButtonLabel" | ||
defaultMessage="Failed documents" | ||
/> | ||
} | ||
paddingSize="m" | ||
> | ||
<div className="failure-list"> | ||
{this._renderPaginationControl()} | ||
{this.props.failedDocs.slice(startIndex, endIndex).map(({ item, reason, doc }) => ( | ||
<div key={item}> | ||
<div className="error-message"> | ||
{item}: {reason} | ||
</div> | ||
<div>{JSON.stringify(doc)}</div> | ||
</div> | ||
))} | ||
</div> | ||
</EuiAccordion> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters