[IM] Move common step containers to shared (#69713)

This commit is contained in:
Alison Goryachev 2020-06-24 12:36:24 -04:00 committed by GitHub
parent b614dbc720
commit 34307c8d13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 90 additions and 73 deletions

View file

@ -6,4 +6,9 @@
export { TabAliases, TabMappings, TabSettings } from './details_panel';
export { StepAliases, StepMappings, StepSettings } from './wizard_steps';
export {
StepAliasesContainer,
StepMappingsContainer,
StepSettingsContainer,
CommonWizardSteps,
} from './wizard_steps';

View file

@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
export { StepAliases } from './step_aliases';
export { StepMappings } from './step_mappings';
export { StepSettings } from './step_settings';
export { StepAliasesContainer } from './step_aliases_container';
export { StepMappingsContainer } from './step_mappings_container';
export { StepSettingsContainer } from './step_settings_container';
export { CommonWizardSteps } from './types';

View file

@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* 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 from 'react';
import { Forms } from '../../../../../shared_imports';
import { CommonWizardSteps } from './types';
import { StepAliases } from './step_aliases';
interface Props {
esDocsBase: string;
}
export const StepAliasesContainer: React.FunctionComponent<Props> = ({ esDocsBase }) => {
const { defaultValue, updateContent } = Forms.useContent<CommonWizardSteps>('aliases');
return (
<StepAliases defaultValue={defaultValue} onChange={updateContent} esDocsBase={esDocsBase} />
);
};

View file

@ -5,20 +5,23 @@
*/
import React from 'react';
import { Forms } from '../../../../shared_imports';
import { documentationService } from '../../../services/documentation';
import { StepMappings } from '../../shared';
import { WizardContent } from '../template_form';
import { Forms } from '../../../../../shared_imports';
import { CommonWizardSteps } from './types';
import { StepMappings } from './step_mappings';
export const StepMappingsContainer = () => {
const { defaultValue, updateContent, getData } = Forms.useContent<WizardContent>('mappings');
interface Props {
esDocsBase: string;
}
export const StepMappingsContainer: React.FunctionComponent<Props> = ({ esDocsBase }) => {
const { defaultValue, updateContent, getData } = Forms.useContent<CommonWizardSteps>('mappings');
return (
<StepMappings
defaultValue={defaultValue}
onChange={updateContent}
indexSettings={getData().settings}
esDocsBase={documentationService.getEsDocsBase()}
esDocsBase={esDocsBase}
/>
);
};

View file

@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* 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 from 'react';
import { Forms } from '../../../../../shared_imports';
import { CommonWizardSteps } from './types';
import { StepSettings } from './step_settings';
interface Props {
esDocsBase: string;
}
export const StepSettingsContainer = React.memo(({ esDocsBase }: Props) => {
const { defaultValue, updateContent } = Forms.useContent<CommonWizardSteps>('settings');
return (
<StepSettings defaultValue={defaultValue} onChange={updateContent} esDocsBase={esDocsBase} />
);
});

View file

@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { Mappings, IndexSettings, Aliases } from '../../../../../../common';
export interface CommonWizardSteps {
settings?: IndexSettings;
mappings?: Mappings;
aliases?: Aliases;
}

View file

@ -8,7 +8,8 @@ export {
TabAliases,
TabMappings,
TabSettings,
StepAliases,
StepMappings,
StepSettings,
StepAliasesContainer,
StepMappingsContainer,
StepSettingsContainer,
CommonWizardSteps,
} from './components';

View file

@ -5,7 +5,4 @@
*/
export { StepLogisticsContainer } from './step_logistics_container';
export { StepAliasesContainer } from './step_aliases_container';
export { StepMappingsContainer } from './step_mappings_container';
export { StepSettingsContainer } from './step_settings_container';
export { StepReviewContainer } from './step_review_container';

View file

@ -1,23 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* 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 from 'react';
import { Forms } from '../../../../shared_imports';
import { documentationService } from '../../../services/documentation';
import { StepAliases } from '../../shared';
import { WizardContent } from '../template_form';
export const StepAliasesContainer = () => {
const { defaultValue, updateContent } = Forms.useContent<WizardContent>('aliases');
return (
<StepAliases
defaultValue={defaultValue}
onChange={updateContent}
esDocsBase={documentationService.getEsDocsBase()}
/>
);
};

View file

@ -1,23 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* 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 from 'react';
import { Forms } from '../../../../shared_imports';
import { documentationService } from '../../../services/documentation';
import { StepSettings } from '../../shared';
import { WizardContent } from '../template_form';
export const StepSettingsContainer = React.memo(() => {
const { defaultValue, updateContent } = Forms.useContent<WizardContent>('settings');
return (
<StepSettings
defaultValue={defaultValue}
onChange={updateContent}
esDocsBase={documentationService.getEsDocsBase()}
/>
);
});

View file

@ -11,13 +11,14 @@ import { EuiSpacer } from '@elastic/eui';
import { TemplateDeserialized, CREATE_LEGACY_TEMPLATE_BY_DEFAULT } from '../../../../common';
import { serializers, Forms } from '../../../shared_imports';
import { SectionError } from '../section_error';
import { StepLogisticsContainer, StepReviewContainer } from './steps';
import {
StepLogisticsContainer,
CommonWizardSteps,
StepSettingsContainer,
StepMappingsContainer,
StepAliasesContainer,
StepReviewContainer,
} from './steps';
} from '../shared';
import { documentationService } from '../../services/documentation';
const { stripEmptyFields } = serializers;
const { FormWizard, FormWizardStep } = Forms;
@ -31,11 +32,8 @@ interface Props {
isEditing?: boolean;
}
export interface WizardContent {
export interface WizardContent extends CommonWizardSteps {
logistics: Omit<TemplateDeserialized, '_kbnMeta' | 'template'>;
settings: TemplateDeserialized['template']['settings'];
mappings: TemplateDeserialized['template']['mappings'];
aliases: TemplateDeserialized['template']['aliases'];
}
export type WizardSection = keyof WizardContent | 'review';
@ -183,15 +181,15 @@ export const TemplateForm = ({
</FormWizardStep>
<FormWizardStep id={wizardSections.settings.id} label={wizardSections.settings.label}>
<StepSettingsContainer />
<StepSettingsContainer esDocsBase={documentationService.getEsDocsBase()} />
</FormWizardStep>
<FormWizardStep id={wizardSections.mappings.id} label={wizardSections.mappings.label}>
<StepMappingsContainer />
<StepMappingsContainer esDocsBase={documentationService.getEsDocsBase()} />
</FormWizardStep>
<FormWizardStep id={wizardSections.aliases.id} label={wizardSections.aliases.label}>
<StepAliasesContainer />
<StepAliasesContainer esDocsBase={documentationService.getEsDocsBase()} />
</FormWizardStep>
<FormWizardStep id={wizardSections.review.id} label={wizardSections.review.label}>