Skip to content

Commit 6bea373

Browse files
[ML] Adding initial file analysis overrides (#74376)
* [ML] Adding initial file analysis overrides * using common default sample lines * correcting bottom padding * adding missed padding * code clean up * fixing translations Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent ae52987 commit 6bea373

File tree

4 files changed

+91
-54
lines changed

4 files changed

+91
-54
lines changed

x-pack/plugins/ml/public/application/datavisualizer/file_based/components/file_datavisualizer_view/file_datavisualizer_view.js

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { EditFlyout } from '../edit_flyout';
2020
import { ExplanationFlyout } from '../explanation_flyout';
2121
import { ImportView } from '../import_view';
2222
import {
23+
DEFAULT_LINES_TO_SAMPLE,
2324
getMaxBytes,
2425
readFile,
2526
createUrlOverrides,
@@ -55,7 +56,9 @@ export class FileDataVisualizerView extends Component {
5556

5657
this.overrides = {};
5758
this.previousOverrides = {};
58-
this.originalSettings = {};
59+
this.originalSettings = {
60+
linesToSample: DEFAULT_LINES_TO_SAMPLE,
61+
};
5962
this.maxFileUploadBytes = getMaxBytes();
6063
}
6164

@@ -129,7 +132,7 @@ export class FileDataVisualizerView extends Component {
129132
const serverSettings = processResults(resp);
130133
const serverOverrides = resp.overrides;
131134

132-
this.previousOverrides = this.overrides;
135+
this.previousOverrides = overrides;
133136
this.overrides = {};
134137

135138
if (serverSettings.format === 'xml') {
@@ -185,9 +188,8 @@ export class FileDataVisualizerView extends Component {
185188
serverError: error,
186189
});
187190

188-
// as long as the previous overrides are different to the current overrides,
189191
// reload the results with the previous overrides
190-
if (overrides !== undefined && isEqual(this.previousOverrides, overrides) === false) {
192+
if (isRetry === false) {
191193
this.setState({
192194
loading: true,
193195
loaded: false,
@@ -244,6 +246,11 @@ export class FileDataVisualizerView extends Component {
244246
};
245247

246248
onCancel = () => {
249+
this.overrides = {};
250+
this.previousOverrides = {};
251+
this.originalSettings = {
252+
linesToSample: DEFAULT_LINES_TO_SAMPLE,
253+
};
247254
this.changeMode(MODE.READ);
248255
this.onFilePickerChange([]);
249256
};
@@ -276,7 +283,7 @@ export class FileDataVisualizerView extends Component {
276283
return (
277284
<div>
278285
{mode === MODE.READ && (
279-
<React.Fragment>
286+
<>
280287
{!loading && !loaded && <AboutPanel onFilePickerChange={this.onFilePickerChange} />}
281288

282289
{loading && <LoadingPanel />}
@@ -286,10 +293,14 @@ export class FileDataVisualizerView extends Component {
286293
)}
287294

288295
{fileCouldNotBeRead && loading === false && (
289-
<React.Fragment>
290-
<FileCouldNotBeRead error={serverError} loaded={loaded} />
296+
<>
297+
<FileCouldNotBeRead
298+
error={serverError}
299+
loaded={loaded}
300+
showEditFlyout={this.showEditFlyout}
301+
/>
291302
<EuiSpacer size="l" />
292-
</React.Fragment>
303+
</>
293304
)}
294305

295306
{loaded && (
@@ -298,8 +309,8 @@ export class FileDataVisualizerView extends Component {
298309
explanation={explanation}
299310
fileName={fileName}
300311
data={fileContents}
301-
showEditFlyout={() => this.showEditFlyout()}
302-
showExplanationFlyout={() => this.showExplanationFlyout()}
312+
showEditFlyout={this.showEditFlyout}
313+
showExplanationFlyout={this.showExplanationFlyout}
303314
disableButtons={isEditFlyoutVisible || isExplanationFlyoutVisible}
304315
/>
305316
)}
@@ -317,19 +328,20 @@ export class FileDataVisualizerView extends Component {
317328
)}
318329

319330
{bottomBarVisible && loaded && (
320-
<BottomBar
321-
mode={MODE.READ}
322-
onChangeMode={this.changeMode}
323-
onCancel={this.onCancel}
324-
disableImport={hasPermissionToImport === false}
325-
/>
331+
<>
332+
<BottomBar
333+
mode={MODE.READ}
334+
onChangeMode={this.changeMode}
335+
onCancel={this.onCancel}
336+
disableImport={hasPermissionToImport === false}
337+
/>
338+
<BottomPadding />
339+
</>
326340
)}
327-
328-
<BottomPadding />
329-
</React.Fragment>
341+
</>
330342
)}
331343
{mode === MODE.IMPORT && (
332-
<React.Fragment>
344+
<>
333345
<ImportView
334346
results={results}
335347
fileName={fileName}
@@ -342,15 +354,16 @@ export class FileDataVisualizerView extends Component {
342354
/>
343355

344356
{bottomBarVisible && (
345-
<BottomBar
346-
mode={MODE.IMPORT}
347-
onChangeMode={this.changeMode}
348-
onCancel={this.onCancel}
349-
/>
357+
<>
358+
<BottomBar
359+
mode={MODE.IMPORT}
360+
onChangeMode={this.changeMode}
361+
onCancel={this.onCancel}
362+
/>
363+
<BottomPadding />
364+
</>
350365
)}
351-
352-
<BottomPadding />
353-
</React.Fragment>
366+
</>
354367
)}
355368
</div>
356369
);
@@ -360,10 +373,10 @@ export class FileDataVisualizerView extends Component {
360373
function BottomPadding() {
361374
// padding for the BottomBar
362375
return (
363-
<React.Fragment>
376+
<>
364377
<EuiSpacer size="m" />
365378
<EuiSpacer size="l" />
366379
<EuiSpacer size="l" />
367-
</React.Fragment>
380+
</>
368381
);
369382
}

x-pack/plugins/ml/public/application/datavisualizer/file_based/components/file_datavisualizer_view/file_error_callouts.tsx

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { FormattedMessage } from '@kbn/i18n/react';
88
import React, { FC } from 'react';
99

10-
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
10+
import { EuiCallOut, EuiSpacer, EuiButtonEmpty, EuiHorizontalRule } from '@elastic/eui';
1111

1212
import numeral from '@elastic/numeral';
1313
import { ErrorResponse } from '../../../../../../common/types/errors';
@@ -77,34 +77,57 @@ export const FileTooLarge: FC<FileTooLargeProps> = ({ fileSize, maxFileSize }) =
7777
interface FileCouldNotBeReadProps {
7878
error: ErrorResponse;
7979
loaded: boolean;
80+
showEditFlyout(): void;
8081
}
8182

82-
export const FileCouldNotBeRead: FC<FileCouldNotBeReadProps> = ({ error, loaded }) => {
83+
export const FileCouldNotBeRead: FC<FileCouldNotBeReadProps> = ({
84+
error,
85+
loaded,
86+
showEditFlyout,
87+
}) => {
8388
const message = error?.body?.message || '';
8489
return (
85-
<EuiCallOut
86-
title={
87-
<FormattedMessage
88-
id="xpack.ml.fileDatavisualizer.fileErrorCallouts.fileCouldNotBeReadTitle"
89-
defaultMessage="File could not be read"
90-
/>
91-
}
92-
color="danger"
93-
iconType="cross"
94-
data-test-subj="mlFileUploadErrorCallout fileCouldNotBeRead"
95-
>
96-
{message}
97-
<Explanation error={error} />
98-
{loaded && (
99-
<>
100-
<EuiSpacer size="s" />
90+
<>
91+
<EuiCallOut
92+
title={
10193
<FormattedMessage
102-
id="xpack.ml.fileDatavisualizer.fileErrorCallouts.revertingToPreviousSettingsDescription"
103-
defaultMessage="Reverting to previous settings"
94+
id="xpack.ml.fileDatavisualizer.fileErrorCallouts.fileCouldNotBeReadTitle"
95+
defaultMessage="File structure cannot be determined"
10496
/>
105-
</>
106-
)}
107-
</EuiCallOut>
97+
}
98+
color="danger"
99+
iconType="cross"
100+
data-test-subj="mlFileUploadErrorCallout fileCouldNotBeRead"
101+
>
102+
{loaded === false && (
103+
<>
104+
<FormattedMessage
105+
id="xpack.ml.fileDatavisualizer.fileErrorCallouts.applyOverridesDescription"
106+
defaultMessage="If you know something about this data, such as the file format or timestamp format, adding initial overrides may help us to infer the rest of the structure."
107+
/>
108+
<br />
109+
<EuiButtonEmpty onClick={showEditFlyout} flush="left" size="xs">
110+
<FormattedMessage
111+
id="xpack.ml.fileDatavisualizer.fileErrorCallouts.overrideButton"
112+
defaultMessage="Apply override settings"
113+
/>
114+
</EuiButtonEmpty>
115+
<EuiHorizontalRule />
116+
</>
117+
)}
118+
{message}
119+
<Explanation error={error} />
120+
{loaded && (
121+
<>
122+
<EuiSpacer size="s" />
123+
<FormattedMessage
124+
id="xpack.ml.fileDatavisualizer.fileErrorCallouts.revertingToPreviousSettingsDescription"
125+
defaultMessage="Reverting to previous settings"
126+
/>
127+
</>
128+
)}
129+
</EuiCallOut>
130+
</>
108131
);
109132
};
110133

x-pack/plugins/ml/public/application/datavisualizer/file_based/components/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export {
1111
readFile,
1212
getMaxBytes,
1313
getMaxBytesFormatted,
14+
DEFAULT_LINES_TO_SAMPLE,
1415
} from './utils';

x-pack/plugins/ml/public/application/datavisualizer/file_based/components/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { getUiSettings } from '../../../../util/dependency_cache';
1919
import { FILE_DATA_VISUALIZER_MAX_FILE_SIZE } from '../../../../../../common/constants/settings';
2020

21-
const DEFAULT_LINES_TO_SAMPLE = 1000;
21+
export const DEFAULT_LINES_TO_SAMPLE = 1000;
2222
const UPLOAD_SIZE_MB = 5;
2323

2424
const overrideDefaults = {

0 commit comments

Comments
 (0)