-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose prettyDuration and commonDurationRanges #2132
Merged
chandlerprall
merged 12 commits into
elastic:master
from
chandlerprall:feature/2118-pretty-print
Jul 18, 2019
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
78adb84
Expose prettyDuration and commonDurationRanges
chandlerprall f6ff441
prettyDuration docs
chandlerprall 88abe91
changelog
chandlerprall 432c781
Merge branch 'master' into feature/2118-pretty-print
chandlerprall c721c8d
Merge branch 'master' into feature/2118-pretty-print
chandlerprall 460a02b
changelog
chandlerprall 899e953
Update src-docs/src/views/pretty_duration/pretty_duration.js
chandlerprall 5bfe171
Update src-docs/src/views/pretty_duration/pretty_duration_example.js
chandlerprall f0fcd06
Update src-docs/src/views/pretty_duration/pretty_duration.js
chandlerprall 10faccc
Update src-docs/src/views/pretty_duration/pretty_duration.js
chandlerprall 389449c
docs tweaks
chandlerprall 7213fc1
lint fix
chandlerprall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { Fragment } from 'react'; | ||
|
||
import { | ||
EuiSpacer, | ||
EuiCodeBlock, | ||
prettyDuration, | ||
} from '../../../../src/components'; | ||
|
||
const examples = [ | ||
{ | ||
start: '2018-01-17T18:57:57.149Z', | ||
end: '2018-01-17T20:00:00.000Z', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY, HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: '2018-01-17T18:57:57.149Z', | ||
end: '2018-01-17T20:00:00.000Z', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY @ HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: '2018-01-17T18:57:57.149Z', | ||
end: 'now-2h', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY @ HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: 'now-17m', | ||
end: 'now', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY @ HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: 'now-17m', | ||
end: 'now-1m', | ||
quickRanges: [], | ||
dateFormat: 'MMMM Do YYYY @ HH:mm:ss.SSS', | ||
}, | ||
{ | ||
start: 'now-15m', | ||
end: 'now', | ||
quickRanges: [ | ||
{ | ||
start: 'now-15m', | ||
end: 'now', | ||
label: 'quick range 15 minutes custom display', | ||
}, | ||
], | ||
dateFormat: 'MMMM Do YYYY, HH:mm:ss.SSS', | ||
}, | ||
]; | ||
|
||
export default function prettyDurationExample() { | ||
return ( | ||
<Fragment> | ||
{examples.map(({ start, end, quickRanges, dateFormat }, idx) => ( | ||
<div key={idx}> | ||
<EuiCodeBlock paddingSize="s"> | ||
prettyDuration('{start}', '{end}',{' '} | ||
{JSON.stringify(quickRanges)}, ' | ||
{dateFormat}') | ||
</EuiCodeBlock> | ||
|
||
<EuiSpacer size="xs" /> | ||
chandlerprall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{prettyDuration(start, end, quickRanges, dateFormat)} | ||
chandlerprall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<EuiSpacer size="xl" /> | ||
</div> | ||
))} | ||
</Fragment> | ||
); | ||
} |
65 changes: 65 additions & 0 deletions
65
src-docs/src/views/pretty_duration/pretty_duration_example.js
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,65 @@ | ||
import React, { Fragment } from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { GuideSectionTypes } from '../../components'; | ||
|
||
import { | ||
EuiAccordion, | ||
EuiCode, | ||
EuiCodeBlock, | ||
commonDurationRanges, | ||
} from '../../../../src/components'; | ||
|
||
import PrettyDuration from './pretty_duration'; | ||
const prettyDurationSource = require('!!raw-loader!./pretty_duration'); | ||
const prettyDurationHtml = renderToHtml(PrettyDuration); | ||
|
||
export const PrettyDurationExample = { | ||
title: 'Pretty Duration', | ||
sections: [ | ||
{ | ||
source: [ | ||
{ | ||
type: GuideSectionTypes.JS, | ||
code: prettyDurationSource, | ||
}, | ||
{ | ||
type: GuideSectionTypes.HTML, | ||
code: prettyDurationHtml, | ||
}, | ||
], | ||
text: ( | ||
<Fragment> | ||
<p> | ||
Use <EuiCode>prettyDuration</EuiCode> to convert a start and end | ||
date string to a human-friendly format. | ||
</p> | ||
|
||
<p> | ||
Start and end values for the duration are passed as the first and | ||
second arguments, respectively. These can be timestamps ( | ||
<EuiCode>2018-01-17T18:57:57.149Z</EuiCode>) or relative times ( | ||
<EuiCode>now-15m</EuiCode>). | ||
</p> | ||
|
||
<p> | ||
An array of quick range values is passed as the third argument. | ||
These are used to pretty format custom ranges. EUI exports | ||
<EuiCode>commonDurationRanges</EuiCode> which can be passed here. | ||
<EuiAccordion buttonContent="show commonDurationRanges definition"> | ||
chandlerprall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<EuiCodeBlock> | ||
{JSON.stringify(commonDurationRanges, null, 2)} | ||
</EuiCodeBlock> | ||
</EuiAccordion> | ||
</p> | ||
|
||
<p> | ||
The output date/time format is specified by the fourth argument. | ||
</p> | ||
</Fragment> | ||
), | ||
demo: <PrettyDuration />, | ||
}, | ||
], | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { EuiSuperDatePicker } from './super_date_picker'; | ||
|
||
export { EuiSuperUpdateButton } from './super_update_button'; | ||
|
||
export { prettyDuration, commonDurationRanges } from './pretty_duration'; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same example as above. Can remove this copy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
dateFormat
is altered slightly in the second example.