-
Notifications
You must be signed in to change notification settings - Fork 405
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
Align OL measure number format of tooltip to measure panel's one #3673
Merged
offtherailz
merged 3 commits into
geosolutions-it:c125_annotations
from
offtherailz:fix_c125_131
Apr 4, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
48 changes: 48 additions & 0 deletions
48
web/client/components/I18N/enhancers/__tests__/addI18NProps-test.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,48 @@ | ||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const React = require('react'); | ||
const ReactDOM = require('react-dom'); | ||
const {createSink} = require('recompose'); | ||
const expect = require('expect'); | ||
const addI18NProps = require('../addI18NProps'); | ||
var Localized = require('../../Localized'); | ||
|
||
|
||
describe('addI18NProps enhancer', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('addI18NProps format with no context', () => { | ||
const Sink = addI18NProps(['formatNumber'])(createSink(props => { | ||
expect(props).toExist(); | ||
expect(props.formatNumber).toExist(); | ||
// this is the default implementation. | ||
expect(props.formatNumber(1.1)).toBe(1.1); | ||
expect(props.formatNumber(1000)).toBe(1000); | ||
})); | ||
ReactDOM.render(<Sink />, document.getElementById("container")); | ||
}); | ||
it('addI18NProps format numbers', () => { | ||
const Sink = addI18NProps(['formatNumber'])(createSink( props => { | ||
expect(props).toExist(); | ||
expect(props.formatNumber).toExist(); | ||
expect(typeof props.formatNumber(1)).toBe('string'); | ||
expect(props.formatNumber(1.1)).toBe("1.1"); | ||
expect(props.formatNumber(1000)).toBe("1,000"); | ||
})); | ||
ReactDOM.render(<Localized locale="en-EN" messages={{}}> | ||
<Sink /> | ||
</Localized>, document.getElementById("container")); | ||
}); | ||
}); |
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,54 @@ | ||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const {injectIntl} = require('react-intl'); | ||
const PropTypes = require('prop-types'); | ||
const {omit} = require('lodash'); | ||
const { compose, branch, getContext, withProps, withPropsOnChange, mapProps } = require('recompose'); | ||
|
||
const omitProps = keys => mapProps(props => omit(props, keys)); | ||
|
||
// TODO: provide better defaults | ||
const defaults = { | ||
locale: navigator && navigator.language, | ||
formats: { }, | ||
messages: { }, | ||
defaultLocale: 'en', | ||
defaultFormats: {}, | ||
formatDate: v => v, | ||
formatTime: v => v, | ||
formatRelative: v => v, | ||
formatNumber: v => v, | ||
formatPlural: v => v, | ||
formatMessage: v => v, | ||
formatHTMLMessage: v => v, | ||
now: () => new Date() | ||
}; | ||
|
||
/** | ||
* Add i18n functionalities and properties as props. Useful to get format functions when the react-intl components can not be used (i.e. with wrapped libs) | ||
* @name addI18NFormat | ||
* @param {string[]} props add the props to format as props. Should be keys of of this interface https://github.com/yahoo/react-intl/wiki/API#intlshape | ||
* @example | ||
* addI18NProps(['formatNumber'])(MyCmp); // MyCmp will receive `formatNumber` from current locale Intl object as a property | ||
*/ | ||
module.exports = (propsToAdd = []) => compose( | ||
// check intl and inject (or add default dummy object) | ||
getContext({intl: PropTypes.object}), | ||
branch( | ||
({intl}) => !!intl, | ||
injectIntl, | ||
withProps({intl: defaults}) | ||
), | ||
// add propsToAdd properties from intl object | ||
withPropsOnChange(['intl'], ({ intl = {} }) => propsToAdd.reduce((acc = {}, k) => ({ | ||
...acc, | ||
[k]: intl[k] | ||
}), {})), | ||
// clean up intl property | ||
omitProps(['intl']) | ||
); |
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.
Not much readable for me.
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.
I had to refactor it a bit to support existing tests and manage errors. Please take a look at it now, It could be more readable and better documented.