Skip to content

Commit

Permalink
Fix all tests I could find
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Mar 10, 2020
1 parent 6365ab6 commit 8eb8fac
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function LayerPanels(
className="lnsConfigPanel__addLayerBtn"
fullWidth
size="s"
data-test-subj={`lnsXY_layer_add`}
data-test-subj="lnsXY_layer_add"
aria-label={i18n.translate('xpack.lens.xyChart.addLayerButton', {
defaultMessage: 'Add layer',
})}
Expand Down Expand Up @@ -236,20 +236,32 @@ function LayerPanel(
const [popoverState, setPopoverState] = useState<{
isOpen: boolean;
openId: string | null;
addingToDimensionId: string | null;
}>({
isOpen: false,
openId: null,
addingToDimensionId: null,
});

const { dimensions } = activeVisualization.getLayerOptions(layerVisualizationConfigProps);
const isEmptyLayer = !dimensions.some(d => d.accessors.length > 0);

function wrapInPopover(id: string, trigger: React.ReactElement, panel: React.ReactElement) {
function wrapInPopover(
id: string,
dimensionId: string,
trigger: React.ReactElement,
panel: React.ReactElement
) {
const noMatch = popoverState.isOpen ? !dimensions.some(d => d.accessors.includes(id)) : false;
return (
<EuiPopover
isOpen={popoverState.isOpen && popoverState.openId === id}
isOpen={
popoverState.isOpen &&
(popoverState.openId === id ||
(noMatch && popoverState.addingToDimensionId === dimensionId))
}
closePopover={() => {
setPopoverState({ isOpen: false, openId: null });
setPopoverState({ isOpen: false, openId: null, addingToDimensionId: null });
}}
button={trigger}
display="block"
Expand Down Expand Up @@ -308,7 +320,7 @@ function LayerPanel(
<DragDrop
key={accessor}
className="lnsConfigPanel__dimension"
data-test-subj="indexPattern-dropTarget"
data-test-subj={dimension.dataTestSubj}
droppable={
dragDropContext.dragging &&
layerDatasource.canHandleDrop({
Expand All @@ -328,22 +340,26 @@ function LayerPanel(
>
{wrapInPopover(
accessor,
dimension.dimensionId,
<NativeRenderer
render={props.datasourceMap[datasourceId].renderDimensionTrigger}
nativeProps={{
...layerDatasourceConfigProps,
columnId: accessor,
filterOperations: dimension.filterOperations,
suggestedPriority: dimension.suggestedPriority,
togglePopover: () => {
if (popoverState.isOpen) {
setPopoverState({
isOpen: false,
openId: null,
addingToDimensionId: null,
});
} else {
setPopoverState({
isOpen: true,
openId: accessor,
addingToDimensionId: null, // not set for existing dimension
});
}
},
Expand Down Expand Up @@ -397,7 +413,7 @@ function LayerPanel(
{dimension.supportsMoreColumns ? (
<DragDrop
className="lnsIndexPatternDimensionPanel"
data-test-subj="indexPattern-dropTarget"
data-test-subj={dimension.dataTestSubj}
droppable={
dragDropContext.dragging &&
layerDatasource.canHandleDrop({
Expand Down Expand Up @@ -426,10 +442,11 @@ function LayerPanel(
}}
>
{wrapInPopover(
dimension.dimensionLabel,
newId,
dimension.dimensionId,
<EuiButtonEmpty
iconType="plusInCircleFilled"
data-test-subj="indexPattern-configure-dimension"
data-test-subj="lns-empty-dimension"
aria-label={i18n.translate('xpack.lens.configure.addConfig', {
defaultMessage: 'Add a configuration',
})}
Expand All @@ -441,11 +458,13 @@ function LayerPanel(
setPopoverState({
isOpen: false,
openId: null,
addingToDimensionId: null,
});
} else {
setPopoverState({
isOpen: true,
openId: dimension.dimensionLabel,
openId: newId,
addingToDimensionId: dimension.dimensionId,
});
}
}}
Expand All @@ -463,6 +482,7 @@ function LayerPanel(
core: props.core,
columnId: newId,
filterOperations: dimension.filterOperations,
suggestedPriority: dimension.suggestedPriority,

setState: (newState: unknown) => {
props.updateVisualization(
Expand All @@ -474,6 +494,11 @@ function LayerPanel(
})
);
props.updateDatasource(datasourceId, newState);
setPopoverState({
isOpen: true,
openId: newId,
addingToDimensionId: null, // clear now that dimension exists
});
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ describe('editor_frame', () => {
act(() => {
instance
.find(DragDrop)
.filter('[data-test-subj="indexPattern-dropTarget"]')
.filter('[data-test-subj="mockVisA"]')
.prop('onDrop')!({
indexPatternId: '1',
field: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function createMockVisualization(): jest.Mocked<Visualization> {
getPersistableState: jest.fn(_state => _state),
getSuggestions: jest.fn(_options => []),
initialize: jest.fn((_frame, _state?) => ({})),
getLayerOptions: jest.fn(() => ({
getLayerOptions: jest.fn(props => ({
dimensions: [
{
layerId: 'layer1',
Expand All @@ -42,6 +42,7 @@ export function createMockVisualization(): jest.Mocked<Visualization> {
supportsMoreColumns: true,
accessors: [],
filterOperations: jest.fn(() => true),
dataTestSubj: 'mockVisA',
},
],
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import _ from 'lodash';
import React, { memo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiLink } from '@elastic/eui';
import { IUiSettingsClient, SavedObjectsClientContract, HttpSetup } from 'src/core/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import {
Expand All @@ -17,7 +19,7 @@ import {
import { DataPublicPluginStart } from '../../../../../../../src/plugins/data/public';
import { IndexPatternColumn, OperationType } from '../indexpattern';
import { getAvailableOperationsByMetadata, buildColumn, changeField } from '../operations';
import { PopoverEditor, PopoverTrigger } from './popover_editor';
import { PopoverEditor } from './popover_editor';
import { changeColumn } from '../state_helpers';
import { isDraggedField, hasField } from '../utils';
import { IndexPatternPrivateState, IndexPatternField } from '../types';
Expand Down Expand Up @@ -179,20 +181,37 @@ export const IndexPatternDimensionTriggerComponent = function IndexPatternDimens
props: IndexPatternDimensionTriggerProps
) {
const layerId = props.layerId;
const currentIndexPattern =
props.state.indexPatterns[props.state.layers[layerId]?.indexPatternId];
const operationFieldSupportMatrix = getOperationFieldSupportMatrix(props);

const selectedColumn: IndexPatternColumn | null =
props.state.layers[layerId].columns[props.columnId] || null;

const { columnId, uniqueLabel } = props;
return (
<PopoverTrigger
{...props}
currentIndexPattern={currentIndexPattern}
selectedColumn={selectedColumn}
operationFieldSupportMatrix={operationFieldSupportMatrix}
/>
<div
id={columnId}
className={[
'lnsPopoverEditor',
selectedColumn ? 'lnsPopoverEditor__anchor' : 'lnsPopoverEditor__link',
].join(' ')}
>
{selectedColumn ? (
<EuiLink
className="lnsPopoverEditor__link"
onClick={() => {
props.togglePopover();
}}
data-test-subj="lns-dimensionTrigger"
aria-label={i18n.translate('xpack.lens.configure.editConfig', {
defaultMessage: 'Edit configuration',
})}
title={i18n.translate('xpack.lens.configure.editConfig', {
defaultMessage: 'Edit configuration',
})}
>
{uniqueLabel}
</EuiLink>
) : null}
</div>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ import {
EuiCallOut,
EuiFormRow,
EuiFieldText,
EuiLink,
EuiSpacer,
} from '@elastic/eui';
import classNames from 'classnames';
import { IndexPatternColumn, OperationType } from '../indexpattern';
import {
IndexPatternDimensionTriggerProps,
IndexPatternDimensionEditorProps,
OperationFieldSupportMatrix,
} from './dimension_panel';
import { IndexPatternDimensionEditorProps, OperationFieldSupportMatrix } from './dimension_panel';
import {
operationDefinitionMap,
getOperationDisplay,
Expand All @@ -40,12 +35,6 @@ import { FormatSelector } from './format_selector';

const operationPanels = getOperationDisplay();

export interface PopoverTriggerProps extends IndexPatternDimensionTriggerProps {
selectedColumn?: IndexPatternColumn;
operationFieldSupportMatrix: OperationFieldSupportMatrix;
currentIndexPattern: IndexPattern;
}

export interface PopoverEditorProps extends IndexPatternDimensionEditorProps {
selectedColumn?: IndexPatternColumn;
operationFieldSupportMatrix: OperationFieldSupportMatrix;
Expand Down Expand Up @@ -380,38 +369,6 @@ export function PopoverEditor(props: PopoverEditorProps) {
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
)
</div>
);
}

export function PopoverTrigger(props: PopoverTriggerProps) {
const { selectedColumn, columnId, uniqueLabel } = props;
return (
<div
id={columnId}
className={[
'lnsPopoverEditor',
selectedColumn ? 'lnsPopoverEditor__anchor' : 'lnsPopoverEditor__link',
].join(' ')}
>
{selectedColumn ? (
<EuiLink
className="lnsPopoverEditor__link"
onClick={() => {
props.togglePopover();
}}
data-test-subj="indexPattern-configure-dimension"
aria-label={i18n.translate('xpack.lens.configure.editConfig', {
defaultMessage: 'Edit configuration',
})}
title={i18n.translate('xpack.lens.configure.editConfig', {
defaultMessage: 'Edit configuration',
})}
>
{uniqueLabel}
</EuiLink>
) : null}
</div>
);
}
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ interface VisualizationDimensionConfig {
hideGrouping?: boolean;

required?: boolean;

dataTestSubj?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ export const buildExpression = (

hide: [Boolean(layer.hide)],

xAccessor: [layer.xAccessor],
xAccessor: [layer.xAccessor!],
yScaleType: [
getScaleType(metadata[layer.layerId][layer.accessors[0]], ScaleType.Ordinal),
],
xScaleType: [
getScaleType(metadata[layer.layerId][layer.xAccessor!], ScaleType.Linear),
],
isHistogram: [isHistogramDimension],
splitAccessor: [layer.splitAccessor],
splitAccessor: [layer.splitAccessor!],
seriesType: [layer.seriesType],
accessors: layer.accessors,
columnToLabel: [JSON.stringify(columnToLabel)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const xyVisualization: Visualization<State, PersistableState> = {
suggestedPriority: 1,
supportsMoreColumns: !layer.xAccessor,
required: true,
dataTestSubj: 'lnsXY_xDimensionPanel',
},
{
dimensionId: 'y',
Expand All @@ -170,6 +171,7 @@ export const xyVisualization: Visualization<State, PersistableState> = {
filterOperations: isNumericMetric,
supportsMoreColumns: true,
required: true,
dataTestSubj: 'lnsXY_yDimensionPanel',
},
{
dimensionId: 'breakdown',
Expand All @@ -180,6 +182,7 @@ export const xyVisualization: Visualization<State, PersistableState> = {
filterOperations: isBucketed,
suggestedPriority: 0,
supportsMoreColumns: !layer.splitAccessor,
dataTestSubj: 'lnsXY_splitDimensionPanel',
},
],
};
Expand Down
6 changes: 3 additions & 3 deletions x-pack/test/functional/apps/lens/smokescreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ export default function({ getService, getPageObjects, ...rest }: FtrProviderCont

await PageObjects.lens.configureDimension({
dimension:
'[data-test-subj="lnsXY_xDimensionPanel"] [data-test-subj="indexPattern-configure-dimension"]',
'[data-test-subj="lnsXY_xDimensionPanel"] [data-test-subj="lns-empty-dimension"]',
operation: 'date_histogram',
field: '@timestamp',
});

await PageObjects.lens.configureDimension({
dimension:
'[data-test-subj="lnsXY_yDimensionPanel"] [data-test-subj="indexPattern-configure-dimension"]',
'[data-test-subj="lnsXY_yDimensionPanel"] [data-test-subj="lns-empty-dimension"]',
operation: 'avg',
field: 'bytes',
});

await PageObjects.lens.configureDimension({
dimension:
'[data-test-subj="lnsXY_splitDimensionPanel"] [data-test-subj="indexPattern-configure-dimension"]',
'[data-test-subj="lnsXY_splitDimensionPanel"] [data-test-subj="lns-empty-dimension"]',
operation: 'terms',
field: 'ip',
});
Expand Down

0 comments on commit 8eb8fac

Please sign in to comment.