Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/elastic/kibana into move-st…
Browse files Browse the repository at this point in the history
…ructure-list-apis
  • Loading branch information
WafaaNasr committed Nov 27, 2023
2 parents 4252208 + 8af39c3 commit ab80e94
Show file tree
Hide file tree
Showing 84 changed files with 1,565 additions and 466 deletions.
2 changes: 0 additions & 2 deletions docs/api/alerting/enable_rule.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

Enable a rule.

WARNING: This API supports <<token-api-authentication>> only.

[NOTE]
====
For the most up-to-date API details, refer to the
Expand Down
4 changes: 2 additions & 2 deletions docs/setup/connect-to-elasticsearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ Details for each programming language library that Elastic provides are in the
https://www.elastic.co/guide/en/elasticsearch/client/index.html[{es} Client documentation].

If you are running {kib} on our hosted {es} Service,
click *Endpoints* on the *Integrations* view
click *Connection details* on the *Integrations* view
to verify your {es} endpoint and Cloud ID, and create API keys for integration.
Alternatively, the *Endpoints* are also accessible through the top bar help menu.
Alternatively, the *Connection details* are also accessible through the top bar help menu.

[float]
=== Add sample data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const DeploymentDetailsModal: FC<Props> = ({ closeModal }) => {
>
<EuiModalHeader>
<EuiModalHeaderTitle>
{i18n.translate('cloud.deploymentDetails.helpMenuLinks.endpoints', {
defaultMessage: 'Endpoints',
{i18n.translate('cloud.deploymentDetails.helpMenuLinks.connectionDetails', {
defaultMessage: 'Connection details',
})}
</EuiModalHeaderTitle>
</EuiModalHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,81 @@ describe('createPointInTimeFinder()', () => {
);
});

test('does not yield empty first page', async () => {
repository.openPointInTimeForType.mockResolvedValueOnce({
id: 'abc123',
});
repository.find.mockResolvedValueOnce({
total: 2,
saved_objects: [],
pit_id: 'abc123',
per_page: 2,
page: 0,
});

const findOptions: SavedObjectsCreatePointInTimeFinderOptions = {
type: ['visualization'],
search: 'foo*',
};

const internalOptions = {};
const finder = new PointInTimeFinder(findOptions, {
logger,
client: repository,
internalOptions,
});

const hits: SavedObjectsFindResult[] = [];
let pageCount = 0;
for await (const result of finder.find()) {
hits.push(...result.saved_objects);
pageCount++;
}

expect(pageCount).toEqual(0);
expect(hits.length).toEqual(0);
});

test('yields empty first page if aggregations are used', async () => {
repository.openPointInTimeForType.mockResolvedValueOnce({
id: 'abc123',
});
repository.find.mockResolvedValueOnce({
total: 2,
saved_objects: [],
pit_id: 'abc123',
per_page: 2,
page: 0,
});

const findOptions: SavedObjectsCreatePointInTimeFinderOptions = {
type: ['visualization'],
search: 'foo*',
aggs: {
some: {
avg: { field: 'fo' },
},
},
};

const internalOptions = {};
const finder = new PointInTimeFinder(findOptions, {
logger,
client: repository,
internalOptions,
});

const hits: SavedObjectsFindResult[] = [];
let pageCount = 0;
for await (const result of finder.find()) {
hits.push(...result.saved_objects);
pageCount++;
}

expect(pageCount).toEqual(1);
expect(hits.length).toEqual(0);
});

test('still applies the defaults in the mandatory fields even when `undefined` is explicitly provided', async () => {
repository.openPointInTimeForType.mockResolvedValueOnce({
id: 'abc123',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ export class PointInTimeFinder<T = unknown, A = unknown>
await this.close();
}

yield results;
// do not yield first page if empty, unless there are aggregations
// (in which case we always want to return at least one page)
if (lastResultsCount > 0 || this.#findOptions.aggs) {
yield results;
}

// We've reached the end when there are fewer hits than our perPage size,
// or when `close()` has been called.
} while (this.#open && lastResultsCount >= this.#findOptions.perPage!);
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es-query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export {
getIndexPatternFromSQLQuery,
getIndexPatternFromESQLQuery,
getLanguageDisplayName,
cleanupESQLQueryForLensSuggestions,
} from './src/es_query';

export {
Expand Down
15 changes: 15 additions & 0 deletions packages/kbn-es-query/src/es_query/es_aggregate_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getAggregateQueryMode,
getIndexPatternFromSQLQuery,
getIndexPatternFromESQLQuery,
cleanupESQLQueryForLensSuggestions,
} from './es_aggregate_query';

describe('sql query helpers', () => {
Expand Down Expand Up @@ -115,4 +116,18 @@ describe('sql query helpers', () => {
expect(idxPattern9).toBe('foo-1, foo-2');
});
});

describe('cleanupESQLQueryForLensSuggestions', () => {
it('should not remove anything if a drop command is not present', () => {
expect(cleanupESQLQueryForLensSuggestions('from a | eval b = 1')).toBe('from a | eval b = 1');
});

it('should remove multiple drop statement if present', () => {
expect(
cleanupESQLQueryForLensSuggestions(
'from a | drop @timestamp | drop a | drop b | keep c | drop d'
)
).toBe('from a | keep c ');
});
});
});
5 changes: 5 additions & 0 deletions packages/kbn-es-query/src/es_query/es_aggregate_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ export function getIndexPatternFromESQLQuery(esql?: string): string {
}
return '';
}

export function cleanupESQLQueryForLensSuggestions(esql?: string): string {
const pipes = (esql || '').split('|');
return pipes.filter((statement) => !/DROP\s/i.test(statement)).join('|');
}
1 change: 1 addition & 0 deletions packages/kbn-es-query/src/es_query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export {
getIndexPatternFromSQLQuery,
getLanguageDisplayName,
getIndexPatternFromESQLQuery,
cleanupESQLQueryForLensSuggestions,
} from './es_aggregate_query';
export { fromCombinedFilter } from './from_combined_filter';
export type {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 { DataView } from '@kbn/data-views-plugin/public';
import { buildDataViewMock } from '@kbn/discover-utils/src/__mocks__';

const fields = [
{
name: '_index',
type: 'string',
scripted: false,
filterable: true,
},
{
name: 'timestamp',
displayName: 'timestamp',
type: 'date',
scripted: false,
filterable: true,
aggregatable: true,
sortable: true,
},
{
name: 'message',
displayName: 'message',
type: 'string',
scripted: false,
filterable: false,
},
{
name: 'extension',
displayName: 'extension',
type: 'string',
scripted: false,
filterable: true,
aggregatable: true,
},
{
name: 'bytes',
displayName: 'bytes',
type: 'number',
scripted: false,
filterable: true,
aggregatable: true,
},
{
name: 'scripted',
displayName: 'scripted',
type: 'number',
scripted: true,
filterable: false,
},
] as DataView['fields'];

export const dataViewWithoutTimefieldMock = buildDataViewMock({
name: 'index-pattern-without-timefield',
fields,
timeFieldName: undefined,
});
17 changes: 14 additions & 3 deletions packages/kbn-unified-data-table/src/components/data_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ import { getDisplayedColumns } from '../utils/columns';
import { convertValueToString } from '../utils/convert_value_to_string';
import { getRowsPerPageOptions } from '../utils/rows_per_page';
import { getRenderCellValueFn } from '../utils/get_render_cell_value';
import { getEuiGridColumns, getLeadControlColumns, getVisibleColumns } from './data_table_columns';
import {
getEuiGridColumns,
getLeadControlColumns,
getVisibleColumns,
hasSourceTimeFieldValue,
} from './data_table_columns';
import { UnifiedDataTableContext } from '../table_context';
import { getSchemaDetectors } from './data_table_schema';
import { DataTableDocumentToolbarBtn } from './data_table_document_selection';
Expand Down Expand Up @@ -617,9 +622,15 @@ export const UnifiedDataTable = ({
[dataView, onFieldEdited, services.dataViewFieldEditor]
);

const shouldShowTimeField = useMemo(
() =>
hasSourceTimeFieldValue(displayedColumns, dataView, columnTypes, showTimeCol, isPlainRecord),
[dataView, displayedColumns, isPlainRecord, showTimeCol, columnTypes]
);

const visibleColumns = useMemo(
() => getVisibleColumns(displayedColumns, dataView, showTimeCol),
[dataView, displayedColumns, showTimeCol]
() => getVisibleColumns(displayedColumns, dataView, shouldShowTimeField),
[dataView, displayedColumns, shouldShowTimeField]
);

const getCellValue = useCallback<UseDataGridColumnsCellActionsProps['getCellValue']>(
Expand Down
Loading

0 comments on commit ab80e94

Please sign in to comment.