[Canvas] Date format argument refactor. (#106496)
* Refactored date_format argument. Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
3d6aa9f44d
commit
0ebe3657c1
|
@ -5,9 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { compose, withProps } from 'recompose';
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import { DateFormatArgInput as Component, Props as ComponentProps } from './date_format';
|
||||
import { Assign } from '@kbn/utility-types';
|
||||
import { DateFormatArgInput, Props as ComponentProps } from './date_format';
|
||||
import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component';
|
||||
import { ArgumentFactory } from '../../../../types/arguments';
|
||||
import { ArgumentStrings } from '../../../../i18n';
|
||||
|
@ -16,6 +17,10 @@ import { SetupInitializer } from '../../../plugin';
|
|||
|
||||
const { DateFormat: strings } = ArgumentStrings;
|
||||
|
||||
const getDateFormatArgInput = (defaultDateFormats: ComponentProps['dateFormats']) => (
|
||||
props: Assign<ComponentProps, { dateFormats?: ComponentProps['dateFormats'] }>
|
||||
) => <DateFormatArgInput dateFormats={defaultDateFormats} {...props} />;
|
||||
|
||||
export const dateFormatInitializer: SetupInitializer<ArgumentFactory<ComponentProps>> = (
|
||||
core,
|
||||
plugins
|
||||
|
@ -35,12 +40,10 @@ export const dateFormatInitializer: SetupInitializer<ArgumentFactory<ComponentPr
|
|||
text: moment.utc(moment()).format(format),
|
||||
}));
|
||||
|
||||
const DateFormatArgInput = compose<ComponentProps, null>(withProps({ dateFormats }))(Component);
|
||||
|
||||
return () => ({
|
||||
name: 'dateFormat',
|
||||
displayName: strings.getDisplayName(),
|
||||
help: strings.getHelp(),
|
||||
simpleTemplate: templateFromReactComponent(DateFormatArgInput),
|
||||
simpleTemplate: templateFromReactComponent(getDateFormatArgInput(dateFormats)),
|
||||
});
|
||||
};
|
Loading…
Reference in a new issue