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

[ML] Indicate missing required privileges for import in File Data Visualizer #50147

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import {
EuiBottomBar,
EuiButton,
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
EuiToolTip,
} from '@elastic/eui';

import { MODE as DATAVISUALIZER_MODE } from '../file_datavisualizer_view/constants';

interface BottomBarProps {
mode: DATAVISUALIZER_MODE;
onChangeMode: (mode: DATAVISUALIZER_MODE) => void;
onCancel: () => void;
disableImport?: boolean;
}

/**
* Bottom bar component for Data Visualizer page.
*/
export const BottomBar: FC<BottomBarProps> = ({ mode, onChangeMode, onCancel, disableImport }) => {
if (mode === DATAVISUALIZER_MODE.READ) {
return (
<EuiBottomBar>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiToolTip
position="top"
content={
disableImport ? (
<FormattedMessage
id="xpack.ml.fileDatavisualizer.bottomBar.missingImportPrivilegesMessage"
defaultMessage="You don't have the privileges required to import data"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO do not reads better than don't
You do not have the privileges required to import data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following https://elastic.github.io/eui/#/guidelines/writing, Use contractions section. But ok with do not as well

/>
) : null
}
>
<EuiButton
fill
isDisabled={disableImport}
onClick={() => onChangeMode(DATAVISUALIZER_MODE.IMPORT)}
>
<FormattedMessage
id="xpack.ml.fileDatavisualizer.bottomBar.readMode.importButtonLabel"
defaultMessage="Import"
/>
</EuiButton>
</EuiToolTip>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty color="ghost" onClick={() => onCancel()}>
<FormattedMessage
id="xpack.ml.fileDatavisualizer.bottomBar.readMode.cancelButtonLabel"
defaultMessage="Cancel"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
);
} else {
return (
<EuiBottomBar>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButton color="ghost" onClick={() => onChangeMode(DATAVISUALIZER_MODE.READ)}>
<FormattedMessage
id="xpack.ml.fileDatavisualizer.bottomBar.backButtonLabel"
defaultMessage="Back"
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty color="ghost" onClick={() => onCancel()}>
<FormattedMessage
id="xpack.ml.fileDatavisualizer.bottomBar.cancelButtonLabel"
defaultMessage="Cancel"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/


export { BottomBar } from './bottom_bar';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/**
* File data visualizer modes.
*/
export enum MODE {
READ,
IMPORT,
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ import {
reduceData,
hasImportPermission,
} from '../utils';

export const MODE = {
READ: 0,
IMPORT: 1,
};
import { MODE } from './constants';

const UPLOAD_SIZE_MB = 5;

Expand Down Expand Up @@ -306,13 +302,12 @@ export class FileDataVisualizerView extends Component {
fields={fields}
/>

<BottomBar
showBar={(bottomBarVisible && loaded)}
{(bottomBarVisible && loaded) && <BottomBar
mode={MODE.READ}
changeMode={this.changeMode}
onChangeMode={this.changeMode}
onCancel={this.onCancel}
disableImport={(hasPermissionToImport === false)}
/>
/>}

<BottomPadding />
</React.Fragment>
Expand All @@ -329,12 +324,11 @@ export class FileDataVisualizerView extends Component {
hideBottomBar={this.hideBottomBar}
/>

<BottomBar
showBar={bottomBarVisible}
{bottomBarVisible && <BottomBar
mode={MODE.IMPORT}
changeMode={this.changeMode}
onChangeMode={this.changeMode}
onCancel={this.onCancel}
/>
/>}

<BottomPadding />
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*/


export { FileDataVisualizerView, MODE } from './file_datavisualizer_view';
export { FileDataVisualizerView } from './file_datavisualizer_view';
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ export function processResults(results) {
};
}

// a check for the minimum privileges needed to create and ingest data into an index.
// if called with no indexName, the check will just look for the minimum cluster privileges.
/**
* A check for the minimum privileges needed to create and ingest data into an index.
* If called with no indexName, the check will just look for the minimum cluster privileges.
* @param {string} indexName
* @returns {Promise<boolean>}
*/
export async function hasImportPermission(indexName) {
const priv = {
cluster: [
Expand Down