Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] value based ES|QL data source #171081

Merged
merged 58 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c873473
lens value based source
ppisljar Nov 13, 2023
fe255c1
extend textBasedDatasource rather than introducing a new valueBased d…
ppisljar Nov 15, 2023
d6caf5d
Merge branch 'main' into lens/valueBased
ppisljar Jan 3, 2024
029de8d
add support in discover
ppisljar Jan 3, 2024
25a48aa
fixing circular dependency
ppisljar Jan 4, 2024
75e1f13
fixing histogram mode
ppisljar Jan 4, 2024
845ded1
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 4, 2024
417b8ad
Merge branch 'main' into lens/valueBased
ppisljar Jan 8, 2024
2bd72cc
fixes
ppisljar Jan 8, 2024
1621b70
trying to fix test
ppisljar Jan 8, 2024
e66962d
Merge branch 'main' into lens/valueBased
ppisljar Jan 9, 2024
d9b807d
trying to fix test
ppisljar Jan 9, 2024
e6ef04b
fixes
ppisljar Jan 10, 2024
56464a5
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 10, 2024
330f25a
fixes
ppisljar Jan 10, 2024
88099a8
fixes
ppisljar Jan 14, 2024
37fccc1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 14, 2024
36cf10a
Merge branch 'main' into lens/valueBased
ppisljar Jan 15, 2024
890d739
trying to fix test
ppisljar Jan 15, 2024
e1a1252
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 15, 2024
33dc62e
Revert "trying to fix test"
ppisljar Jan 16, 2024
021484b
trying to fix test
ppisljar Jan 16, 2024
3b4d276
Merge branch 'main' into lens/valueBased
ppisljar Jan 16, 2024
af7c8c2
fixing based on review
ppisljar Jan 17, 2024
a382c72
fixing based on review
ppisljar Jan 18, 2024
b3104b8
Merge branch 'main' into lens/valueBased
ppisljar Jan 18, 2024
98b4f84
fixing
ppisljar Jan 18, 2024
044fa30
Merge branch 'main' into lens/valueBased
ppisljar Jan 18, 2024
af9b787
Merge branch 'main' into lens/valueBased
ppisljar Jan 19, 2024
5463975
Merge branch 'main' into lens/valueBased
stratoula Jan 22, 2024
663c7b2
fixing based on last review comment
ppisljar Jan 22, 2024
f74ee11
Simplifications and solve bug
stratoula Jan 22, 2024
7190ab5
Merge branch 'lens/valueBased' into branch-byvalue-textbased
stratoula Jan 22, 2024
47d10f0
Merge pull request #11 from stratoula/branch-byvalue-textbased
ppisljar Jan 22, 2024
6192b27
fixing tests
ppisljar Jan 23, 2024
b768e0d
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 23, 2024
570c98d
fixing tests
ppisljar Jan 23, 2024
5190cb6
fixing tests
ppisljar Jan 23, 2024
e1bd07f
fixing tests
ppisljar Jan 23, 2024
67e87c5
Apply suggestions from code review
ppisljar Jan 23, 2024
8d06bb4
fixing based on review
ppisljar Jan 23, 2024
5ef2386
fixing based on review
ppisljar Jan 23, 2024
55c4763
fixing test
ppisljar Jan 23, 2024
87436a0
fixing test
ppisljar Jan 23, 2024
69c8e35
fixing test
ppisljar Jan 24, 2024
5dc0696
Update src/plugins/unified_histogram/public/chart/chart.tsx
ppisljar Jan 24, 2024
8013daa
fixing
ppisljar Jan 24, 2024
e1ce91a
Merge branch 'main' into lens/valueBased
ppisljar Jan 24, 2024
6cff500
fixing
ppisljar Jan 24, 2024
c61b3df
fixing state issues
ppisljar Jan 24, 2024
5287cb9
fixing state issues
ppisljar Jan 24, 2024
5aaf6ab
Fixes based on review
stratoula Jan 25, 2024
2351e02
Clenaup
stratoula Jan 25, 2024
53a4461
Merge pull request #12 from stratoula/woof-meow-3
ppisljar Jan 25, 2024
df3f27b
fixing test
ppisljar Jan 25, 2024
c6c0835
fixing test
ppisljar Jan 25, 2024
3a48475
Merge branch 'main' into lens/valueBased
ppisljar Jan 25, 2024
2400cbd
Merge branch 'main' into lens/valueBased
ppisljar Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useCallback } from 'react';
import { UnifiedHistogramContainer } from '@kbn/unified-histogram-plugin/public';
import { css } from '@emotion/react';
import useObservable from 'react-use/lib/useObservable';
import { Datatable } from '@kbn/expressions-plugin/common';
ppisljar marked this conversation as resolved.
Show resolved Hide resolved
import { useDiscoverHistogram } from './use_discover_histogram';
import { type DiscoverMainContentProps, DiscoverMainContent } from './discover_main_content';
import { useAppStateSelector } from '../../services/discover_app_state_container';
Expand Down Expand Up @@ -40,6 +41,7 @@ export const DiscoverHistogramLayout = ({
isPlainRecord,
});

const datatable = useObservable(dataState.data$.documents$);
const renderCustomChartToggleActions = useCallback(
() =>
React.isValidElement(panelsToggle)
Expand All @@ -54,11 +56,21 @@ export const DiscoverHistogramLayout = ({
return null;
}

let table: Datatable | undefined;
if (datatable && ['partial', 'complete'].includes(datatable.fetchStatus)) {
table = {
type: 'datatable' as 'datatable',
rows: datatable.result!.map((r) => r.raw),
ppisljar marked this conversation as resolved.
Show resolved Hide resolved
columns: datatable.textBasedQueryColumns || [],
};
}
ppisljar marked this conversation as resolved.
Show resolved Hide resolved

return (
<UnifiedHistogramContainer
{...unifiedHistogramProps}
searchSessionId={searchSessionId}
requestAdapter={dataState.inspectorAdapters.requests}
table={table}
container={container}
css={histogramLayoutCss}
renderCustomChartToggleActions={renderCustomChartToggleActions}
Expand Down
35 changes: 34 additions & 1 deletion src/plugins/unified_histogram/public/chart/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type { DataView, DataViewField } from '@kbn/data-views-plugin/public';
import type { LensEmbeddableInput } from '@kbn/lens-plugin/public';
import type { AggregateQuery, Filter, Query, TimeRange } from '@kbn/es-query';
import { Subject } from 'rxjs';
import { LensAttributes } from '@kbn/lens-embeddable-utils';
import { TextBasedPersistedState } from '@kbn/lens-plugin/public/datasources/text_based/types';
ppisljar marked this conversation as resolved.
Show resolved Hide resolved
import { Histogram } from './histogram';
import type {
UnifiedHistogramBreakdownContext,
Expand Down Expand Up @@ -267,6 +269,35 @@ export function Chart({
});
}

const removeTables = (attributes: LensAttributes) => {
const layers = attributes.state.datasourceStates.textBased?.layers;
ppisljar marked this conversation as resolved.
Show resolved Hide resolved

const newState = {
...attributes,
state: {
...attributes.state,
datasourceStates: {
...attributes.state.datasourceStates,
textBased: {
...(attributes.state.datasourceStates.textBased || {}),
layers: {} as TextBasedPersistedState['layers'],
},
},
},
};

if (layers) {
for (const key of Object.keys(layers)) {
// Modify the value as needed, e.g., appending ' modified' to each value
ppisljar marked this conversation as resolved.
Show resolved Hide resolved
const newLayer = { ...layers[key] };
delete newLayer.table;
newState.state.datasourceStates.textBased!.layers[key] = newLayer;
}
}

return newState;
};

return (
<EuiFlexGroup
{...a11yCommonProps}
Expand Down Expand Up @@ -397,7 +428,9 @@ export function Chart({
)}
{canSaveVisualization && isSaveModalVisible && lensAttributesContext.attributes && (
<LensSaveModalComponent
initialInput={lensAttributesContext.attributes as unknown as LensEmbeddableInput}
initialInput={
removeTables(lensAttributesContext.attributes) as unknown as LensEmbeddableInput
}
onSave={() => {}}
onClose={() => setIsSaveModalVisible(false)}
isSaveable={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Subject } from 'rxjs';
import { pick } from 'lodash';
import useMount from 'react-use/lib/useMount';
import { LensSuggestionsApi } from '@kbn/lens-plugin/public';
import { Datatable } from '@kbn/expressions-plugin/common';
ppisljar marked this conversation as resolved.
Show resolved Hide resolved
import { UnifiedHistogramLayout, UnifiedHistogramLayoutProps } from '../layout';
import type { UnifiedHistogramInputMessage, UnifiedHistogramRequestContext } from '../types';
import {
Expand Down Expand Up @@ -43,6 +44,7 @@ export type UnifiedHistogramContainerProps = {
searchSessionId?: UnifiedHistogramRequestContext['searchSessionId'];
requestAdapter?: UnifiedHistogramRequestContext['adapter'];
isChartLoading?: boolean;
table?: Datatable;
stratoula marked this conversation as resolved.
Show resolved Hide resolved
} & Pick<
UnifiedHistogramLayoutProps,
| 'services'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Query,
TimeRange,
} from '@kbn/es-query';
import type { DatatableColumn } from '@kbn/expressions-plugin/common';
import type { Datatable, DatatableColumn } from '@kbn/expressions-plugin/common';
import { LensSuggestionsApi, Suggestion } from '@kbn/lens-plugin/public';
import { isEqual } from 'lodash';
import { useEffect, useMemo, useRef, useState } from 'react';
Expand All @@ -32,6 +32,7 @@ export const useLensSuggestions = ({
timeRange,
lensSuggestionsApi,
onSuggestionChange,
table,
}: {
dataView: DataView;
query?: Query | AggregateQuery;
Expand All @@ -42,13 +43,15 @@ export const useLensSuggestions = ({
timeRange?: TimeRange;
lensSuggestionsApi: LensSuggestionsApi;
onSuggestionChange?: (suggestion: Suggestion | undefined) => void;
table?: Datatable;
}) => {
const suggestions = useMemo(() => {
const context = {
dataViewSpec: dataView?.toSpec(),
fieldName: '',
textBasedColumns: columns,
query: query && isOfAggregateQueryType(query) ? query : undefined,
table,
};
const allSuggestions = isPlainRecord
? lensSuggestionsApi(context, dataView, ['lnsDatatable']) ?? []
Expand All @@ -57,10 +60,10 @@ export const useLensSuggestions = ({
const [firstSuggestion] = allSuggestions;

return { firstSuggestion, allSuggestions };
}, [dataView, isPlainRecord, lensSuggestionsApi, query, columns]);
}, [dataView, columns, query, table, isPlainRecord, lensSuggestionsApi]);

const [allSuggestions, setAllSuggestions] = useState(suggestions.allSuggestions);
const currentSuggestion = originalSuggestion ?? suggestions.firstSuggestion;
const currentSuggestion = originalSuggestion || suggestions.firstSuggestion;
const suggestionDeps = useRef(getSuggestionDeps({ dataView, query, columns }));
const histogramQuery = useRef<AggregateQuery | undefined>();
const histogramSuggestion = useMemo(() => {
Expand Down Expand Up @@ -122,7 +125,7 @@ export const useLensSuggestions = ({
}, [currentSuggestion, dataView, query, timeRange, data, lensSuggestionsApi]);

useEffect(() => {
const newSuggestionsDeps = getSuggestionDeps({ dataView, query, columns });
const newSuggestionsDeps = getSuggestionDeps({ dataView, query, columns, table });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, while testing I noticed that refreshing grid data resets the currently selected suggestion. This should not happen ideally, right?

Jan-24-2024 11-06-40

Btw, the bars chart has some weird issues with rendering as I had to resize the histogram for it to appear.

Copy link
Contributor

@stratoula stratoula Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fixed them both @jughosta , you can retest!


if (!isEqual(suggestionDeps.current, newSuggestionsDeps)) {
setAllSuggestions(suggestions.allSuggestions);
Expand All @@ -133,6 +136,7 @@ export const useLensSuggestions = ({
}, [
columns,
dataView,
table,
onSuggestionChange,
query,
suggestions.firstSuggestion,
Expand All @@ -152,8 +156,10 @@ const getSuggestionDeps = ({
dataView,
query,
columns,
table,
}: {
dataView: DataView;
query?: Query | AggregateQuery;
columns?: DatatableColumn[];
}) => [dataView.id, columns, query];
table?: Datatable;
}) => [dataView.id, columns, query, table];
6 changes: 5 additions & 1 deletion src/plugins/unified_histogram/public/layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { PropsWithChildren, ReactElement, useState } from 'react';
import { Observable } from 'rxjs';
import { createHtmlPortalNode, InPortal, OutPortal } from 'react-reverse-portal';
import { css } from '@emotion/css';
import type { DatatableColumn } from '@kbn/expressions-plugin/common';
import type { Datatable, DatatableColumn } from '@kbn/expressions-plugin/common';
import type { DataView, DataViewField } from '@kbn/data-views-plugin/public';
import type {
EmbeddableComponentProps,
Expand Down Expand Up @@ -179,6 +179,8 @@ export interface UnifiedHistogramLayoutProps extends PropsWithChildren<unknown>
* Allows users to enable/disable default actions
*/
withDefaultActions?: EmbeddableComponentProps['withDefaultActions'];

table?: Datatable;
}

export const UnifiedHistogramLayout = ({
Expand Down Expand Up @@ -207,6 +209,7 @@ export const UnifiedHistogramLayout = ({
disabledActions,
lensSuggestionsApi,
input$,
table,
onTopPanelHeightChange,
onChartHiddenChange,
onTimeIntervalChange,
Expand Down Expand Up @@ -235,6 +238,7 @@ export const UnifiedHistogramLayout = ({
data: services.data,
lensSuggestionsApi,
onSuggestionChange,
table,
});

const chart = suggestionUnsupported ? undefined : originalChart;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/unified_histogram/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@kbn/resizable-layout",
"@kbn/shared-ux-button-toolbar",
"@kbn/calculate-width-from-char-count",
"@kbn/lens-embeddable-utils",
"@kbn/i18n-react",
"@kbn/field-utils",
],
Expand Down
63 changes: 39 additions & 24 deletions test/functional/apps/discover/group3/_request_counts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

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

export default function ({ getService, getPageObjects }: FtrProviderContext) {
Expand Down Expand Up @@ -88,56 +88,51 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
query2,
savedSearchesRequests,
setQuery,
expectedRequests = 2,
expectedRefreshRequest = expectedRequests,
}: {
type: 'ese' | 'esql';
savedSearch: string;
query1: string;
query2: string;
savedSearchesRequests?: number;
setQuery: (query: string) => Promise<void>;
expectedRequests?: number;
expectedRefreshRequest?: number;
}) => {
it('should send 2 search requests (documents + chart) on page load', async () => {
it(`should send ${expectedRequests} search requests (documents + chart) on page load`, async () => {
await browser.refresh();
await browser.execute(async () => {
performance.setResourceTimingBufferSize(Number.MAX_SAFE_INTEGER);
});
await waitForLoadingToFinish();
const searchCount = await getSearchCount(type);
expect(searchCount).to.be(2);
expect(searchCount).to.be(expectedRequests);
});

it('should send 2 requests (documents + chart) when refreshing', async () => {
await expectSearches(type, 2, async () => {
it(`should send ${expectedRefreshRequest} requests (documents + chart) when refreshing`, async () => {
await expectSearches(type, expectedRequests, async () => {
await queryBar.clickQuerySubmitButton();
});
});

it('should send 2 requests (documents + chart) when changing the query', async () => {
await expectSearches(type, 2, async () => {
it(`should send ${expectedRequests} requests (documents + chart) when changing the query`, async () => {
await expectSearches(type, expectedRequests, async () => {
await setQuery(query1);
await queryBar.clickQuerySubmitButton();
});
});

it('should send 2 requests (documents + chart) when changing the time range', async () => {
await expectSearches(type, 2, async () => {
it(`should send ${expectedRequests} requests (documents + chart) when changing the time range`, async () => {
await expectSearches(type, expectedRequests, async () => {
await PageObjects.timePicker.setAbsoluteRange(
'Sep 21, 2015 @ 06:31:44.000',
'Sep 23, 2015 @ 00:00:00.000'
);
});
});

it('should send 2 requests (documents + chart) when toggling the chart visibility', async () => {
await expectSearches(type, 2, async () => {
await PageObjects.discover.toggleChartVisibility();
});
await expectSearches(type, 2, async () => {
await PageObjects.discover.toggleChartVisibility();
});
});

it('should send 2 requests for saved search changes', async () => {
it(`should send ${savedSearchesRequests} requests for saved search changes`, async () => {
await setQuery(query1);
await queryBar.clickQuerySubmitButton();
await PageObjects.timePicker.setAbsoluteRange(
Expand All @@ -148,24 +143,24 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// TODO: Check why the request happens 4 times in case of opening a saved search
// https://github.com/elastic/kibana/issues/165192
// creating the saved search
await expectSearches(type, savedSearchesRequests ?? 2, async () => {
await expectSearches(type, savedSearchesRequests ?? expectedRequests, async () => {
await PageObjects.discover.saveSearch(savedSearch);
});
// resetting the saved search
await setQuery(query2);
await queryBar.clickQuerySubmitButton();
await waitForLoadingToFinish();
await expectSearches(type, 2, async () => {
await expectSearches(type, expectedRequests, async () => {
await PageObjects.discover.revertUnsavedChanges();
});
// clearing the saved search
await expectSearches('ese', 2, async () => {
await expectSearches('ese', savedSearchesRequests ?? expectedRequests, async () => {
await testSubjects.click('discoverNewButton');
await waitForLoadingToFinish();
});
// loading the saved search
// TODO: https://github.com/elastic/kibana/issues/165192
await expectSearches(type, savedSearchesRequests ?? 2, async () => {
await expectSearches(type, savedSearchesRequests ?? expectedRequests, async () => {
await PageObjects.discover.loadSavedSearch(savedSearch);
});
});
Expand All @@ -182,6 +177,15 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
setQuery: (query) => queryBar.setQuery(query),
});

it(`should send 2 requests (documents + chart) when toggling the chart visibility`, async () => {
await expectSearches(type, 2, async () => {
await PageObjects.discover.toggleChartVisibility();
});
await expectSearches(type, 2, async () => {
await PageObjects.discover.toggleChartVisibility();
});
});

it('should send 2 requests (documents + chart) when adding a filter', async () => {
await expectSearches(type, 2, async () => {
await filterBar.addFilter({
Expand Down Expand Up @@ -240,8 +244,19 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
savedSearch: 'esql test',
query1: 'from logstash-* | where bytes > 1000 | stats countB = count(bytes) ',
query2: 'from logstash-* | where bytes < 2000 | stats countB = count(bytes) ',
savedSearchesRequests: 3,
savedSearchesRequests: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

setQuery: (query) => monacoEditor.setCodeEditorValue(query),
expectedRequests: 1,
expectedRefreshRequest: 2,
});

it(`should send 2 requests (documents + chart) when toggling the chart visibility`, async () => {
await expectSearches(type, 2, async () => {
await PageObjects.discover.toggleChartVisibility();
});
await expectSearches(type, 1, async () => {
await PageObjects.discover.toggleChartVisibility();
});
});
});
});
Expand Down
Loading