Skip to content

Commit

Permalink
[Discover] Mark other lnsXY charts as Customized too
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Apr 3, 2024
1 parent 051bd82 commit 4406b0e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const SuggestionSelector = ({
>
<EuiComboBox
data-test-subj="unifiedHistogramSuggestionSelector"
prepend={<EuiIcon type={activeSuggestion?.previewIcon ?? 'empty'} />}
prepend={<EuiIcon type={activeSuggestion?.previewIcon ?? 'lensApp'} />}
placeholder={i18n.translate('unifiedHistogram.suggestionSelectorPlaceholder', {
defaultMessage: 'Select visualization',
})}
Expand All @@ -110,7 +110,7 @@ export const SuggestionSelector = ({
return (
<EuiFlexGroup gutterSize="s" alignItems="center" responsive={false}>
<EuiFlexItem grow={null}>
<EuiIcon type={suggestion?.previewIcon ?? 'empty'} />
<EuiIcon type={suggestion?.previewIcon ?? 'lensApp'} />
</EuiFlexItem>
<EuiFlexItem>{option.label}</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@ export class LensVisService {
}
}

if (
externalVisContext &&
externalVisContext.suggestionType === UnifiedHistogramSuggestionType.lensSuggestion
) {
if (externalVisContext) {
// externalVisContext can be based on an unfamiliar suggestion, but it was saved somehow, so try to restore it too
const derivedSuggestion = deriveLensSuggestionFromLensAttributes({
externalVisContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import type { DataView } from '@kbn/data-views-plugin/common';
import type { Suggestion } from '@kbn/lens-plugin/public';
import {
exportVisContext,
canImportVisContext,
exportVisContext,
isSuggestionShapeAndVisContextCompatible,
} from './external_vis_context';
import { getLensVisMock } from '../__mocks__/lens_vis';
import { dataViewWithTimefieldMock } from '../__mocks__/data_view_with_timefield';
import { tableMock, tableQueryMock } from '../__mocks__/table';
import type { UnifiedHistogramVisContext } from '../types';
import { UnifiedHistogramSuggestionType, UnifiedHistogramVisContext } from '../types';

describe('external_vis_context', () => {
const dataView: DataView = dataViewWithTimefieldMock;
Expand Down Expand Up @@ -63,6 +63,7 @@ describe('external_vis_context', () => {
isSuggestionShapeAndVisContextCompatible(
{ visualizationId: 'lnsPie', visualizationState: { shape: 'donut' } } as Suggestion,
{
suggestionType: UnifiedHistogramSuggestionType.lensSuggestion,
attributes: {
visualizationType: 'lnsPie',
state: { visualization: { shape: 'donut' } },
Expand All @@ -75,6 +76,7 @@ describe('external_vis_context', () => {
isSuggestionShapeAndVisContextCompatible(
{ visualizationId: 'lnsPie', visualizationState: { shape: 'donut' } } as Suggestion,
{
suggestionType: UnifiedHistogramSuggestionType.lensSuggestion,
attributes: {
visualizationType: 'lnsPie',
state: { visualization: { shape: 'waffle' } },
Expand All @@ -87,12 +89,76 @@ describe('external_vis_context', () => {
isSuggestionShapeAndVisContextCompatible(
{ visualizationId: 'lnsPie', visualizationState: { shape: 'donut' } } as Suggestion,
{
suggestionType: UnifiedHistogramSuggestionType.lensSuggestion,
attributes: {
visualizationType: 'lnsXY',
},
} as UnifiedHistogramVisContext
)
).toBe(false);

expect(
isSuggestionShapeAndVisContextCompatible(
{
visualizationId: 'lnsXY',
visualizationState: { preferredSeriesType: 'bar_stacked' },
} as Suggestion,
{
attributes: {
visualizationType: 'lnsXY',
state: { visualization: { preferredSeriesType: 'bar_stacked' } },
},
} as UnifiedHistogramVisContext
)
).toBe(true);

expect(
isSuggestionShapeAndVisContextCompatible(
{
visualizationId: 'lnsXY',
visualizationState: { preferredSeriesType: 'bar_stacked' },
} as Suggestion,
{
suggestionType: UnifiedHistogramSuggestionType.histogramForESQL,
attributes: {
visualizationType: 'lnsXY',
state: { visualization: { preferredSeriesType: 'line' } },
},
} as UnifiedHistogramVisContext
)
).toBe(true);

expect(
isSuggestionShapeAndVisContextCompatible(
{
visualizationId: 'lnsXY',
visualizationState: { preferredSeriesType: 'bar_stacked' },
} as Suggestion,
{
suggestionType: UnifiedHistogramSuggestionType.lensSuggestion,
attributes: {
visualizationType: 'lnsXY',
state: { visualization: { preferredSeriesType: 'line' } },
},
} as UnifiedHistogramVisContext
)
).toBe(false);

expect(
isSuggestionShapeAndVisContextCompatible(
{
visualizationId: 'lnsXY',
visualizationState: { preferredSeriesType: 'bar_stacked' },
} as Suggestion,
{
suggestionType: UnifiedHistogramSuggestionType.histogramForDataView,
attributes: {
visualizationType: 'lnsXY',
state: { visualization: { preferredSeriesType: 'bar_stacked' } },
},
} as UnifiedHistogramVisContext
)
).toBe(true);
});
});
});
25 changes: 21 additions & 4 deletions src/plugins/unified_histogram/public/utils/external_vis_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { Suggestion } from '@kbn/lens-plugin/public';
import type { UnifiedHistogramVisContext } from '../types';
import { UnifiedHistogramSuggestionType, UnifiedHistogramVisContext } from '../types';
import { removeTablesFromLensAttributes } from './lens_vis_from_table';

export const exportVisContext = (
Expand Down Expand Up @@ -66,11 +66,28 @@ export const isSuggestionShapeAndVisContextCompatible = (
if (!suggestion && !externalVisContext) {
return true;
}

if (suggestion?.visualizationId !== externalVisContext?.attributes?.visualizationType) {
return false;
}

if (externalVisContext?.suggestionType !== UnifiedHistogramSuggestionType.lensSuggestion) {
return true;
}

if (suggestion?.visualizationId === 'lnsXY') {
return (
// @ts-expect-error visualization state has different structure between vis types
suggestion?.visualizationState?.preferredSeriesType ===
// @ts-expect-error visualization state has different structure between vis types
externalVisContext?.attributes?.state?.visualization?.preferredSeriesType
);
}

return (
suggestion?.visualizationId === externalVisContext?.attributes?.visualizationType &&
// @ts-expect-error visualization state has different structure between vis types
suggestion?.visualizationState?.shape ===
// @ts-expect-error visualization state has different structure between vis types
externalVisContext?.attributes?.state?.visualization?.shape
// @ts-expect-error visualization state has different structure between vis types
externalVisContext?.attributes?.state?.visualization?.shape
);
};
7 changes: 6 additions & 1 deletion test/functional/apps/discover/group3/_lens_vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const find = getService('find');
const browser = getService('browser');
const toasts = getService('toasts');
const PageObjects = getPageObjects([
'settings',
'common',
Expand Down Expand Up @@ -86,10 +87,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await testSubjects.getVisibleText('lnsChartSwitchPopover')).to.be(seriesType);
});

await toasts.dismissAll();
await testSubjects.scrollIntoView('applyFlyoutButton');
await testSubjects.click('applyFlyoutButton');
}

async function getCurrentVisSeriesTypeLabel() {
await toasts.dismissAll();
await testSubjects.click('unifiedHistogramEditFlyoutVisualization');
const seriesType = await testSubjects.getVisibleText('lnsChartSwitchPopover');
await testSubjects.click('cancelFlyoutButton');
Expand All @@ -108,6 +112,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']);
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover');
await browser.setWindowSize(1300, 1000);
});

after(async () => {
Expand Down Expand Up @@ -618,7 +623,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.discover.waitUntilSearchingHasFinished();

await testSubjects.missingOrFail('unsavedChangesBadge');
expect(await PageObjects.discover.getCurrentLensChart()).to.be('Bar vertical stacked');
expect(await PageObjects.discover.getCurrentLensChart()).to.be('Customized');
expect(await getCurrentVisSeriesTypeLabel()).to.be('Line');
expect(await getCurrentVisChartTitle()).to.be('Bar vertical stacked');
});
Expand Down

0 comments on commit 4406b0e

Please sign in to comment.