Keep timeframe when editing a map from a dashboard (#135374)

* Keep timeframe when editing a map from a dashboard

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2022-06-29 10:06:21 -06:00 committed by GitHub
parent a34db6986b
commit a48c7d9f0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View file

@ -262,6 +262,7 @@ export class MapApp extends React.Component<Props, State> {
filters: [..._.get(globalState, 'filters', []), ...appFilters, ...savedObjectFilters],
query,
time: getInitialTimeFilters({
hasSaveAndReturnConfig: this.props.savedMap.hasSaveAndReturnConfig(),
serializedMapState,
globalState,
}),

View file

@ -10,13 +10,15 @@ import { getUiSettings } from '../../../kibana_services';
import { SerializedMapState } from './types';
export function getInitialTimeFilters({
hasSaveAndReturnConfig,
serializedMapState,
globalState,
}: {
hasSaveAndReturnConfig: boolean;
serializedMapState?: SerializedMapState;
globalState: GlobalQueryStateFromUrl;
}) {
if (serializedMapState?.timeFilters) {
if (!hasSaveAndReturnConfig && serializedMapState?.timeFilters) {
return serializedMapState.timeFilters;
}

View file

@ -8,7 +8,14 @@
import expect from '@kbn/expect';
export default function ({ getPageObjects, getService }) {
const PageObjects = getPageObjects(['common', 'dashboard', 'header', 'maps', 'visualize']);
const PageObjects = getPageObjects([
'common',
'dashboard',
'header',
'maps',
'timePicker',
'visualize',
]);
const dashboardAddPanel = getService('dashboardAddPanel');
const dashboardPanelActions = getService('dashboardPanelActions');
const testSubjects = getService('testSubjects');
@ -75,6 +82,14 @@ export default function ({ getPageObjects, getService }) {
});
describe('save and return', () => {
it('should use dashboard instead of time stored in map state', async () => {
// join example map's time is "last 17 minutes"
// ensure map has dashboard time
const timeConfig = await PageObjects.timePicker.getTimeConfig();
expect(timeConfig.start).to.equal('Sep 20, 2015 @ 00:00:00.000');
expect(timeConfig.end).to.equal('Sep 20, 2015 @ 01:00:00.000');
});
it('should return to dashboard', async () => {
await PageObjects.maps.clickSaveAndReturnButton();
await PageObjects.dashboard.waitForRenderComplete();