Skip to content

Commit

Permalink
Merge branch 'master' into move-kbn-ui-shared-deps-into-bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jun 14, 2021
2 parents f0063e3 + b60a438 commit e5356f2
Show file tree
Hide file tree
Showing 44 changed files with 728 additions and 837 deletions.
103 changes: 50 additions & 53 deletions api_docs/deprecations.mdx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ describe('interpreter/functions#filtersToAst', () => {
expect(actual[0].functions[0]).toHaveProperty('name', 'kibanaFilter');
expect(actual[0].functions[0].arguments).toMatchInlineSnapshot(`
Object {
"disabled": Array [
false,
],
"negate": Array [
false,
],
Expand All @@ -35,6 +38,9 @@ describe('interpreter/functions#filtersToAst', () => {
expect(actual[1].functions[0]).toHaveProperty('name', 'kibanaFilter');
expect(actual[1].functions[0].arguments).toMatchInlineSnapshot(`
Object {
"disabled": Array [
false,
],
"negate": Array [
true,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const filtersToAst = (filters: Filter[] | Filter) => {
buildExpressionFunction<ExpressionFunctionKibanaFilter>('kibanaFilter', {
query: JSON.stringify(restOfFilter),
negate: filter.meta.negate,
disabled: filter.meta.disabled,
}),
]);
});
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/data/common/search/expressions/kibana_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { KibanaFilter } from './kibana_context_type';
interface Arguments {
query: string;
negate?: boolean;
disabled?: boolean;
}

export type ExpressionFunctionKibanaFilter = ExpressionFunctionDefinition<
Expand Down Expand Up @@ -45,6 +46,13 @@ export const kibanaFilterFunction: ExpressionFunctionKibanaFilter = {
defaultMessage: 'Should the filter be negated',
}),
},
disabled: {
types: ['boolean'],
default: false,
help: i18n.translate('data.search.functions.kibanaFilter.disabled.help', {
defaultMessage: 'Should the filter be disabled',
}),
},
},

fn(input, args) {
Expand All @@ -53,7 +61,7 @@ export const kibanaFilterFunction: ExpressionFunctionKibanaFilter = {
meta: {
negate: args.negate || false,
alias: '',
disabled: false,
disabled: args.disabled || false,
},
...JSON.parse(args.query),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ export function createDiscoverGridDirective(reactDirective: any) {
['settings', { watchDepth: 'reference' }],
['showTimeCol', { watchDepth: 'value' }],
['sort', { watchDepth: 'value' }],
['className', { watchDepth: 'value' }],
]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React, { useRef, useEffect } from 'react';
import { I18nProvider } from '@kbn/i18n/react';
import { IScope } from 'angular';
import { getServices } from '../../../kibana_services';
import { DocTableLegacyProps, injectAngularElement } from './create_doc_table_react';

type AngularEmbeddableScope = IScope & { renderProps?: DocTableEmbeddableProps };

export interface DocTableEmbeddableProps extends Partial<DocTableLegacyProps> {
refs: HTMLElement;
}

function getRenderFn(domNode: Element, props: DocTableEmbeddableProps) {
const directive = {
template: `<doc-table
class="panel-content"
columns="renderProps.columns"
data-description="{{renderProps.searchDescription}}"
data-shared-item
data-test-subj="embeddedSavedSearchDocTable"
data-title="{{renderProps.sharedItemTitle}}"
filter="renderProps.onFilter"
hits="renderProps.rows"
index-pattern="renderProps.indexPattern"
is-loading="renderProps.isLoading"
on-add-column="renderProps.onAddColumn"
on-change-sort-order="renderProps.onSort"
on-move-column="renderProps.onMoveColumn"
on-remove-column="renderProps.onRemoveColumn"
render-complete
sorting="renderProps.sort"
total-hit-count="renderProps.totalHitCount"
use-new-fields-api="renderProps.useNewFieldsApi"></doc-table>`,
};

return async () => {
try {
const injector = await getServices().getEmbeddableInjector();
return await injectAngularElement(domNode, directive.template, props, injector);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
throw e;
}
};
}

export function DiscoverDocTableEmbeddable(props: DocTableEmbeddableProps) {
return (
<I18nProvider>
<DocTableLegacyInner {...props} />
</I18nProvider>
);
}

function DocTableLegacyInner(renderProps: DocTableEmbeddableProps) {
const scope = useRef<AngularEmbeddableScope | undefined>();

useEffect(() => {
if (renderProps.refs && !scope.current) {
const fn = getRenderFn(renderProps.refs, renderProps);
fn().then((newScope) => {
scope.current = newScope;
});
} else if (scope?.current) {
scope.current.renderProps = { ...renderProps };
scope.current.$applyAsync();
}
}, [renderProps]);

useEffect(() => {
return () => {
scope.current?.$destroy();
};
}, []);
return <React.Fragment />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
export { createDocTableDirective } from './doc_table';
export { getSort, getSortArray } from './lib/get_sort';
export { getSortForSearchSource } from './lib/get_sort_for_search_source';
export { getDefaultSort } from './lib/get_default_sort';
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export interface DiscoverGridProps {
* Determines which element labels the grid for ARIA
*/
ariaLabelledBy: string;
/**
* Optional class name to apply
*/
className?: string;
/**
* Determines which columns are displayed
*/
Expand Down Expand Up @@ -175,6 +179,7 @@ export const DiscoverGrid = ({
isSortEnabled = true,
isPaginationEnabled = true,
controlColumnIds = ['openDetails', 'select'],
className,
}: DiscoverGridProps) => {
const [selectedDocs, setSelectedDocs] = useState<string[]>([]);
const [isFilterActive, setIsFilterActive] = useState(false);
Expand Down Expand Up @@ -284,6 +289,7 @@ export const DiscoverGrid = ({
),
[displayedColumns, indexPattern, showTimeCol, settings, defaultColumns, isSortEnabled]
);

const schemaDetectors = useMemo(() => getSchemaDetectors(), []);
const columnsVisibility = useMemo(
() => ({
Expand Down Expand Up @@ -368,6 +374,7 @@ export const DiscoverGrid = ({
data-title={searchTitle}
data-description={searchDescription}
data-document-number={displayedRows.length}
className={className}
>
<KibanaContextProvider services={{ uiSettings: services.uiSettings }}>
<EuiDataGridMemoized
Expand Down
Loading

0 comments on commit e5356f2

Please sign in to comment.