Skip to content

Commit

Permalink
Fix edit datasource not working following changes in elastic#67234
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Jun 8, 2020
1 parent 1e45e98 commit 37362fe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { CreateDatasourceFrom } from '../types';
export interface CustomConfigureDatasourceProps {
packageName: string;
from: CreateDatasourceFrom;
datasource: NewDatasource | (NewDatasource & { id: string });
datasource: NewDatasource;
datasourceId?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import { CreateDatasourceFrom } from './types';
export const StepConfigureDatasource: React.FunctionComponent<{
from?: CreateDatasourceFrom;
packageInfo: PackageInfo;
datasource: NewDatasource | (NewDatasource & { id: string });
datasource: NewDatasource;
datasourceId?: string;
updateDatasource: (fields: Partial<NewDatasource>) => void;
validationResults: DatasourceValidationResults;
submitAttempted: boolean;
}> = ({
from = 'config',
packageInfo,
datasource,
datasourceId,
updateDatasource,
validationResults,
submitAttempted,
Expand Down Expand Up @@ -70,9 +72,10 @@ export const StepConfigureDatasource: React.FunctionComponent<{
) : (
<EuiPanel>
<CustomConfigureDatasource
from={from}
packageName={packageInfo.name}
datasource={datasource}
from={from}
datasourceId={datasourceId}
/>
</EuiPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ export const EditDatasourcePage: React.FunctionComponent = () => {
const [loadingError, setLoadingError] = useState<Error>();
const [agentConfig, setAgentConfig] = useState<AgentConfig>();
const [packageInfo, setPackageInfo] = useState<PackageInfo>();
const [datasource, setDatasource] = useState<NewDatasource & { id: string }>({
id: '',
const [datasource, setDatasource] = useState<NewDatasource>({
name: '',
description: '',
config_id: '',
Expand All @@ -94,6 +93,7 @@ export const EditDatasourcePage: React.FunctionComponent = () => {
}
if (datasourceData?.item) {
const {
id,
revision,
inputs,
created_by,
Expand Down Expand Up @@ -302,6 +302,7 @@ export const EditDatasourcePage: React.FunctionComponent = () => {
from={'edit'}
packageInfo={packageInfo}
datasource={datasource}
datasourceId={datasourceId}
updateDatasource={updateDatasource}
validationResults={validationResults!}
submitAttempted={formState === 'INVALID'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,21 @@ import { LinkToApp } from '../../../../../common/components/endpoint/link_to_app
import {
CustomConfigureDatasourceContent,
CustomConfigureDatasourceProps,
NewDatasource,
} from '../../../../../../../ingest_manager/public';
import { getManagementUrl } from '../../../..';

type DatasourceWithId = NewDatasource & { id: string };

/**
* Exports Endpoint-specific datasource configuration instructions
* for use in the Ingest app create / edit datasource config
*/
export const ConfigureEndpointDatasource = memo<CustomConfigureDatasourceContent>(
({
from,
datasource,
}: {
from: string;
datasource: CustomConfigureDatasourceProps['datasource'];
}) => {
({ from, datasourceId }: CustomConfigureDatasourceProps) => {
const { services } = useKibana();
let policyUrl = '';
if (from === 'edit') {
if (from === 'edit' && datasourceId) {
policyUrl = getManagementUrl({
name: 'policyDetails',
policyId: (datasource as DatasourceWithId).id,
policyId: datasourceId,
});
}

Expand Down

0 comments on commit 37362fe

Please sign in to comment.