-
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
Move filter bar into data plugin #35460
Move filter bar into data plugin #35460
Conversation
…plugin/filter-bar
…er-bar remains the UI component + directive
…plugin/filter-bar
Pinging @elastic/kibana-app-arch |
💔 Build Failed |
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.
Stylesheet moves lgtm
💔 Build Failed |
… to removal of Promise class from code). Now digest is being called once when mapAndFlatten is called.
💔 Build Failed |
💔 Build Failed |
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.
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)); |
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.
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) => { |
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.
Does this need wrapped in Promise.resolve since mapAndFlattenFilters returns a Promise?
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.
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?
src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts
Show resolved
Hide resolved
this.applyFilters.loadLegacyDirectives(); | ||
this.filterBar.loadLegacyDirectives(); | ||
}, | ||
...this.applyFilters.setup(), |
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.
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() { |
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.
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); |
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.
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 |
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.
* 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() { |
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.
Same note here on the convention of returning the public contract from the setup
method
}); | ||
}; | ||
/** | ||
* Search Bar Service |
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.
* 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) { |
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.
woo hoo 🎊
$rootScope.$digest(); | ||
|
||
it('should add filters to appState', async function () { | ||
await queryFilter.addFilters(filters); |
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.
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.
Summary
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.- [ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)- [ ] Documentation was added for features that require explanation or tutorials- [ ] This was checked for keyboard-only and screenreader accessibility