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] Moves import buttons in file data visualizer #159722

Merged
merged 10 commits into from Jun 20, 2023

This file was deleted.

This file was deleted.

Expand Up @@ -13,7 +13,6 @@ import { EuiSpacer } from '@elastic/eui';
import { isEqual } from 'lodash';

import { AboutPanel, LoadingPanel } from '../about_panel';
import { BottomBar } from '../bottom_bar';
import { ResultsView } from '../results_view';
import {
FileCouldNotBeRead,
Expand Down Expand Up @@ -54,7 +53,6 @@ export class FileDataVisualizerView extends Component {
mode: MODE.READ,
isEditFlyoutVisible: false,
isExplanationFlyoutVisible: false,
bottomBarVisible: false,
hasPermissionToImport: false,
fileCouldNotBeReadPermissionError: false,
};
Expand Down Expand Up @@ -85,7 +83,6 @@ export class FileDataVisualizerView extends Component {
this.setState(
{
loading: files.length > 0,
bottomBarVisible: files.length > 0,
loaded: false,
fileName: '',
fileContents: '',
Expand Down Expand Up @@ -213,30 +210,18 @@ export class FileDataVisualizerView extends Component {

closeEditFlyout = () => {
this.setState({ isEditFlyoutVisible: false });
this.showBottomBar();
};

showEditFlyout = () => {
this.setState({ isEditFlyoutVisible: true });
this.hideBottomBar();
};

closeExplanationFlyout = () => {
this.setState({ isExplanationFlyoutVisible: false });
this.showBottomBar();
};

showExplanationFlyout = () => {
this.setState({ isExplanationFlyoutVisible: true });
this.hideBottomBar();
};

showBottomBar = () => {
this.setState({ bottomBarVisible: true });
};

hideBottomBar = () => {
this.setState({ bottomBarVisible: false });
};

setOverrides = (overrides) => {
Expand Down Expand Up @@ -282,7 +267,6 @@ export class FileDataVisualizerView extends Component {
mode,
isEditFlyoutVisible,
isExplanationFlyoutVisible,
bottomBarVisible,
hasPermissionToImport,
fileCouldNotBeReadPermissionError,
} = this.state;
Expand Down Expand Up @@ -333,6 +317,9 @@ export class FileDataVisualizerView extends Component {
showEditFlyout={this.showEditFlyout}
showExplanationFlyout={this.showExplanationFlyout}
disableButtons={isEditFlyoutVisible || isExplanationFlyoutVisible}
onChangeMode={this.changeMode}
onCancel={this.onCancel}
disableImport={hasPermissionToImport === false}
/>
)}
<EditFlyout
Expand All @@ -347,18 +334,6 @@ export class FileDataVisualizerView extends Component {
{isExplanationFlyoutVisible && (
<ExplanationFlyout results={results} closeFlyout={this.closeExplanationFlyout} />
)}

{bottomBarVisible && loaded && (
<>
<BottomBar
mode={MODE.READ}
onChangeMode={this.changeMode}
onCancel={this.onCancel}
disableImport={hasPermissionToImport === false}
/>
<BottomPadding />
</>
)}
</>
)}
{mode === MODE.IMPORT && (
Expand All @@ -369,38 +344,17 @@ export class FileDataVisualizerView extends Component {
fileContents={fileContents}
data={data}
dataViewsContract={this.props.dataViewsContract}
showBottomBar={this.showBottomBar}
hideBottomBar={this.hideBottomBar}
fileUpload={this.props.fileUpload}
getAdditionalLinks={this.props.getAdditionalLinks}
capabilities={this.props.capabilities}
mode={MODE.IMPORT}
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ shall we pass the mode variable instead of the constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in 5e16356

onChangeMode={this.changeMode}
onCancel={this.onCancel}
/>

{bottomBarVisible && (
<>
<BottomBar
mode={MODE.IMPORT}
onChangeMode={this.changeMode}
onCancel={this.onCancel}
/>
<BottomPadding />
</>
)}
</>
)}
<Chat />
</div>
);
}
}

function BottomPadding() {
// padding for the BottomBar
return (
<>
<EuiSpacer size="m" />
<EuiSpacer size="l" />
<EuiSpacer size="l" />
</>
);
}
Expand Up @@ -16,6 +16,9 @@ import {
EuiPanel,
EuiSpacer,
EuiTitle,
EuiFlexGroup,
EuiFlexItem,
EuiButtonEmpty,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
Expand All @@ -32,6 +35,7 @@ import {
addCombinedFieldsToMappings,
getDefaultCombinedFields,
} from '../../../common/components/combined_fields';
import { MODE as DATAVISUALIZER_MODE } from '../file_data_visualizer_view/constants';

const DEFAULT_TIME_FIELD = '@timestamp';
const DEFAULT_INDEX_SETTINGS = { number_of_shards: 1 };
Expand Down Expand Up @@ -98,7 +102,7 @@ export class ImportView extends Component {

// TODO - sort this function out. it's a mess
async import() {
const { data, results, dataViewsContract, showBottomBar, fileUpload } = this.props;
const { data, results, dataViewsContract, fileUpload } = this.props;

const { format } = results;
let { timeFieldName } = this.state;
Expand Down Expand Up @@ -149,7 +153,6 @@ export class ImportView extends Component {
permissionCheckStatus: IMPORT_STATUS.COMPLETE,
},
() => {
this.props.hideBottomBar();
setTimeout(async () => {
let success = true;
const createPipeline = pipelineString !== '';
Expand Down Expand Up @@ -309,8 +312,6 @@ export class ImportView extends Component {
}
}

showBottomBar();

this.setState({
importing: false,
imported: success,
Expand Down Expand Up @@ -408,12 +409,10 @@ export class ImportView extends Component {

showFilebeatFlyout = () => {
this.setState({ isFilebeatFlyoutVisible: true });
this.props.hideBottomBar();
};

closeFilebeatFlyout = () => {
this.setState({ isFilebeatFlyoutVisible: false });
this.props.showBottomBar();
};

async loadDataViewNames() {
Expand Down Expand Up @@ -524,28 +523,74 @@ export class ImportView extends Component {
<EuiSpacer size="m" />

{(initialized === false || importing === true) && (
<EuiButton
isDisabled={disableImport}
onClick={this.clickImport}
isLoading={importing}
iconSide="right"
fill
data-test-subj="dataVisualizerFileImportButton"
>
<FormattedMessage
id="xpack.dataVisualizer.file.importView.importButtonLabel"
defaultMessage="Import"
/>
</EuiButton>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButton
isDisabled={disableImport}
onClick={this.clickImport}
isLoading={importing}
iconSide="right"
fill
data-test-subj="dataVisualizerFileImportButton"
>
<FormattedMessage
id="xpack.dataVisualizer.file.importView.importButtonLabel"
defaultMessage="Import"
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={() => this.props.onChangeMode(DATAVISUALIZER_MODE.READ)}
isDisabled={importing}
>
<FormattedMessage
id="xpack.dataVisualizer.file.importView.backButtonLabel"
defaultMessage="Back"
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty onClick={() => this.props.onCancel()} isDisabled={importing}>
<FormattedMessage
id="xpack.dataVisualizer.file.importView.cancelButtonLabel"
defaultMessage="Select a different file"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
)}

{initialized === true && importing === false && (
<EuiButton onClick={this.clickReset}>
<FormattedMessage
id="xpack.dataVisualizer.file.importView.resetButtonLabel"
defaultMessage="Reset"
/>
</EuiButton>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButton onClick={this.clickReset}>
<FormattedMessage
id="xpack.dataVisualizer.file.importView.resetButtonLabel"
defaultMessage="Reset"
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={() => this.props.onChangeMode(DATAVISUALIZER_MODE.READ)}
isDisabled={importing}
>
<FormattedMessage
id="xpack.dataVisualizer.file.importView.backButtonLabel"
defaultMessage="Back"
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty onClick={() => this.props.onCancel()} isDisabled={importing}>
<FormattedMessage
id="xpack.dataVisualizer.file.importView.importNewButtonLabel"
defaultMessage="Import a new file"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
)}
</EuiPanel>

Expand Down