-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Do not remove selection when clicking refresh fields #8312
Conversation
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.
What are your thoughts on simply updating the updateFieldList() function as to not introduce another conditional path?
function updateFieldList(results) {
index.fetchFieldsError = results.fetchFieldsError;
index.dateFields = results.dateFields;
if (results.dateFields.length && index.timeField) {
const matchingField = results.dateFields.find(field => field.name === index.timeField.name);
index.timeField = matchingField ? matchingField : results.dateFields[0];
}
}
mostly because of this:
There's also the fact that by moving the conditional higher up, the autocomplete is tied to actually clicking the "refresh fields" button. Otherwise, it would also occur on index-changes, where I'm not sure if its necessary. |
const matchingField = results.dateFields.find(field => field.name === seedField.name); | ||
index.timeField = matchingField ? matchingField : results.dateFields[0]; | ||
|
||
} |
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.
1 minor nit: I haven't generally seen function bodies with whitespace padding in the codebase, and I know the AirBnB style-guide complains about it by default. It's up to you, but it might be a little more consistent/future-proof to remove the padding.
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.
Also, I think we should tweak the names here to reinforce the intent of seeding the date field. As it is, it isn't clear that this function is specific to date fields unless you read its implementation and get to line 265.
I think we can make the logic a little clearer by renaming matchingField
to something which reflects its role as a flag, because we don't really want to set it as the timeField
value, we want to set the value passed into the function.
function updateFieldListAndSetTimeField(results, timeField) {
updateFieldList(results);
if (!results.dateFields.length) {
return;
}
const defaultTimeField = results.dateFields[0];
const isTimeFieldAvailable = results.dateFields.find(field => field.name === timeField.name);
index.timeField = isTimeFieldAvailable ? timeField : defaultTimeField;
}
Lastly, how about combining this with updateFieldList
and using timeField
as an optional argument? Then you won't need a condition inside of refreshFieldList
:
function updateFieldList(results, timeField = undefined) {
index.fetchFieldsError = results.fetchFieldsError;
index.dateFields = results.dateFields;
if (!timeField) {
return;
}
if (!results.dateFields.length) {
return;
}
const defaultTimeField = results.dateFields[0];
const isTimeFieldAvailable = results.dateFields.find(field => field.name === timeField.name);
index.timeField = isTimeFieldAvailable ? timeField : defaultTimeField;
}
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.
Awesome work! Just had a couple small suggestions about code clarity.
@cjcenizal thanks for the tips. I made your changes to improve readability.
@tylersmalley can you both do a quick check again? thx! |
Fair enough, LGTM. |
@@ -247,6 +254,18 @@ uiModules.get('apps/management') | |||
}, notify.fatal); | |||
} | |||
|
|||
function updateFieldListAndSetTimeField(results, seedField) { |
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.
seedField
seems a little deceptive, since we're always passing in a reference to a timeField
. So I think that naming it timeField
will make the code a little easier to follow.
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.
Nice, I just had a couple questions... sorry for being so nit picky!
LGTM if you just want to merge already. :) |
bb78b1e
to
d896802
Compare
d896802
to
411957c
Compare
--------- **Commit 1:** do not remove selection when clicking refreh fields * Original sha: afce3be * Authored by Thomas Neirynck <[email protected]> on 2016-09-16T17:51:06Z **Commit 2:** improve readability * Original sha: 411957c * Authored by Thomas Neirynck <[email protected]> on 2016-09-20T21:32:21Z
--------- **Commit 1:** do not remove selection when clicking refreh fields * Original sha: afce3be * Authored by Thomas Neirynck <[email protected]> on 2016-09-16T17:51:06Z **Commit 2:** improve readability * Original sha: 411957c * Authored by Thomas Neirynck <[email protected]> on 2016-09-20T21:32:21Z
[backport] PR #8312 to 5.x
[backport] PR #8312 to 5.0
--------- **Commit 1:** do not remove selection when clicking refreh fields * Original sha: f4e8dbaaeb0bcfda261523018f4ac560df988e00 [formerly afce3be] * Authored by Thomas Neirynck <[email protected]> on 2016-09-16T17:51:06Z **Commit 2:** improve readability * Original sha: 530a4f8e9945d9ce56b8507307c5c58c06b5fc35 [formerly 411957c] * Authored by Thomas Neirynck <[email protected]> on 2016-09-20T21:32:21Z Former-commit-id: a227bcc
[backport] PR elastic#8312 to 5.x Former-commit-id: 68d2bf0
for #8300.
Instead of clearing out the combobox, fill it in with default option.