[Textbased] Depict histogram for timebased adhoc dataviews (#161524)

## Summary

Part of https://github.com/elastic/kibana/issues/158802

We decided that in the case we don't render a Lens suggestion (for
example when we have the SELECT * case) to render the histogram.

**Reminder**: Histogram makes sense only of there is a time field. For
text based mode, time field exists **ONLY** if there is the @timestamp
field.

I don't allow navigation to Lens or open the edit flyout in this case.
When the edit flyout allows the editing of the form based visualizations
(such as histogram) I will enable it then.

FTs have been changed to accomodate this change.


<img width="1751" alt="image"
src="3d28d881-bc60-43de-acf8-8cbcd172a3df">


### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Stratoula Kalafateli 2023-07-11 14:32:33 +03:00 committed by GitHub
parent 91a0d2f454
commit f8ef18a26b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 20 deletions

View file

@ -244,6 +244,17 @@ describe('Chart', () => {
).toBeTruthy();
});
it('should not render the edit on the fly button when chart is visible and suggestions dont exist', async () => {
const component = await mountComponent({
currentSuggestion: undefined,
allSuggestions: undefined,
isPlainRecord: true,
});
expect(
component.find('[data-test-subj="unifiedHistogramEditFlyoutVisualization"]').exists()
).toBeFalsy();
});
it('should render the save button when chart is visible and suggestions exist', async () => {
const component = await mountComponent({
currentSuggestion: currentSuggestionMock,

View file

@ -275,7 +275,7 @@ export function Chart({
[isFlyoutVisible]
);
const canEditVisualizationOnTheFly = isPlainRecord && chartVisible;
const canEditVisualizationOnTheFly = currentSuggestion && chartVisible;
return (
<EuiFlexGroup
@ -438,6 +438,7 @@ export function Chart({
disableTriggers={disableTriggers}
disabledActions={disabledActions}
onTotalHitsChange={onTotalHitsChange}
hasLensSuggestions={Boolean(currentSuggestion)}
onChartLoad={onChartLoad}
onFilter={onFilter}
onBrushEnd={onBrushEnd}

View file

@ -51,6 +51,7 @@ function mountComponent() {
request: {
searchSessionId: '123',
},
hasLensSuggestions: false,
hits: {
status: UnifiedHistogramFetchStatus.loading,
total: undefined,

View file

@ -40,6 +40,7 @@ export interface HistogramProps {
hits?: UnifiedHistogramHitsContext;
chart: UnifiedHistogramChartContext;
isPlainRecord?: boolean;
hasLensSuggestions: boolean;
getTimeRange: () => TimeRange;
refetch$: Observable<UnifiedHistogramInputMessage>;
lensAttributesContext: LensAttributesContext;
@ -58,6 +59,7 @@ export function Histogram({
hits,
chart: { timeInterval },
isPlainRecord,
hasLensSuggestions,
getTimeRange,
refetch$,
lensAttributesContext: attributesContext,
@ -109,9 +111,10 @@ export function Histogram({
}
const adapterTables = adapters?.tables?.tables;
const totalHits = isPlainRecord
? Object.values(adapterTables ?? {})?.[0]?.rows?.length
: adapterTables?.unifiedHistogram?.meta?.statistics?.totalCount;
const totalHits =
isPlainRecord && hasLensSuggestions
? Object.values(adapterTables ?? {})?.[0]?.rows?.length
: adapterTables?.unifiedHistogram?.meta?.statistics?.totalCount;
onTotalHitsChange?.(
isLoading ? UnifiedHistogramFetchStatus.loading : UnifiedHistogramFetchStatus.complete,

View file

@ -69,7 +69,7 @@ export const useLensSuggestions = ({
return {
allSuggestions,
currentSuggestion,
suggestionUnsupported: isPlainRecord && !currentSuggestion,
suggestionUnsupported: !dataView.isTimeBased(),
};
};

View file

@ -72,8 +72,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await testSubjects.exists('showQueryBarMenu')).to.be(false);
expect(await testSubjects.exists('addFilter')).to.be(false);
expect(await testSubjects.exists('dscViewModeDocumentButton')).to.be(false);
// here Lens suggests a table so the chart is not rendered
expect(await testSubjects.exists('unifiedHistogramChart')).to.be(false);
// when Lens suggests a table, we render the histogram
expect(await testSubjects.exists('unifiedHistogramChart')).to.be(true);
expect(await testSubjects.exists('unifiedHistogramQueryHits')).to.be(true);
expect(await testSubjects.exists('discoverAlertsButton')).to.be(false);
expect(await testSubjects.exists('shareTopNavButton')).to.be(true);

View file

@ -131,19 +131,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(searchesCountBeforeRestore).to.be(searchesCountAfterRestore); // no new searches started during restore
});
it('should should clean the search session when navigating to SQL mode, and reinitialize when navigating back', async () => {
await PageObjects.common.navigateToApp('discover');
await PageObjects.timePicker.setDefaultAbsoluteRange();
await PageObjects.header.waitUntilLoadingHasFinished();
expect(await searchSessions.exists()).to.be(true);
await PageObjects.discover.selectTextBaseLang('SQL');
await PageObjects.header.waitUntilLoadingHasFinished();
await searchSessions.missingOrFail();
await browser.goBack();
await PageObjects.header.waitUntilLoadingHasFinished();
expect(await searchSessions.exists()).to.be(true);
});
});
async function getSearchSessionId(): Promise<string> {