Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -948,6 +948,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
!isFullscreen && operationSupportMatrix.operationWithoutField.has(formulaOperationName);

const hasButtonGroups = !isFullscreen && (hasFormula || supportStaticValue);

const initialMethod = useMemo(() => {
let methodId = '';
if (showStaticValueFunction) {
Expand Down Expand Up @@ -1066,6 +1067,10 @@ export function DimensionEditor(props: DimensionEditorProps) {
selectedOperationDefinition.filterable ||
selectedOperationDefinition.shiftable);

const activeTable = props.activeData?.[layerId];
const activeColumnMeta = activeTable?.columns.find((col) => col.id === columnId)?.meta;
const resolvedDataType = activeColumnMeta?.type ?? selectedColumn?.dataType;

return (
<div id={columnId}>
<div className="lnsIndexPatternDimensionEditor--padded">
Expand Down Expand Up @@ -1214,7 +1219,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
{enableFormatSelector &&
!isFullscreen &&
selectedColumn &&
(selectedColumn.dataType === 'number' || selectedColumn.operationType === 'range') ? (
(resolvedDataType === 'number' || selectedColumn.operationType === 'range') ? (
<FormatSelector
selectedColumn={selectedColumn}
onChange={onFormatChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ const bytesColumn: GenericIndexPatternColumn = {
params: { format: { id: 'bytes' } },
};

const lastValueColumn = (
dataType: GenericIndexPatternColumn['dataType']
): GenericIndexPatternColumn => ({
label: 'Last value of source',
dataType,
isBucketed: false,
operationType: 'last_value',
sourceField: 'source',
params: {},
});

/**
* The datasource exposes four main pieces of code which are tested at
* an integration test level. The main reason for this fairly high level
Expand All @@ -168,8 +179,7 @@ const bytesColumn: GenericIndexPatternColumn = {
* - Dimension trigger: Not tested here
* - Dimension editor component: First half of the tests
*/
// Failing: See https://github.com/elastic/kibana/issues/253327
describe.skip('FormBasedDimensionEditor', () => {
describe('FormBasedDimensionEditor', () => {
let state: FormBasedPrivateState;
let setState: jest.Mock;
let defaultProps: FormBasedDimensionEditorProps;
Expand Down Expand Up @@ -286,6 +296,7 @@ describe.skip('FormBasedDimensionEditor', () => {
afterEach(() => {
if (wrapper) {
wrapper.unmount();
wrapper = undefined as unknown as ReactWrapper | ShallowWrapper;
}
});

Expand Down Expand Up @@ -326,7 +337,8 @@ describe.skip('FormBasedDimensionEditor', () => {
await userEvent.click(screen.getByRole('button', { name: /open list of options/i }));
expect(screen.getByText(/There aren't any options available/)).toBeInTheDocument();
});
test('should list all field names and document as a whole in prioritized order', async () => {
// Failing: See https://github.com/elastic/kibana/issues/253327
test.skip('should list all field names and document as a whole in prioritized order', async () => {
Comment on lines +340 to +341
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Until this slow test issue is fixed #253327, lets only skip the problematic test and not the whole suite.

const { getVisibleFieldSelectOptions } = renderDimensionPanel();

const comboBoxButton = screen.getAllByRole('button', { name: /open list of options/i })[0];
Expand Down Expand Up @@ -2513,4 +2525,52 @@ describe.skip('FormBasedDimensionEditor', () => {

expect(wrapper.find('[data-test-subj="lens-dimensionTabs"]').exists()).toBeFalsy();
});

describe('FormatSelector numeric column detection', () => {
it('should show FormatSelector when activeData reports the column as numeric', () => {
renderDimensionPanel({
state: getStateWithColumns({ col1: lastValueColumn('string') }),
activeData: {
first: {
type: 'datatable',
columns: [{ id: 'col1', name: 'source', meta: { type: 'number' } }],
rows: [],
},
},
});

expect(screen.getByTestId('indexPattern-dimension-format')).toBeInTheDocument();
});

it('should hide FormatSelector when activeData reports the column as non-numeric', () => {
renderDimensionPanel({
state: getStateWithColumns({ col1: lastValueColumn('number') }),
activeData: {
first: {
type: 'datatable',
columns: [{ id: 'col1', name: 'source', meta: { type: 'string' } }],
rows: [],
},
},
});

expect(screen.queryByTestId('indexPattern-dimension-format')).not.toBeInTheDocument();
});

it('should show FormatSelector when selectedColumn dataType is numeric and activeData is not available', () => {
renderDimensionPanel({
state: getStateWithColumns({ col1: lastValueColumn('number') }),
});

expect(screen.getByTestId('indexPattern-dimension-format')).toBeInTheDocument();
});

it('should hide FormatSelector selectedColumn dataType is non numeric and activeData is not available', () => {
renderDimensionPanel({
state: getStateWithColumns({ col1: lastValueColumn('string') }),
});

expect(screen.queryByTestId('indexPattern-dimension-format')).not.toBeInTheDocument();
});
});
});
Loading