Kibana version: 7.7.0 BC5 (latest snapshot from apr 13th)
Elasticsearch version: 7.7.0 BC5 (latest snapshot from apr 13th)
Server OS version: darwin_x86_64
Browser version: chrome latest
Browser OS version: os x
Original install method (e.g. download page, yum, from source, etc.): from staging
Describe the bug: If user adds a filter or deletes a filter - on an index pattern - even after saving - Kibana doesn't let her generate csv report in discover. Instead it keeps displaying the message - please save your work.
Please note - if you switch the index pattern and then open the saved search on the previous index pattern with/without filter on which you were trying to generate report - then Kibana lets you generate the CSV report without any issues.
Steps to reproduce:
Screenshots (if relevant):

Errors in browser console (if relevant):
While saving the discover state with .keyword filter:
kbn-ui-shared-deps.js:334 TypeError: Cannot read property 'change' of undefined
at 22.bundle.js:3
at c.$digest (kbn-ui-shared-deps.js:334)
at kbn-ui-shared-deps.js:334
at Yr.completeTask (kbn-ui-shared-deps.js:334)
at kbn-ui-shared-deps.js:334
(anonymous) @ kbn-ui-shared-deps.js:334
(anonymous) @ kbn-ui-shared-deps.js:334
$digest @ kbn-ui-shared-deps.js:334
(anonymous) @ kbn-ui-shared-deps.js:334
Yr.completeTask @ kbn-ui-shared-deps.js:334
(anonymous) @ kbn-ui-shared-deps.js:334
setTimeout (async)
o.defer @ kbn-ui-shared-deps.js:334
$evalAsync @ kbn-ui-shared-deps.js:334
_callee10$ @ 22.bundle.js:3
l @ kbn-ui-shared-deps.js:288
(anonymous) @ kbn-ui-shared-deps.js:288
forEach.e.<computed> @ kbn-ui-shared-deps.js:288
asyncGeneratorStep @ 22.bundle.js:3
_next @ 22.bundle.js:3
Promise.then (async)
asyncGeneratorStep @ 22.bundle.js:3
_next @ 22.bundle.js:3
Promise.then (async)
asyncGeneratorStep @ 22.bundle.js:3
_next @ 22.bundle.js:3
(anonymous) @ 22.bundle.js:3
(anonymous) @ 22.bundle.js:3
_saveDataSource @ 22.bundle.js:3
saveDataSource @ 22.bundle.js:3
onSave @ 22.bundle.js:3
_callee$ @ commons.bundle.js:3
l @ kbn-ui-shared-deps.js:288
(anonymous) @ kbn-ui-shared-deps.js:288
forEach.e.<computed> @ kbn-ui-shared-deps.js:288
asyncGeneratorStep @ commons.bundle.js:3
_next @ commons.bundle.js:3
(anonymous) @ commons.bundle.js:3
(anonymous) @ commons.bundle.js:3
onSaveConfirmed @ commons.bundle.js:3
_callee$ @ commons.bundle.js:3
l @ kbn-ui-shared-deps.js:288
(anonymous) @ kbn-ui-shared-deps.js:288
forEach.e.<computed> @ kbn-ui-shared-deps.js:288
asyncGeneratorStep @ commons.bundle.js:3
_next @ commons.bundle.js:3
(anonymous) @ commons.bundle.js:3
(anonymous) @ commons.bundle.js:3
(anonymous) @ commons.bundle.js:3
m @ kbn-ui-shared-deps.js:342
w @ kbn-ui-shared-deps.js:342
(anonymous) @ kbn-ui-shared-deps.js:342
x @ kbn-ui-shared-deps.js:342
L @ kbn-ui-shared-deps.js:342
T @ kbn-ui-shared-deps.js:342
O @ kbn-ui-shared-deps.js:342
Cn @ kbn-ui-shared-deps.js:342
ce @ kbn-ui-shared-deps.js:342
Ln @ kbn-ui-shared-deps.js:342
Dn @ kbn-ui-shared-deps.js:342
On @ kbn-ui-shared-deps.js:342
t.unstable_runWithPriority @ kbn-ui-shared-deps.js:350
Hi @ kbn-ui-shared-deps.js:342
se @ kbn-ui-shared-deps.js:342
Tn @ kbn-ui-shared-deps.js:342
Show 27 more frames
Pinging @elastic/kibana-app (Team:KibanaApp)
Please note this is a regression from 7.6.2
Seems like the problem is that https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js#L60 is always undefined. https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js#L772 should actually be chrome.docTitle.
I'm not sure how exactly this broke after 7.6.2 - will prepare a fix though.
There is a workaround - the saving works, but after this an error is preventing discover to inform the share popover. If you open the saved search via the flyout again, it takes another path through the code and the button becomes clickable.
OK, I investigated this further and it seems like there is another underlying problem as well.
The check whether the current state is dirty is comparing to the initialState: https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover_state.ts#L175
Even if you saved your search, it would still recognize this as dirty and there is no mechanism to update this initalState variable as far as I can tell.
@kertal I think you worked on the state management here recently, could you have a look please?
@flash1293 thx, taking over