Skip to content
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

Fix #7722 Improved header validation on CSV import #7950

Merged
merged 1 commit into from
Aug 17, 2016

Conversation

ck-lee
Copy link
Contributor

@ck-lee ck-lee commented Aug 6, 2016

@elasticmachine
Copy link
Contributor

Can one of the admins verify this patch?

@ck-lee
Copy link
Contributor Author

ck-lee commented Aug 6, 2016

Screenshot for reference...
image

@Bargs Bargs self-assigned this Aug 8, 2016
@Bargs
Copy link
Contributor

Bargs commented Aug 8, 2016

@ck-lee Thanks for the contribution! I'll try to review this as soon as I can

@Bargs Bargs added the review label Aug 8, 2016
describe('simple validations', function () {

it('should return empty array if fields are valid', function () {
var errors = validateHeaders(['aa', 'bb', 'cc', 'dd', 'ee']);
Copy link
Contributor

@Bargs Bargs Aug 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const here, and if you need mutability prefer let over var. This applies to the whole file, but I'll just leave this one note here

@Bargs
Copy link
Contributor

Bargs commented Aug 12, 2016

@ck-lee this looks great! I really appreciate the thorough tests you included. I added some comments, but it's all pretty minor stuff

@ck-lee
Copy link
Contributor Author

ck-lee commented Aug 13, 2016

@Bargs: Thanks again. Please review.

const errors = [];

const fieldsWithPositions = _.reduce(fields, (result, field, index) => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for a newline here

@Bargs
Copy link
Contributor

Bargs commented Aug 16, 2016

@thomasneirynck could you do a second review?

@thomasneirynck
Copy link
Contributor

@Bargs will do!

@ck-lee ck-lee force-pushed the better-csv-import-errors-messages branch 2 times, most recently from 18a9188 to 78e23e0 Compare August 16, 2016 19:37
export default function validateHeaders(fields) {
if (!_.isArray(fields)) {
throw new Error('first argument must be an array');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove this guard clause. This isn't really public API for 3rd party clients, where throwing runtime errors can be helpful.

Some clean JSDoc on the function signature would tell the story just as well IMO, and it'd be less code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with that, I still think it's a good idea to enforce your preconditions. Especially when using lodash where many of the functions can operate on both objects and arrays, not checking your arguments could lead to hard to find bugs that don't throw errors.

That said, it's not in our styleguide and it's a minor issue here, so it's not worth holding up this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. This is a minor one. And I think it is worth considering in the future if the validateHeaders module grows more than a couple validation checks.

@thomasneirynck
Copy link
Contributor

great! minor suggestions to reduce code footprint, but LGTM.

@ck-lee
Copy link
Contributor Author

ck-lee commented Aug 17, 2016

All done now. @thomasneirynck Please review. I will do a squash when it is ready to be merged.

@thomasneirynck
Copy link
Contributor

@ck-lee, thanks! LGTM

@Bargs
Copy link
Contributor

Bargs commented Aug 17, 2016

LGTM too, @ck-lee squash away and we'll get this thing merged!

Fix eslint

Comment on code

Separate validation logic to lib
Unit tests

Code formatting

Use const for immutables and arrays
Multiline condition statement with brackets
Fix whitespace

Added unit tests for argument validations

Simplify validateHeaders by using lodash reduce

Fix formatting after code review

Use arrow function

Removed redundant unit tests.
Added jsdoc
Removed argument validations.

Minor comment fix.
@ck-lee ck-lee force-pushed the better-csv-import-errors-messages branch from 00c107e to 49c4d7b Compare August 17, 2016 19:13
@ck-lee
Copy link
Contributor Author

ck-lee commented Aug 17, 2016

Squashed! Woohoo... This would be my first major PR. Thank you @thomasneirynck @Bargs

@Bargs
Copy link
Contributor

Bargs commented Aug 17, 2016

Thank YOU @ck-lee, this is a great contribution!

@Bargs Bargs merged commit 56b2695 into elastic:master Aug 17, 2016
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
…messages

Fix elastic#7722 Improved header validation on CSV import

Former-commit-id: 56b2695
cee-chen added a commit that referenced this pull request Aug 14, 2024
`v95.6.0` ⏩ `v95.7.0`

_[Questions? Please see our Kibana upgrade
FAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)_

---

## [`v95.7.0`](https://github.com/elastic/eui/releases/v95.7.0)

**CSS-in-JS conversions**

- Converted `EuiSelectable` to Emotion
([#7940](elastic/eui#7940))
  - Removed `$euiSelectableListItemBorder`
  - Removed `$euiSelectableListItemPadding`
- Converted `EuiSelectableTemplateSitewide` to Emotion
([#7944](elastic/eui#7944))
  - Removed `$euiSelectableTemplateFocusBackgroundLight`
  - Removed `$euiSelectableTemplateFocusBackgroundDark`
  - Removed `$euiSelectableTemplateSitewideTypes`
- Converted `EuiComboBox` to Emotion
([#7950](elastic/eui#7950))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants