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

[File data visualizer] Disabling create data view based on capabilities #117347

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,7 @@ export class FileDataVisualizerView extends Component {
<div>
{mode === MODE.READ && (
<>
{!loading && !loaded && (
<AboutPanel
onFilePickerChange={this.onFilePickerChange}
disabled={!fileCouldNotBeReadPermissionError}
/>
)}
{!loading && !loaded && <AboutPanel onFilePickerChange={this.onFilePickerChange} />}

{loading && <LoadingPanel />}

Expand Down Expand Up @@ -373,6 +368,7 @@ export class FileDataVisualizerView extends Component {
savedObjectsClient={this.savedObjectsClient}
fileUpload={this.props.fileUpload}
resultsLinks={this.props.resultsLinks}
capabilities={this.props.capabilities}
/>

{bottomBarVisible && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { CombinedField, CombinedFieldsForm } from '../../../common/components/combined_fields';
import { JsonEditor, EDITOR_MODE } from '../json_editor';
import { FindFileStructureResponse } from '../../../../../../file_upload/common';
import { DataViewToolTip } from './data_view_tooltip';
const EDITOR_HEIGHT = '300px';

interface Props {
Expand All @@ -42,6 +43,7 @@ interface Props {
combinedFields: CombinedField[];
onCombinedFieldsChange(combinedFields: CombinedField[]): void;
results: FindFileStructureResponse;
canCreateDataView: boolean;
}

export const AdvancedSettings: FC<Props> = ({
Expand All @@ -63,6 +65,7 @@ export const AdvancedSettings: FC<Props> = ({
combinedFields,
onCombinedFieldsChange,
results,
canCreateDataView,
}) => {
return (
<React.Fragment>
Expand Down Expand Up @@ -98,18 +101,20 @@ export const AdvancedSettings: FC<Props> = ({

<EuiSpacer size="m" />

<EuiCheckbox
id="createIndexPattern"
label={
<FormattedMessage
id="xpack.dataVisualizer.file.advancedImportSettings.createDataViewLabel"
defaultMessage="Create data view"
/>
}
checked={createIndexPattern === true}
disabled={initialized === true}
onChange={onCreateIndexPatternChange}
/>
<DataViewToolTip showTooltip={canCreateDataView === false}>
<EuiCheckbox
id="createIndexPattern"
label={
<FormattedMessage
id="xpack.dataVisualizer.file.advancedImportSettings.createDataViewLabel"
defaultMessage="Create data view"
/>
}
checked={createIndexPattern === true}
disabled={initialized === true || canCreateDataView === false}
onChange={onCreateIndexPatternChange}
/>
</DataViewToolTip>

<EuiSpacer size="s" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 React, { FC } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiToolTip } from '@elastic/eui';

interface Props {
children?: React.ReactElement;
showTooltip: boolean;
}

export const DataViewToolTip: FC<Props> = ({ children, showTooltip }) => {
return (
<EuiToolTip
position="top"
content={
showTooltip ? (
<FormattedMessage
id="xpack.dataVisualizer.file.cannotCreateDataView.tooltip"
defaultMessage="You require permission to create data views"
Copy link
Contributor

@szabosteve szabosteve Nov 3, 2021

Choose a reason for hiding this comment

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

Minor suggestion

Suggested change
defaultMessage="You require permission to create data views"
defaultMessage="You need permission to create data views"

Copy link
Member Author

@jgowdyelastic jgowdyelastic Nov 3, 2021

Choose a reason for hiding this comment

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

Updated in 93f540c

/>
) : null
}
>
{children}
</EuiToolTip>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SimpleSettings } from './simple';
import { AdvancedSettings } from './advanced';
import { CombinedField } from '../../../common/components/combined_fields';
import { FindFileStructureResponse } from '../../../../../../file_upload/common';
import { useDataVisualizerKibana } from '../../../kibana_context';

interface Props {
index: string;
Expand Down Expand Up @@ -56,6 +57,14 @@ export const ImportSettings: FC<Props> = ({
onCombinedFieldsChange,
results,
}) => {
const {
services: {
application: { capabilities },
},
} = useDataVisualizerKibana();

const canCreateDataView = capabilities.savedObjectsManagement.edit as boolean;

const tabs = [
{
id: 'simple-settings',
Expand All @@ -74,6 +83,7 @@ export const ImportSettings: FC<Props> = ({
onCreateIndexPatternChange={onCreateIndexPatternChange}
indexNameError={indexNameError}
combinedFields={combinedFields}
canCreateDataView={canCreateDataView}
/>
</React.Fragment>
),
Expand Down Expand Up @@ -106,6 +116,7 @@ export const ImportSettings: FC<Props> = ({
combinedFields={combinedFields}
onCombinedFieldsChange={onCombinedFieldsChange}
results={results}
canCreateDataView={canCreateDataView}
/>
</React.Fragment>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CombinedField,
CombinedFieldsReadOnlyForm,
} from '../../../common/components/combined_fields';
import { DataViewToolTip } from './data_view_tooltip';

interface Props {
index: string;
Expand All @@ -23,6 +24,7 @@ interface Props {
onCreateIndexPatternChange(): void;
indexNameError: string;
combinedFields: CombinedField[];
canCreateDataView: boolean;
}

export const SimpleSettings: FC<Props> = ({
Expand All @@ -33,6 +35,7 @@ export const SimpleSettings: FC<Props> = ({
onCreateIndexPatternChange,
indexNameError,
combinedFields,
canCreateDataView,
}) => {
return (
<React.Fragment>
Expand Down Expand Up @@ -69,19 +72,21 @@ export const SimpleSettings: FC<Props> = ({

<EuiSpacer size="m" />

<EuiCheckbox
id="createIndexPattern"
label={
<FormattedMessage
id="xpack.dataVisualizer.file.simpleImportSettings.createDataViewLabel"
defaultMessage="Create data view"
/>
}
checked={createIndexPattern === true}
disabled={initialized === true}
onChange={onCreateIndexPatternChange}
data-test-subj="dataVisualizerFileCreateIndexPatternCheckbox"
/>
<DataViewToolTip showTooltip={canCreateDataView === false}>
<EuiCheckbox
id="createIndexPattern"
label={
<FormattedMessage
id="xpack.dataVisualizer.file.simpleImportSettings.createDataViewLabel"
defaultMessage="Create data view"
/>
}
checked={createIndexPattern === true}
disabled={initialized === true || canCreateDataView === false}
onChange={onCreateIndexPatternChange}
data-test-subj="dataVisualizerFileCreateIndexPatternCheckbox"
/>
</DataViewToolTip>

<EuiSpacer size="m" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ImportView extends Component {
constructor(props) {
super(props);

this.state = getDefaultState(DEFAULT_STATE, this.props.results);
this.state = getDefaultState(DEFAULT_STATE, this.props.results, this.props.capabilities);
this.savedObjectsClient = props.savedObjectsClient;
}

Expand Down Expand Up @@ -640,7 +640,7 @@ async function createKibanaIndexPattern(indexPatternName, indexPatterns, timeFie
}
}

function getDefaultState(state, results) {
function getDefaultState(state, results, capabilities) {
const indexSettingsString =
state.indexSettingsString === ''
? JSON.stringify(DEFAULT_INDEX_SETTINGS, null, 2)
Expand All @@ -666,13 +666,17 @@ function getDefaultState(state, results) {

const timeFieldName = results.timestamp_field;

const createIndexPattern =
capabilities.savedObjectsManagement.edit === false ? false : state.createIndexPattern;
pheyos marked this conversation as resolved.
Show resolved Hide resolved

return {
...DEFAULT_STATE,
indexSettingsString,
mappingsString,
pipelineString,
timeFieldName,
combinedFields,
createIndexPattern,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const FileDataVisualizer: FC<Props> = ({ additionalLinks }) => {
http={coreStart.http}
fileUpload={fileUpload}
resultsLinks={additionalLinks}
capabilities={coreStart.application.capabilities}
/>
</KibanaContextProvider>
);
Expand Down