Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Aug 14, 2023
1 parent 0c79dda commit fb5c6d9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/plugins/unified_histogram/public/chart/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface ChartProps {
disabledActions?: LensEmbeddableInput['disabledActions'];
input$?: UnifiedHistogramInput$;
lensTablesAdapter?: Record<string, Datatable>;
isOnHistogramMode?: boolean;
onResetChartHeight?: () => void;
onChartHiddenChange?: (chartHidden: boolean) => void;
onTimeIntervalChange?: (timeInterval: string) => void;
Expand Down Expand Up @@ -104,6 +105,7 @@ export function Chart({
disabledActions,
input$: originalInput$,
lensTablesAdapter,
isOnHistogramMode,
onResetChartHeight,
onChartHiddenChange,
onTimeIntervalChange,
Expand Down Expand Up @@ -425,7 +427,7 @@ export function Chart({
disableTriggers={disableTriggers}
disabledActions={disabledActions}
onTotalHitsChange={onTotalHitsChange}
hasLensSuggestions={Boolean(currentSuggestion)}
hasLensSuggestions={!Boolean(isOnHistogramMode)}
onChartLoad={onChartLoad}
onFilter={onFilter}
onBrushEnd={onBrushEnd}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const useLensSuggestions = ({
const [allSuggestions, setAllSuggestions] = useState(suggestions.allSuggestions);
let currentSuggestion = originalSuggestion ?? suggestions.firstSuggestion;
const suggestionDeps = useRef(getSuggestionDeps({ dataView, query, columns }));
let isOnHistogramMode = false;

if (
!currentSuggestion &&
Expand All @@ -114,9 +115,9 @@ export const useLensSuggestions = ({
isOfAggregateQueryType(query) &&
timeRange
) {
const interval = computeInterval(timeRange, data);
const language = getAggregateQueryMode(query);
if (language === 'esql') {
const interval = computeInterval(timeRange, data);
const histogramQuery = `${query[language]} | eval uniqueName = 1
| EVAL timestamp=DATE_TRUNC(${dataView.timeFieldName}, ${interval}) | stats rows = count(uniqueName) by timestamp | rename timestamp as \`${dataView.timeFieldName} every ${interval}\``;
const context = {
Expand Down Expand Up @@ -147,6 +148,7 @@ export const useLensSuggestions = ({
: [];
if (sug.length) {
currentSuggestion = sug[0];
isOnHistogramMode = true;
}
}
}
Expand All @@ -173,6 +175,7 @@ export const useLensSuggestions = ({
allSuggestions,
currentSuggestion,
suggestionUnsupported: isPlainRecord && !currentSuggestion,
isOnHistogramMode,
};
};

Expand Down
24 changes: 13 additions & 11 deletions src/plugins/unified_histogram/public/layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,18 @@ export const UnifiedHistogramLayout = ({
onBrushEnd,
children,
}: UnifiedHistogramLayoutProps) => {
const { allSuggestions, currentSuggestion, suggestionUnsupported } = useLensSuggestions({
dataView,
query,
originalSuggestion,
isPlainRecord,
columns,
timeRange,
data: services.data,
lensSuggestionsApi,
onSuggestionChange,
});
const { allSuggestions, currentSuggestion, suggestionUnsupported, isOnHistogramMode } =
useLensSuggestions({
dataView,
query,
originalSuggestion,
isPlainRecord,
columns,
timeRange,
data: services.data,
lensSuggestionsApi,
onSuggestionChange,
});

const chart = suggestionUnsupported ? undefined : originalChart;

Expand Down Expand Up @@ -279,6 +280,7 @@ export const UnifiedHistogramLayout = ({
onFilter={onFilter}
onBrushEnd={onBrushEnd}
lensTablesAdapter={lensTablesAdapter}
isOnHistogramMode={isOnHistogramMode}
/>
</InPortal>
<InPortal node={mainPanelNode}>{children}</InPortal>
Expand Down
4 changes: 2 additions & 2 deletions test/functional/apps/discover/group2/_sql_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// when Lens suggests a table, we render the histogram
expect(await testSubjects.exists('unifiedHistogramChart')).to.be(true);
// when Lens suggests a table, we render an ESQL based histogram
expect(await testSubjects.exists('unifiedHistogramChart')).to.be(false);
expect(await testSubjects.exists('unifiedHistogramQueryHits')).to.be(true);
expect(await testSubjects.exists('discoverAlertsButton')).to.be(false);
expect(await testSubjects.exists('shareTopNavButton')).to.be(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ 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> {
Expand Down

0 comments on commit fb5c6d9

Please sign in to comment.