Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into sessions/dele…
Browse files Browse the repository at this point in the history
…te-btn
  • Loading branch information
Liza K committed Feb 3, 2021
2 parents 61ef149 + bb802c0 commit e55c8b5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import { get } from 'lodash';
import { getIndexPatterns } from './plugin_services';
import { TimelionFunctionArgs } from '../../common/types';
import { indexPatterns as indexPatternsUtils } from '../../../data/public';
import {
IndexPatternField,
indexPatterns as indexPatternsUtils,
KBN_FIELD_TYPES,
} from '../../../data/public';

export interface Location {
min: number;
Expand All @@ -30,6 +34,8 @@ export interface FunctionArg {
};
}

const isRuntimeField = (field: IndexPatternField) => Boolean(field.runtimeField);

export function getArgValueSuggestions() {
const indexPatterns = getIndexPatterns();

Expand Down Expand Up @@ -85,18 +91,15 @@ export function getArgValueSuggestions() {

const valueSplit = partial.split(':');
return indexPattern.fields
.getAll()
.filter((field) => {
return (
.getByType(KBN_FIELD_TYPES.NUMBER)
.filter(
(field) =>
!isRuntimeField(field) &&
field.aggregatable &&
'number' === field.type &&
containsFieldName(valueSplit[1], field) &&
!indexPatternsUtils.isNestedField(field)
);
})
.map((field) => {
return { name: `${valueSplit[0]}:${field.name}`, help: field.type };
});
)
.map((field) => ({ name: `${valueSplit[0]}:${field.name}`, help: field.type }));
},
async split(partial: string, functionArgs: FunctionArg[]) {
const indexPattern = await getIndexPattern(functionArgs);
Expand All @@ -106,17 +109,21 @@ export function getArgValueSuggestions() {

return indexPattern.fields
.getAll()
.filter((field) => {
return (
.filter(
(field) =>
!isRuntimeField(field) &&
field.aggregatable &&
['number', 'boolean', 'date', 'ip', 'string'].includes(field.type) &&
[
KBN_FIELD_TYPES.NUMBER,
KBN_FIELD_TYPES.BOOLEAN,
KBN_FIELD_TYPES.DATE,
KBN_FIELD_TYPES.IP,
KBN_FIELD_TYPES.STRING,
].includes(field.type as KBN_FIELD_TYPES) &&
containsFieldName(partial, field) &&
!indexPatternsUtils.isNestedField(field)
);
})
.map((field) => {
return { name: field.name, help: field.type };
});
)
.map((field) => ({ name: field.name, help: field.type }));
},
async timefield(partial: string, functionArgs: FunctionArg[]) {
const indexPattern = await getIndexPattern(functionArgs);
Expand All @@ -125,17 +132,14 @@ export function getArgValueSuggestions() {
}

return indexPattern.fields
.getAll()
.filter((field) => {
return (
'date' === field.type &&
.getByType(KBN_FIELD_TYPES.DATE)
.filter(
(field) =>
!isRuntimeField(field) &&
containsFieldName(partial, field) &&
!indexPatternsUtils.isNestedField(field)
);
})
.map((field) => {
return { name: field.name };
});
)
.map((field) => ({ name: field.name }));
},
},
};
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/maps/public/render_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export async function renderApp({
...withNotifyOnErrors(getToasts()),
});

const stateTransfer = getEmbeddableService().getStateTransfer();

setAppChrome();

function renderMapApp(routeProps: RouteComponentProps<{ savedMapId?: string }>) {
const stateTransfer = getEmbeddableService()?.getStateTransfer();

const { embeddableId, originatingApp, valueInput } =
stateTransfer?.getIncomingEditorState() || {};
stateTransfer.getIncomingEditorState() || {};

let mapEmbeddableInput;
if (routeProps.match.params.savedMapId) {
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function renderApp({
const newPath = hash.substr(1);
return <Redirect to={newPath} />;
} else if (pathname === '/' || pathname === '') {
return <ListPage />;
return <ListPage stateTransfer={stateTransfer} />;
} else {
return <Redirect to="/" />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { Redirect } from 'react-router-dom';
import { getSavedObjectsClient, getToasts } from '../../kibana_services';
import { MapsListView } from './maps_list_view';
import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants';
import { EmbeddableStateTransfer } from '../../../../../../src/plugins/embeddable/public';

export class LoadListAndRender extends React.Component {
export class LoadListAndRender extends React.Component<{ stateTransfer: EmbeddableStateTransfer }> {
_isMounted: boolean = false;
state = {
mapsLoaded: false,
Expand All @@ -20,6 +21,7 @@ export class LoadListAndRender extends React.Component {

componentDidMount() {
this._isMounted = true;
this.props.stateTransfer.clearEditorState();
this._loadMapsList();
}

Expand Down
13 changes: 13 additions & 0 deletions x-pack/test/functional/apps/maps/embeddable/save_and_return.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ export default function ({ getPageObjects, getService }) {
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.equal(2);
});

it('should lose its connection to the dashboard when creating new map', async () => {
await PageObjects.maps.gotoMapListingPage();
await PageObjects.maps.openNewMap();
await PageObjects.maps.expectMissingSaveAndReturnButton();

// return to origin should not be present in save modal
await testSubjects.click('mapSaveButton');
const redirectToOriginCheckboxExists = await testSubjects.exists(
'returnToOriginModeSwitch'
);
expect(redirectToOriginCheckboxExists).to.be(false);
});
});

describe('save as', () => {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/page_objects/gis_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export function GisPageProvider({ getService, getPageObjects }: FtrProviderConte
await testSubjects.click('mapSaveAndReturnButton');
}

async expectMissingSaveAndReturnButton() {
await testSubjects.missingOrFail('mapSaveAndReturnButton');
}

async expectMissingSaveButton() {
await testSubjects.missingOrFail('mapSaveButton');
}
Expand Down

0 comments on commit e55c8b5

Please sign in to comment.