forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Canvas] Added formatnumber and formatdate UIs to sidebar (elastic#43059
) * Added formatnumber and formatdate transform UIs * Added rounddate transform * Changed default custom format * Changed to UTC date * Fixed ts error * Fixed help text * Added type def for arguments * Added types for tranforms * Added snapshots * Fixed prop
- Loading branch information
Showing
21 changed files
with
621 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
...n_src/uis/arguments/date_format/__examples__/__snapshots__/date_format.examples.storyshot
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
.../canvas/canvas_plugin_src/uis/arguments/date_format/__examples__/date_format.examples.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 { storiesOf } from '@storybook/react'; | ||
import React from 'react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { DateFormatArgInput } from '../date_format'; | ||
|
||
const dateFormats = [ | ||
{ value: 'l', text: 'Shorthand' }, | ||
{ value: 'x', text: 'Unix' }, | ||
{ value: 'LLL', text: 'Longhand' }, | ||
]; | ||
|
||
storiesOf('arguments/DateFormat', module) | ||
.add('with no format', () => ( | ||
<DateFormatArgInput | ||
dateFormats={dateFormats} | ||
onValueChange={action('onValueChange')} | ||
argValue="" | ||
argId="DateFormatExample1" | ||
renderError={action('renderError')} | ||
/> | ||
)) | ||
.add('with preset format', () => ( | ||
<DateFormatArgInput | ||
dateFormats={dateFormats} | ||
onValueChange={action('onValueChange')} | ||
argValue="LLL" | ||
argId="DateFormatExample2" | ||
renderError={action('renderError')} | ||
/> | ||
)) | ||
.add('with custom format', () => ( | ||
<DateFormatArgInput | ||
dateFormats={dateFormats} | ||
onValueChange={action('onValueChange')} | ||
argValue="MM/DD/YYYY" | ||
argId="DateFormatExample3" | ||
renderError={action('renderError')} | ||
/> | ||
)); |
52 changes: 52 additions & 0 deletions
52
x-pack/legacy/plugins/canvas/canvas_plugin_src/uis/arguments/date_format/date_format.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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, { FunctionComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormatSelect } from '../../../../public/components/format_select/format_select'; | ||
import { ArgumentProps } from '../../../../types/arguments'; | ||
|
||
interface DateFormatOption { | ||
/** A MomentJS format string */ | ||
value: string; | ||
/** The name to display for the format */ | ||
text: string; | ||
} | ||
|
||
export interface Props extends ArgumentProps { | ||
/** An array of number formats options */ | ||
dateFormats: DateFormatOption[]; | ||
/** The handler to invoke when value changes */ | ||
onValueChange: (value: string) => void; | ||
/** The value of the argument */ | ||
argValue: string; | ||
/** The ID for the argument */ | ||
argId: string; | ||
} | ||
|
||
export const DateFormatArgInput: FunctionComponent<Props> = ({ | ||
dateFormats, | ||
onValueChange, | ||
argValue, | ||
argId, | ||
}) => ( | ||
<FormatSelect | ||
argId={argId} | ||
argValue={argValue} | ||
formatOptions={dateFormats} | ||
onValueChange={onValueChange} | ||
defaultCustomFormat="M/D/YY h:ma" | ||
/> | ||
); | ||
|
||
DateFormatArgInput.propTypes = { | ||
dateFormats: PropTypes.arrayOf( | ||
PropTypes.shape({ value: PropTypes.string, text: PropTypes.string }) | ||
).isRequired, | ||
onValueChange: PropTypes.func.isRequired, | ||
argValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]).isRequired, | ||
argId: PropTypes.string.isRequired, | ||
}; |
41 changes: 41 additions & 0 deletions
41
x-pack/legacy/plugins/canvas/canvas_plugin_src/uis/arguments/date_format/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 { compose, withProps } from 'recompose'; | ||
import moment from 'moment'; | ||
import { DateFormatArgInput as Component, Props as ComponentProps } from './date_format'; | ||
import { AdvancedSettings } from '../../../../public/lib/kibana_advanced_settings'; | ||
// @ts-ignore untyped local lib | ||
import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component'; | ||
import { ArgumentFactory } from '../../../../types/arguments'; | ||
|
||
const formatMap = { | ||
DEFAULT: AdvancedSettings.get('dateFormat'), | ||
NANOS: AdvancedSettings.get('dateNanosFormat'), | ||
ISO8601: '', | ||
LOCAL_LONG: 'LLLL', | ||
LOCAL_SHORT: 'LLL', | ||
LOCAL_DATE: 'l', | ||
LOCAL_TIME_WITH_SECONDS: 'LTS', | ||
}; | ||
|
||
const now = moment(); | ||
|
||
const dateFormats = Object.values(formatMap).map(format => ({ | ||
value: format, | ||
text: moment.utc(now).format(format), | ||
})); | ||
|
||
export const DateFormatArgInput = compose<ComponentProps, null>(withProps({ dateFormats }))( | ||
Component | ||
); | ||
|
||
export const dateFormat: ArgumentFactory<ComponentProps> = () => ({ | ||
name: 'dateFormat', | ||
displayName: 'Date Format', | ||
help: 'Select or enter a MomentJS format', | ||
simpleTemplate: templateFromReactComponent(DateFormatArgInput), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.