Skip to content

Commit

Permalink
Fix #55603
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Jan 31, 2020
1 parent 0d14da6 commit e75c6fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 13 additions & 2 deletions x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ function createMockFilterManager() {
}),
setFilters: jest.fn((newFilters: unknown[]) => {
filters = newFilters;
subscriber();
if (subscriber) subscriber();
}),
setAppFilters: jest.fn((newFilters: unknown[]) => {
filters = newFilters;
if (subscriber) subscriber();
}),
getFilters: () => filters,
getGlobalFilters: () => {
Expand Down Expand Up @@ -189,6 +193,13 @@ describe('Lens App', () => {
`);
});

it('clears app filters on load', () => {
const defaultArgs = makeDefaultArgs();
mount(<App {...defaultArgs} />);

expect(defaultArgs.data.query.filterManager.setAppFilters).toHaveBeenCalledWith([]);
});

it('sets breadcrumbs when the document title changes', async () => {
const defaultArgs = makeDefaultArgs();
const instance = mount(<App {...defaultArgs} />);
Expand Down Expand Up @@ -246,7 +257,7 @@ describe('Lens App', () => {

expect(args.docStorage.load).toHaveBeenCalledWith('1234');
expect(args.data.indexPatterns.get).toHaveBeenCalledWith('1');
expect(args.data.query.filterManager.setFilters).toHaveBeenCalledWith([
expect(args.data.query.filterManager.setAppFilters).toHaveBeenCalledWith([
{ query: { match_phrase: { src: 'test' } } },
]);
expect(TopNavMenu).toHaveBeenCalledWith(
Expand Down
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export function App({
const { lastKnownDoc } = state;

useEffect(() => {
// Clear app-specific filters when navigating to Lens. Necessary because Lens
// can be loaded without a full page refresh
data.query.filterManager.setAppFilters([]);

const filterSubscription = data.query.filterManager.getUpdates$().subscribe({
next: () => {
setState(s => ({ ...s, filters: data.query.filterManager.getFilters() }));
Expand Down Expand Up @@ -123,7 +127,8 @@ export function App({
core.notifications
)
.then(indexPatterns => {
data.query.filterManager.setFilters(doc.state.filters);
// Don't overwrite any pinned filters
data.query.filterManager.setAppFilters(doc.state.filters);
setState(s => ({
...s,
isLoading: false,
Expand Down

0 comments on commit e75c6fd

Please sign in to comment.