Skip to content

Commit ebb090d

Browse files
authored
[ML] Indicate missing required privileges for import in File Data Viz (#50147) (#50221)
* [ML] show a tooltip which indicates missing required privileges for data import * [ML] fix export * [ML] PR comments
1 parent fa5d6bc commit ebb090d

File tree

7 files changed

+121
-103
lines changed

7 files changed

+121
-103
lines changed

x-pack/legacy/plugins/ml/public/datavisualizer/file_based/components/bottom_bar/bottom_bar.js

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { FC } from 'react';
8+
import { FormattedMessage } from '@kbn/i18n/react';
9+
import {
10+
EuiBottomBar,
11+
EuiButton,
12+
EuiButtonEmpty,
13+
EuiFlexGroup,
14+
EuiFlexItem,
15+
EuiToolTip,
16+
} from '@elastic/eui';
17+
18+
import { MODE as DATAVISUALIZER_MODE } from '../file_datavisualizer_view/constants';
19+
20+
interface BottomBarProps {
21+
mode: DATAVISUALIZER_MODE;
22+
onChangeMode: (mode: DATAVISUALIZER_MODE) => void;
23+
onCancel: () => void;
24+
disableImport?: boolean;
25+
}
26+
27+
/**
28+
* Bottom bar component for Data Visualizer page.
29+
*/
30+
export const BottomBar: FC<BottomBarProps> = ({ mode, onChangeMode, onCancel, disableImport }) => {
31+
if (mode === DATAVISUALIZER_MODE.READ) {
32+
return (
33+
<EuiBottomBar>
34+
<EuiFlexGroup>
35+
<EuiFlexItem grow={false}>
36+
<EuiToolTip
37+
position="top"
38+
content={
39+
disableImport ? (
40+
<FormattedMessage
41+
id="xpack.ml.fileDatavisualizer.bottomBar.missingImportPrivilegesMessage"
42+
defaultMessage="You don't have the privileges required to import data"
43+
/>
44+
) : null
45+
}
46+
>
47+
<EuiButton
48+
fill
49+
isDisabled={disableImport}
50+
onClick={() => onChangeMode(DATAVISUALIZER_MODE.IMPORT)}
51+
>
52+
<FormattedMessage
53+
id="xpack.ml.fileDatavisualizer.bottomBar.readMode.importButtonLabel"
54+
defaultMessage="Import"
55+
/>
56+
</EuiButton>
57+
</EuiToolTip>
58+
</EuiFlexItem>
59+
<EuiFlexItem grow={false}>
60+
<EuiButtonEmpty color="ghost" onClick={() => onCancel()}>
61+
<FormattedMessage
62+
id="xpack.ml.fileDatavisualizer.bottomBar.readMode.cancelButtonLabel"
63+
defaultMessage="Cancel"
64+
/>
65+
</EuiButtonEmpty>
66+
</EuiFlexItem>
67+
</EuiFlexGroup>
68+
</EuiBottomBar>
69+
);
70+
} else {
71+
return (
72+
<EuiBottomBar>
73+
<EuiFlexGroup>
74+
<EuiFlexItem grow={false}>
75+
<EuiButton color="ghost" onClick={() => onChangeMode(DATAVISUALIZER_MODE.READ)}>
76+
<FormattedMessage
77+
id="xpack.ml.fileDatavisualizer.bottomBar.backButtonLabel"
78+
defaultMessage="Back"
79+
/>
80+
</EuiButton>
81+
</EuiFlexItem>
82+
<EuiFlexItem grow={false}>
83+
<EuiButtonEmpty color="ghost" onClick={() => onCancel()}>
84+
<FormattedMessage
85+
id="xpack.ml.fileDatavisualizer.bottomBar.cancelButtonLabel"
86+
defaultMessage="Cancel"
87+
/>
88+
</EuiButtonEmpty>
89+
</EuiFlexItem>
90+
</EuiFlexGroup>
91+
</EuiBottomBar>
92+
);
93+
}
94+
};
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
87
export { BottomBar } from './bottom_bar';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
/**
8+
* File data visualizer modes.
9+
*/
10+
export enum MODE {
11+
READ,
12+
IMPORT,
13+
}

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ import {
3131
reduceData,
3232
hasImportPermission,
3333
} from '../utils';
34-
35-
export const MODE = {
36-
READ: 0,
37-
IMPORT: 1,
38-
};
34+
import { MODE } from './constants';
3935

4036
const UPLOAD_SIZE_MB = 5;
4137

@@ -306,13 +302,12 @@ export class FileDataVisualizerView extends Component {
306302
fields={fields}
307303
/>
308304

309-
<BottomBar
310-
showBar={(bottomBarVisible && loaded)}
305+
{(bottomBarVisible && loaded) && <BottomBar
311306
mode={MODE.READ}
312-
changeMode={this.changeMode}
307+
onChangeMode={this.changeMode}
313308
onCancel={this.onCancel}
314309
disableImport={(hasPermissionToImport === false)}
315-
/>
310+
/>}
316311

317312
<BottomPadding />
318313
</React.Fragment>
@@ -329,12 +324,11 @@ export class FileDataVisualizerView extends Component {
329324
hideBottomBar={this.hideBottomBar}
330325
/>
331326

332-
<BottomBar
333-
showBar={bottomBarVisible}
327+
{bottomBarVisible && <BottomBar
334328
mode={MODE.IMPORT}
335-
changeMode={this.changeMode}
329+
onChangeMode={this.changeMode}
336330
onCancel={this.onCancel}
337-
/>
331+
/>}
338332

339333
<BottomPadding />
340334
</React.Fragment>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*/
66

77

8-
export { FileDataVisualizerView, MODE } from './file_datavisualizer_view';
8+
export { FileDataVisualizerView } from './file_datavisualizer_view';

x-pack/legacy/plugins/ml/public/datavisualizer/file_based/components/utils/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ export function processResults(results) {
116116
};
117117
}
118118

119-
// a check for the minimum privileges needed to create and ingest data into an index.
120-
// if called with no indexName, the check will just look for the minimum cluster privileges.
119+
/**
120+
* A check for the minimum privileges needed to create and ingest data into an index.
121+
* If called with no indexName, the check will just look for the minimum cluster privileges.
122+
* @param {string} indexName
123+
* @returns {Promise<boolean>}
124+
*/
121125
export async function hasImportPermission(indexName) {
122126
const priv = {
123127
cluster: [

0 commit comments

Comments
 (0)