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

React/EUI-ify indexed fields table #16695

Merged
merged 16 commits into from
Mar 9, 2018

Conversation

jen-huang
Copy link
Contributor

Fixes #16694
Relates to #15721

Converts the indexed fields table to React/EUI.

screen shot 2018-02-12 at 10 19 05 pm

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

Awesome! This looks great! The code pattern is probably the best I've ever seen ;)

I did find a few things:

Tooltip positioning

I'm not sure if this is fixable outside of EUI but this is definitely misaligned.

screen shot 2018-02-13 at 11 42 23 am

Yes indicators

I'm not sure I love this choice of icon to indicate yes. Did this come down from design?

screen shot 2018-02-13 at 11 43 36 am

Refresh fields

This doesn't seem to work for me. If I click the button, the fields are fetched, but the table isn't updated. You probably just need to re render the table once this happens in the angular code

@jen-huang
Copy link
Contributor Author

jen-huang commented Feb 14, 2018

@chrisronline Thanks for the review!

  1. Issue created for EUI: Fix Tooltip positioning eui#401

  2. Yes, design is here. I left out the grey circle indicators for no after speaking to @snide about legibility.

  3. Can you give me an example of when the contents of this table would change after refreshing the fields? I have a potential fix that triggers re-rendering, but having a hard time finding a use case where the info is updated, to verify my fix.

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.

Looks great overall! Just had a couple of minor suggestions.

I have to say that I am not really feeling the dots in the table. 😐 My brain just doesn't pick up their meaning as quickly as with checkmarks. I also find myself feeling a bit unsure about what I can do with the table when the actions are hidden until you hover. I didn't realize I could edit the rows until I accidentally stumbled upon that functionality.

} else if($state.tab === 'scriptedFields') {
updateScriptedFieldsTable($scope, $state);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor suggestion: how about early exiting here to avoid nesting, and a slightly terser switch instead of else if?

if ($scope.fieldFilter === undefined) {
  return;
}

switch ($state.tab) {
  case 'indexedFields':
    updateIndexedFieldsTable($scope, $state);
  case 'scriptedFields':
    updateScriptedFieldsTable($scope, $state);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated 👍

}


// import React, { Component } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we delete this commented out code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow how did that get in there... 🙈

@jen-huang
Copy link
Contributor Author

@cjcenizal Thanks for reviewing! Might the hidden actions be something that can be added to TableOfRecords? Some property like show: true; so that user doesn't have to hover to see the actions column?

@snide Any thoughts on CJ's comments above about dots vs checkmarks?

@elasticmachine
Copy link
Contributor

💔 Build Failed

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.

💰LGTM!

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elastic elastic deleted a comment from elasticmachine Feb 17, 2018
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@chrisronline
Copy link
Contributor

@jen-huang I don't think it's a requirement, but feel free to check out the new table implementation in EUI and how @cjcenizal updated the scripted fields table to use it #16901. It might be cool to start using that in this PR

@jen-huang jen-huang force-pushed the eui/indexed-fields-table branch from c3d462c to 8caf7e2 Compare March 6, 2018 21:43
@elasticmachine
Copy link
Contributor

💔 Build Failed

@jen-huang jen-huang force-pushed the eui/indexed-fields-table branch from 8caf7e2 to 979acef Compare March 7, 2018 17:57
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@jen-huang
Copy link
Contributor Author

@chrisronline PR ready for another pass with EuiTableInMemory. Pulled in reselect as well to match #16649.

import { ScriptedFieldsTable } from './scripted_fields_table';

const REACT_INDEXED_FIELDS_DOM_ELEMENT_ID = 'reactIndexedFieldsTable';
Copy link
Contributor

@chrisronline chrisronline Mar 8, 2018

Choose a reason for hiding this comment

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

I'm still seeing an issue where the fields aren't refreshing once I click Refresh Fields. I think it's because this change is never propagating to the React component.

I'm wondering if we just let this parent container control the fields and pass it in so we can easily tie a change in the fields to the React lifecycle. Or maybe find another way.

But if you like the first idea, here is a some code I whipped up that might work:

diff --git a/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/edit_index_pattern.js b/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/edit_index_pattern.js
index f1187c3fed..02ab1c6540 100644
--- a/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/edit_index_pattern.js
+++ b/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/edit_index_pattern.js
@@ -67,6 +67,7 @@ function updateIndexedFieldsTable($scope, $state) {
       render(
         <IndexedFieldsTable
           indexPattern={$scope.indexPattern}
+          fields={$scope.fields}
           fieldFilter={$scope.fieldFilter}
           fieldWildcardMatcher={$scope.fieldWildcardMatcher}
           indexedFieldTypeFilter={$scope.indexedFieldTypeFilter}
@@ -138,6 +139,7 @@ uiModules.get('apps/management')
     $scope.$watch('indexPattern.fields', function () {
       $scope.editSections = $scope.editSectionsProvider($scope.indexPattern);
       $scope.refreshFilters();
+      $scope.fields = $scope.indexPattern.getNonScriptedFields();
       updateIndexedFieldsTable($scope, $state);
       updateScriptedFieldsTable($scope, $state);
     });
@@ -180,7 +182,11 @@ uiModules.get('apps/management')
     $scope.refreshFields = function () {
       const confirmModalOptions = {
         confirmButtonText: 'Refresh',
-        onConfirm: () => { $scope.indexPattern.refreshFields(); },
+        onConfirm: async () => {
+          await $scope.indexPattern.refreshFields();
+          $scope.fields = $scope.indexPattern.getNonScriptedFields();
+          updateIndexedFieldsTable($scope, $state);
+        },
         title: 'Refresh field list?'
       };
       confirmModal(
diff --git a/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/indexed_fields_table/indexed_fields_table.js b/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/indexed_fields_table/indexed_fields_table.js
index 995f4bbb37..acea91db5d 100644
--- a/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/indexed_fields_table/indexed_fields_table.js
+++ b/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/indexed_fields_table/indexed_fields_table.js
@@ -10,6 +10,7 @@ import {
 export class IndexedFieldsTable extends Component {
   static propTypes = {
     indexPattern: PropTypes.object.isRequired,
+    fields: PropTypes.array.isRequired,
     fieldFilter: PropTypes.string,
     indexedFieldTypeFilter: PropTypes.string,
     helpers: PropTypes.shape({
@@ -22,12 +23,14 @@ export class IndexedFieldsTable extends Component {
     super(props);
 
     this.state = {
-      fields: []
+      fields: this.mapFields(this.props.fields),
     };
   }
 
-  componentWillMount() {
-    this.fetchFields();
+  componentWillReceiveProps(nextProps) {
+    if (nextProps.fields !== this.props.fields) {
+      this.setState({ fields: this.mapFields(nextProps.fields) });
+    }
   }
 
   mapFields(fields) {
@@ -47,13 +50,6 @@ export class IndexedFieldsTable extends Component {
       });
   }
 
-  fetchFields = async () => {
-    const fields = this.mapFields(await this.props.indexPattern.getNonScriptedFields());
-    this.setState({
-      fields
-    });
-  }
-
   getFilteredFields = createSelector(
     (state) => state.fields,
     (state, props) => props.fieldFilter,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, implemented similar changes

Copy link
Contributor

@bmcconaghy bmcconaghy left a comment

Choose a reason for hiding this comment

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

a couple of minor things, but looking good.


mapFields(fields) {
const { indexPattern, fieldWildcardMatcher } = this.props;
const fieldWildcardMatch = fieldWildcardMatcher((indexPattern.sourceFilters && indexPattern.sourceFilters.map(f => f.value) || []));
Copy link
Contributor

Choose a reason for hiding this comment

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

this line is really long

Copy link
Contributor Author

Choose a reason for hiding this comment

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

broke it up

...field,
displayName: field.displayName,
routes: field.routes,
indexPattern: field.indexPattern,
Copy link
Contributor

Choose a reason for hiding this comment

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

lines 41-43 are covered by line 40.

Copy link
Contributor Author

@jen-huang jen-huang Mar 8, 2018

Choose a reason for hiding this comment

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

displayName, routes, and indexPattern aren't enumerable properties :(

Object.keys(field)
(7) ["name", "type", "count", "scripted", "searchable", "aggregatable", "readFromDocValues"]

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh, nm then :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave a comment here explaining that? I'm pretty sure I would come along and make the same assumption Bill did. :)

@jen-huang
Copy link
Contributor Author

@chrisronline Ready for another pass, refresh fields should work now.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded


// Allow the componentWillMount code to execute
// https://github.com/airbnb/enzyme/issues/450
await component.update(); // Fire `componentWillMount()`
Copy link
Contributor

Choose a reason for hiding this comment

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

We can simplify all of this from #16968

// Ensure all promises resolve
await new Promise(resolve => process.nextTick(resolve));
// Ensure the state changes are reflected
component.update();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so much better!!

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

This is looking GREAT! I just have one minor request for the tests that should hopefully make them more clear.

@jen-huang
Copy link
Contributor Author

@chrisronline Updated!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

LGTM!!!

@jen-huang jen-huang merged commit e755514 into elastic:master Mar 9, 2018
jen-huang added a commit to jen-huang/kibana that referenced this pull request Mar 9, 2018
* React/EUI-ifying indexed fields table
jen-huang added a commit that referenced this pull request Mar 9, 2018
* React/EUI-ifying indexed fields table
@jen-huang jen-huang deleted the eui/indexed-fields-table branch June 5, 2019 19:47
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.

5 participants