Skip to content

Commit

Permalink
[Ingest Manager] Fix create data source from integration (#66626) (#6…
Browse files Browse the repository at this point in the history
…6680)

* Fix add datasource button from integration not responsive

* Fix React key prop warnings

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
jen-huang and elasticmachine authored May 15, 2020
1 parent f585220 commit 0da143e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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, { useState, useEffect } from 'react';
import React, { useState, useEffect, useMemo, useCallback } from 'react';
import { useRouteMatch, useHistory } from 'react-router-dom';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -95,32 +95,46 @@ export const CreateDatasourcePage: React.FunctionComponent = () => {
// Datasource validation state
const [validationResults, setValidationResults] = useState<DatasourceValidationResults>();

// Form state
const [formState, setFormState] = useState<DatasourceFormState>('INVALID');

// Update package info method
const updatePackageInfo = (updatedPackageInfo: PackageInfo | undefined) => {
if (updatedPackageInfo) {
setPackageInfo(updatedPackageInfo);
setFormState('VALID');
} else {
setFormState('INVALID');
setPackageInfo(undefined);
}
const updatePackageInfo = useCallback(
(updatedPackageInfo: PackageInfo | undefined) => {
if (updatedPackageInfo) {
setPackageInfo(updatedPackageInfo);
if (agentConfig) {
setFormState('VALID');
}
} else {
setFormState('INVALID');
setPackageInfo(undefined);
}

// eslint-disable-next-line no-console
console.debug('Package info updated', updatedPackageInfo);
};
// eslint-disable-next-line no-console
console.debug('Package info updated', updatedPackageInfo);
},
[agentConfig, setPackageInfo, setFormState]
);

// Update agent config method
const updateAgentConfig = (updatedAgentConfig: AgentConfig | undefined) => {
if (updatedAgentConfig) {
setAgentConfig(updatedAgentConfig);
} else {
setFormState('INVALID');
setAgentConfig(undefined);
}
const updateAgentConfig = useCallback(
(updatedAgentConfig: AgentConfig | undefined) => {
if (updatedAgentConfig) {
setAgentConfig(updatedAgentConfig);
if (packageInfo) {
setFormState('VALID');
}
} else {
setFormState('INVALID');
setAgentConfig(undefined);
}

// eslint-disable-next-line no-console
console.debug('Agent config updated', updatedAgentConfig);
};
// eslint-disable-next-line no-console
console.debug('Agent config updated', updatedAgentConfig);
},
[packageInfo, setAgentConfig, setFormState]
);

const hasErrors = validationResults ? validationHasErrors(validationResults) : false;

Expand Down Expand Up @@ -163,7 +177,6 @@ export const CreateDatasourcePage: React.FunctionComponent = () => {
: getHref('integration_details', { pkgkey });

// Save datasource
const [formState, setFormState] = useState<DatasourceFormState>('INVALID');
const saveDatasource = async () => {
setFormState('LOADING');
const result = await sendCreateDatasource(datasource);
Expand Down Expand Up @@ -215,33 +228,43 @@ export const CreateDatasourcePage: React.FunctionComponent = () => {
packageInfo,
};

const stepSelectConfig = useMemo(
() => (
<StepSelectConfig
pkgkey={pkgkey}
updatePackageInfo={updatePackageInfo}
agentConfig={agentConfig}
updateAgentConfig={updateAgentConfig}
/>
),
[pkgkey, updatePackageInfo, agentConfig, updateAgentConfig]
);

const stepSelectPackage = useMemo(
() => (
<StepSelectPackage
agentConfigId={configId}
updateAgentConfig={updateAgentConfig}
packageInfo={packageInfo}
updatePackageInfo={updatePackageInfo}
/>
),
[configId, updateAgentConfig, packageInfo, updatePackageInfo]
);

const steps: EuiStepProps[] = [
from === 'package'
? {
title: i18n.translate('xpack.ingestManager.createDatasource.stepSelectAgentConfigTitle', {
defaultMessage: 'Select an agent configuration',
}),
children: (
<StepSelectConfig
pkgkey={pkgkey}
updatePackageInfo={updatePackageInfo}
agentConfig={agentConfig}
updateAgentConfig={updateAgentConfig}
/>
),
children: stepSelectConfig,
}
: {
title: i18n.translate('xpack.ingestManager.createDatasource.stepSelectPackageTitle', {
defaultMessage: 'Select an integration',
}),
children: (
<StepSelectPackage
agentConfigId={configId}
updateAgentConfig={updateAgentConfig}
packageInfo={packageInfo}
updatePackageInfo={updatePackageInfo}
/>
),
children: stepSelectPackage,
},
{
title: i18n.translate('xpack.ingestManager.createDatasource.stepDefineDatasourceTitle', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export const DatasourcesTable: React.FunctionComponent<Props> = ({
search={{
toolsRight: [
<EuiButton
key="addDatasourceButton"
isDisabled={!hasWriteCapabilities}
iconType="plusInCircle"
href={getHref('add_datasource_from_configuration', { configId: config.id })}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,12 @@ export const DataStreamListPage: React.FunctionComponent<{}> = () => {
sorting={true}
search={{
toolsRight: [
<EuiButton color="primary" iconType="refresh" onClick={() => sendRequest()}>
<EuiButton
key="reloadButton"
color="primary"
iconType="refresh"
onClick={() => sendRequest()}
>
<FormattedMessage
id="xpack.ingestManager.dataStreamList.reloadDataStreamsButtonText"
defaultMessage="Reload"
Expand Down

0 comments on commit 0da143e

Please sign in to comment.