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

Move filter bar into data plugin #35460

Closed

Conversation

lizozom
Copy link
Contributor

@lizozom lizozom commented Apr 23, 2019

Summary

  • Deangularized parts of query_filter and push_filters
  • Moved query_filter and push_filters to reside in filter_manager (filter_bar is now the UI component)
  • Moved filter bar to data plugin.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Stylesheet moves lgtm

@elasticmachine
Copy link
Contributor

💔 Build Failed

Liza Katz added 3 commits April 24, 2019 15:40
… to removal of Promise class from code).

Now digest is being called once when mapAndFlatten is called.
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@Bargs Bargs left a comment

Choose a reason for hiding this comment

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

There still seems to be a digest issue. For example adding a new filter via the filter bar doesn’t take effect in Discover until some other action triggers a digest cycle (like mouse hovering over the date histogram).

Also left a few minor comments inline. Other than that things look pretty good!

const queryFilter = Private(FilterBarQueryFilterProvider);

const pushFilters = (filters, simulate) => {
const appState = getAppState();
if (filters.length && !simulate) {
const flatFilters = _.flatten(filters);
const deduplicatedFilters = flatFilters.filter((v, i) => i === flatFilters.findIndex(f => _.isEqual(v, f)));
filterBarPushFilters(appState)(deduplicatedFilters);
Promise.resolve(pushFilterBarFilters(appState, deduplicatedFilters));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this returning a promise now? The only usage of it I see doesn't seem to handle the promise.

if (!filterState.filters) {
filterState.filters = [];
}
return Promise.resolve(mapAndFlattenFilters(indexPatterns, filters)).then((mappedFilters) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need wrapped in Promise.resolve since mapAndFlattenFilters returns a Promise?

Copy link
Member

@lukeelmers lukeelmers 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 a big one, but looking solid so far! Did an initial read through the code (haven't tested yet), and added a few notes for discussion.

It might make this a little easier to review if it were separated out into 2 smaller PRs (deangularize, then move). But based on the commit history that may be a non-trivial change at this point, so I reviewed anyway.

Also, since we actually relocate the filter bar here, would you mind updating the dev docs entry accordingly?

this.applyFilters.loadLegacyDirectives();
this.filterBar.loadLegacyDirectives();
},
...this.applyFilters.setup(),
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary for apply filters to be its own service? It doesn't feel like it has much going on to justify existing as an independent service.

To me it would feel more natural to have a filter service that includes both filter bar and apply filters... along with any other filter-related utilities we may add in the future.

// nothing to do here yet
}

public loadLegacyDirectives() {
Copy link
Member

Choose a reason for hiding this comment

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

In the new platform, any items that are part of a plugin's public contract should be returned by that plugin's setup method. I propose we follow the same convention in our services for consistency.

In this case, that would mean making loadLegacyDirectives private, and returning it from the public setup method. Or even better, just add it to the setup method directly:

public setup() {
  return {
    ApplyFiltersPopover,
    loadLegacyDirectives: once(setupDirective),
  };
}

This also ensures that ReturnType<ApplyFiltersService['setup']> captures the entire contract of this service

export class ApplyFiltersService {
private setupDirectives: any;
public setup() {
this.setupDirectives = _.once(setupDirective);
Copy link
Member

Choose a reason for hiding this comment

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

looks like lodash isn't imported in this file... should probably also prefer import { once } from 'lodash'; instead of _

import { setupDirective } from './directive';

/**
* Search Bar Service
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Search Bar Service
* Apply Filters Service

(if this really needs to be a separate service -- see my other note on that)

// nothing to do here yet
}

public loadLegacyDirectives() {
Copy link
Member

Choose a reason for hiding this comment

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

Same note here on the convention of returning the public contract from the setup method

});
};
/**
* Search Bar Service
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Search Bar Service
* Filter Bar Service

(if this needs to be it's own service)

@@ -30,7 +30,7 @@ import { createLegacyClass } from './utils/legacy_class';

const location = 'EventEmitter';

export function EventsProvider(Private, Promise) {
Copy link
Member

Choose a reason for hiding this comment

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

woo hoo 🎊

$rootScope.$digest();

it('should add filters to appState', async function () {
await queryFilter.addFilters(filters);
Copy link
Member

Choose a reason for hiding this comment

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

thank you for sorting out these test updates. i have a feeling we will have a lot of these to do over time, so appreciate you blazing the trail here.

@lukeelmers lukeelmers added the release_note:skip Skip the PR/issue when compiling release notes label Apr 26, 2019
@lizozom lizozom closed this May 23, 2019
@stacey-gammon stacey-gammon mentioned this pull request Jun 30, 2019
94 tasks
@lizozom lizozom deleted the newplatform/data-plugin/filter-bar branch November 14, 2019 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes v7.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants