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

Do not remove selection when clicking refresh fields #8312

Merged
merged 2 commits into from
Sep 20, 2016

Conversation

thomasneirynck
Copy link
Contributor

@thomasneirynck thomasneirynck commented Sep 16, 2016

for #8300.

Instead of clearing out the combobox, fill it in with default option.

@thomasneirynck thomasneirynck changed the title do not remove selection when clicking refreh fields do not remove selection when clicking refresh fields Sep 16, 2016
@epixa epixa added v5.0.0 and removed v5.0.0-beta1 labels Sep 20, 2016
Copy link
Contributor

@tylersmalley tylersmalley left a 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];
    }
  }

@thomasneirynck
Copy link
Contributor Author

@tylersmalley

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.

@cjcenizal cjcenizal self-assigned this Sep 20, 2016
const matchingField = results.dateFields.find(field => field.name === seedField.name);
index.timeField = matchingField ? matchingField : results.dateFields[0];

}
Copy link
Contributor

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.

Copy link
Contributor

@cjcenizal cjcenizal Sep 20, 2016

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;
  }

Copy link
Contributor

@cjcenizal cjcenizal left a 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.

@thomasneirynck
Copy link
Contributor Author

@cjcenizal thanks for the tips. I made your changes to improve readability.

  • I did keep the two named functions, I'm not a fan of function overloading (it doesn't improve clarity imho, and it's bad habit, especially in JS where a compiler can't deduplicate the function). I also think we don't need that code path, when we are changing indices.
  • Also, the angular creates new timefield instances each refresh, so I don't want to carry the old one in the new state. hence the small deviation from your suggestion at the end.

@tylersmalley can you both do a quick check again? thx!

@tylersmalley
Copy link
Contributor

Fair enough, LGTM.

@@ -247,6 +254,18 @@ uiModules.get('apps/management')
}, notify.fatal);
}

function updateFieldListAndSetTimeField(results, seedField) {
Copy link
Contributor

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.

Copy link
Contributor

@cjcenizal cjcenizal left a 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!

@cjcenizal
Copy link
Contributor

LGTM if you just want to merge already. :)

@thomasneirynck thomasneirynck merged commit 058ddd6 into elastic:master Sep 20, 2016
elastic-jasper added a commit that referenced this pull request Sep 20, 2016
---------

**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
elastic-jasper added a commit that referenced this pull request Sep 20, 2016
---------

**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
thomasneirynck added a commit that referenced this pull request Sep 21, 2016
thomasneirynck added a commit that referenced this pull request Sep 21, 2016
thomasneirynck added a commit to thomasneirynck/kibana that referenced this pull request Sep 21, 2016
@epixa epixa added v5.0.0 and removed v5.0.0 labels Oct 7, 2016
@epixa epixa changed the title do not remove selection when clicking refresh fields Do not remove selection when clicking refresh fields Oct 9, 2016
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
---------

**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
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants