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 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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ export const ResultsLinks: FC<Props> = ({
additionalLinks,
}) => {
const {
services: { fileUpload },
services: {
fileUpload,
application: { getUrlForApp, capabilities },
share: {
urlGenerators: { getUrlGenerator },
},
},
} = useDataVisualizerKibana();

const [duration, setDuration] = useState({
Expand All @@ -72,15 +78,6 @@ export const ResultsLinks: FC<Props> = ({
const [indexPatternManagementLink, setIndexPatternManagementLink] = useState('');
const [generatedLinks, setGeneratedLinks] = useState<Record<string, string>>({});

const {
services: {
application: { getUrlForApp, capabilities },
share: {
urlGenerators: { getUrlGenerator },
},
},
} = useDataVisualizerKibana();

useEffect(() => {
let unmounted = false;

Expand Down Expand Up @@ -137,11 +134,14 @@ export const ResultsLinks: FC<Props> = ({
setIndexManagementLink(
getUrlForApp('management', { path: '/data/index_management/indices' })
);
setIndexPatternManagementLink(
getUrlForApp('management', {
path: `/kibana/indexPatterns${createIndexPattern ? `/patterns/${indexPatternId}` : ''}`,
})
);

if (capabilities.indexPatterns.save === true) {
setIndexPatternManagementLink(
getUrlForApp('management', {
path: `/kibana/indexPatterns${createIndexPattern ? `/patterns/${indexPatternId}` : ''}`,
})
);
}
}

return () => {
Expand Down
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 { CreateDataViewToolTip } from './create_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}
/>
<CreateDataViewToolTip 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}
/>
</CreateDataViewToolTip>

<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 CreateDataViewToolTip: FC<Props> = ({ children, showTooltip }) => {
return (
<EuiToolTip
position="top"
content={
showTooltip ? (
<FormattedMessage
id="xpack.dataVisualizer.file.cannotCreateDataView.tooltip"
defaultMessage="You need permission to create data views."
/>
) : 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,15 @@ export const ImportSettings: FC<Props> = ({
onCombinedFieldsChange,
results,
}) => {
const {
services: {
application: { capabilities },
},
} = useDataVisualizerKibana();

const canCreateDataView =
capabilities.savedObjectsManagement.edit === true || capabilities.indexPatterns.save === true;

const tabs = [
{
id: 'simple-settings',
Expand All @@ -74,6 +84,7 @@ export const ImportSettings: FC<Props> = ({
onCreateIndexPatternChange={onCreateIndexPatternChange}
indexNameError={indexNameError}
combinedFields={combinedFields}
canCreateDataView={canCreateDataView}
/>
</React.Fragment>
),
Expand Down Expand Up @@ -106,6 +117,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 { CreateDataViewToolTip } from './create_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"
/>
<CreateDataViewToolTip 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"
/>
</CreateDataViewToolTip>

<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 All @@ -85,7 +85,7 @@ export class ImportView extends Component {
}

clickReset = () => {
const state = getDefaultState(this.state, this.props.results);
const state = getDefaultState(this.state, this.props.results, this.props.capabilities);
this.setState(state, () => {
this.loadIndexPatternNames();
});
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,19 @@ function getDefaultState(state, results) {

const timeFieldName = results.timestamp_field;

const createIndexPattern =
capabilities.savedObjectsManagement.edit === false && capabilities.indexPatterns.save === false
? false
: state.createIndexPattern;

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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const FileDataVisualizerPage: FC = () => {
},
});
},
canDisplay: async () => true,
canDisplay: async ({ indexPatternId }) => indexPatternId !== '',
},
],
[]
Expand Down