Skip to content

Commit

Permalink
Merge branch 'master' into uptime_remove-monitor-states-graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Apr 15, 2020
2 parents 7f92c66 + ac549ac commit 71b018e
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,9 @@ function discoverController(
if (newSavedQueryId) {
setAppState({ savedQuery: newSavedQueryId });
} else {
//reset filters and query string, remove savedQuery from state
// remove savedQueryId from state
const state = {
...appStateContainer.getState(),
query: getDefaultQuery(
localStorage.get('kibana.userQueryLanguage') || config.get('search:queryLanguage')
),
filters: [],
};
delete state.savedQuery;
appStateContainer.set(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function QueryLanguageSwitcher(props: Props) {
size="xs"
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
className="euiFormControlLayout__append"
data-test-subj={'switchQueryLanguageButton'}
>
{props.language === 'lucene' ? luceneLabel : kqlLabel}
</EuiButtonEmpty>
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/data/public/ui/search_bar/create_search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
const onQuerySubmitRef = useRef(props.onQuerySubmit);
const defaultQuery = {
query: '',
language: core.uiSettings.get('search:queryLanguage'),
language:
storage.get('kibana.userQueryLanguage') || core.uiSettings.get('search:queryLanguage'),
};
const [query, setQuery] = useState<Query>(props.query || defaultQuery);

Expand Down Expand Up @@ -161,7 +162,7 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
setQuery,
savedQueryId: props.savedQueryId,
notifications: core.notifications,
uiSettings: core.uiSettings,
defaultLanguage: defaultQuery.language,
});

// Fire onQuerySubmit on query or timerange change
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/public/ui/search_bar/lib/use_saved_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ interface UseSavedQueriesProps {
queryService: DataPublicPluginStart['query'];
setQuery: Function;
notifications: CoreStart['notifications'];
uiSettings: CoreStart['uiSettings'];
savedQueryId?: string;
defaultLanguage: string;
}

interface UseSavedQueriesReturn {
Expand All @@ -41,7 +41,7 @@ interface UseSavedQueriesReturn {

export const useSavedQuery = (props: UseSavedQueriesProps): UseSavedQueriesReturn => {
// Handle saved queries
const defaultLanguage = props.uiSettings.get('search:queryLanguage');
const defaultLanguage = props.defaultLanguage;
const [savedQuery, setSavedQuery] = useState<SavedQuery | undefined>();

// Effect is used to convert a saved query id into an object
Expand Down
36 changes: 11 additions & 25 deletions src/plugins/embeddable/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
# The Embeddable API V2
# Embeddables

The Embeddable API's main goal is to have documented and standardized ways to share and exchange information and functionality across applications and plugins.
Embeddables are re-usable widgets that can be rendered in any environment or plugin. Developers can embed them directly in their plugin. End users can dynamically add them to any embeddable _containers_.

There are three main pieces of this infrastructure:
- Embeddables & Containers
- Actions
- Triggers
## Embeddable containers

## Embeddables & Containers
Containers are a special type of embeddable that can contain nested embeddables. Embeddables can be dynamically added to embeddable _containers_. Currently only dashboard uses this interface.

Embeddables are isolated, serializable, renderable widgets. A developer can hard code an embeddable inside their
application, or they can use some built in actions to allow users to dynamically add them to *containers*.

Containers are a special type of embeddable that can contain nested embeddables.

## Actions

Actions are pluggable pieces of functionality exposed to the user that take an embeddable as context, plus an optional action context.

## Triggers

Triggers are the way actions are connected to a user action. We ship with two default triggers, `CONTEXT_MENU_TRIGGER` and `APPLY_FILTER`.

Actions attached to the `CONTEXT_MENU_TRIGGER` will be displayed in supported embeddables context menu to the user. Actions attached to the `APPLY_FILTER` trigger will show up when any embeddable emits this trigger.
## Examples

A developer can register new triggers that their embeddables, or external components, can emit (as long as they have an embeddable to pass along as context).
Many example embeddables are implemented and registered [here](https://github.com/elastic/kibana/tree/master/examples/embeddable_examples). They can be played around with and explored [in the Embeddable Explorer example plugin](https://github.com/elastic/kibana/tree/master/examples/embeddable_explorer). Just run kibana with

## Examples
```
yarn start --run-examples
```

Many examples can be viewed in the functionally tested `kbn_tp_embeddable_explorer` plugin, as well as the jest tested classes inside the `embeddable_api/public/test_samples` folder.
and navigate to the Embeddable explorer app.

## Testing

Run unit tests

```shell
node scripts/jest embeddable_api
node scripts/jest embeddable
```
19 changes: 19 additions & 0 deletions test/functional/apps/discover/_saved_queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ export default function({ getService, getPageObjects }) {
await savedQueryManagementComponent.clearCurrentlyLoadedQuery();
expect(await queryBar.getQueryString()).to.eql('');
});

// https://github.com/elastic/kibana/issues/63505
it('allows clearing if non default language was remembered in localstorage', async () => {
await queryBar.switchQueryLanguage('lucene');
await PageObjects.common.navigateToApp('discover'); // makes sure discovered is reloaded without any state in url
await queryBar.expectQueryLanguageOrFail('lucene'); // make sure lucene is remembered after refresh (comes from localstorage)
await savedQueryManagementComponent.loadSavedQuery('OkResponse');
await queryBar.expectQueryLanguageOrFail('kql');
await savedQueryManagementComponent.clearCurrentlyLoadedQuery();
await queryBar.expectQueryLanguageOrFail('lucene');
});

// fails: bug in discover https://github.com/elastic/kibana/issues/63561
// unskip this test when bug is fixed
it.skip('changing language removes saved query', async () => {
await savedQueryManagementComponent.loadSavedQuery('OkResponse');
await queryBar.switchQueryLanguage('lucene');
expect(await queryBar.getQueryString()).to.eql('');
});
});
});
}
20 changes: 20 additions & 0 deletions test/functional/services/query_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../ftr_provider_context';

export function QueryBarProvider({ getService, getPageObjects }: FtrProviderContext) {
Expand All @@ -25,6 +26,7 @@ export function QueryBarProvider({ getService, getPageObjects }: FtrProviderCont
const log = getService('log');
const PageObjects = getPageObjects(['header', 'common']);
const find = getService('find');
const browser = getService('browser');

class QueryBar {
async getQueryString(): Promise<string> {
Expand Down Expand Up @@ -62,6 +64,24 @@ export function QueryBarProvider({ getService, getPageObjects }: FtrProviderCont
public async clickQuerySubmitButton(): Promise<void> {
await testSubjects.click('querySubmitButton');
}

public async switchQueryLanguage(lang: 'kql' | 'lucene'): Promise<void> {
await testSubjects.click('switchQueryLanguageButton');
const kqlToggle = await testSubjects.find('languageToggle');
const currentLang =
(await kqlToggle.getAttribute('aria-checked')) === 'true' ? 'kql' : 'lucene';
if (lang !== currentLang) {
await kqlToggle.click();
}

await browser.pressKeys(browser.keys.ESCAPE); // close popover
await this.expectQueryLanguageOrFail(lang); // make sure lang is switched
}

public async expectQueryLanguageOrFail(lang: 'kql' | 'lucene'): Promise<void> {
const queryLanguageButton = await testSubjects.find('switchQueryLanguageButton');
expect((await queryLanguageButton.getVisibleText()).toLowerCase()).to.eql(lang);
}
}

return new QueryBar();
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EditorFrameInstance } from '../types';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { Document, SavedObjectStore } from '../persistence';
import { mount } from 'enzyme';
import { SavedObjectSaveModal } from '../../../../../src/plugins/saved_objects/public';
import {
esFilters,
FilterManager,
Expand Down Expand Up @@ -650,6 +651,27 @@ describe('Lens App', () => {
},
});
});

it('does not show the copy button on first save', async () => {
const args = defaultArgs;
args.editorFrame = frame;

instance = mount(<App {...args} />);

const onChange = frame.mount.mock.calls[0][1].onChange;
await act(async () =>
onChange({
filterableIndexPatterns: [],
doc: ({ expression: 'valid expression' } as unknown) as Document,
})
);
instance.update();

await act(async () => getButton(instance).run(instance.getDOMNode()));
instance.update();

expect(instance.find(SavedObjectSaveModal).prop('showCopyOnSave')).toEqual(false);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export function App({
}}
onClose={() => setState(s => ({ ...s, isSaveModalVisible: false }))}
title={lastKnownDoc.title || ''}
showCopyOnSave={!addToDashboardMode}
showCopyOnSave={!!lastKnownDoc.id && !addToDashboardMode}
objectType={i18n.translate('xpack.lens.app.saveModalType', {
defaultMessage: 'Lens visualization',
})}
Expand Down

0 comments on commit 71b018e

Please sign in to comment.