mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Fix sort field error message for last value (#184883)
This PR fixes a minor bug on the **Last Value** editor config in which the **Sort by date field** was always considered invalid.
This commit is contained in:
parent
53b445833f
commit
556531b333
2 changed files with 72 additions and 7 deletions
|
@ -21,6 +21,7 @@ import type { FormBasedLayer } from '../../types';
|
|||
import { TermsIndexPatternColumn } from './terms';
|
||||
import { EuiSwitch, EuiSwitchEvent } from '@elastic/eui';
|
||||
import { buildExpression, parseExpression } from '@kbn/expressions-plugin/common';
|
||||
import { FormRow } from './shared_components';
|
||||
|
||||
const uiSettingsMock = {} as IUiSettingsClient;
|
||||
|
||||
|
@ -877,6 +878,7 @@ describe('last_value', () => {
|
|||
|
||||
expect(new Harness(instance).showArrayValuesSwitchDisabled).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not display an array for the last value if the column is referenced', () => {
|
||||
const updateLayerSpy = jest.fn();
|
||||
const instance = shallow(
|
||||
|
@ -892,6 +894,72 @@ describe('last_value', () => {
|
|||
|
||||
expect(new Harness(instance).arrayValuesSwitchNotExisiting).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should show valid sort field for date field', () => {
|
||||
const instance = shallow(
|
||||
<InlineOptions
|
||||
{...defaultProps}
|
||||
isReferenced={true}
|
||||
layer={layer}
|
||||
paramEditorUpdater={jest.fn()}
|
||||
columnId="col2"
|
||||
currentColumn={
|
||||
{
|
||||
...layer.columns.col2,
|
||||
params: {
|
||||
sortField: 'timestamp',
|
||||
},
|
||||
} as LastValueIndexPatternColumn
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(instance.find(FormRow).prop('isInvalid')).toBe(false);
|
||||
});
|
||||
|
||||
it('should show invalid sort field for missing field', () => {
|
||||
const instance = shallow(
|
||||
<InlineOptions
|
||||
{...defaultProps}
|
||||
isReferenced={true}
|
||||
layer={layer}
|
||||
paramEditorUpdater={jest.fn()}
|
||||
columnId="col2"
|
||||
currentColumn={
|
||||
{
|
||||
...layer.columns.col2,
|
||||
params: {
|
||||
sortField: 'not-a-real-field',
|
||||
},
|
||||
} as LastValueIndexPatternColumn
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(instance.find(FormRow).prop('isInvalid')).toBe(true);
|
||||
});
|
||||
|
||||
it('should show invalid sort field for non-date field', () => {
|
||||
const instance = shallow(
|
||||
<InlineOptions
|
||||
{...defaultProps}
|
||||
isReferenced={true}
|
||||
layer={layer}
|
||||
paramEditorUpdater={jest.fn()}
|
||||
columnId="col2"
|
||||
currentColumn={
|
||||
{
|
||||
...layer.columns.col2,
|
||||
params: {
|
||||
sortField: 'bytes',
|
||||
},
|
||||
} as LastValueIndexPatternColumn
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(instance.find(FormRow).prop('isInvalid')).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ const supportedTypes = new Set([
|
|||
'date_range',
|
||||
]);
|
||||
|
||||
function getInvalidSortFieldMessage(
|
||||
function getInvalidSortFieldMessages(
|
||||
sortField: string,
|
||||
columnId: string,
|
||||
indexPattern?: IndexPattern
|
||||
|
@ -226,7 +226,7 @@ export const lastValueOperation: OperationDefinition<
|
|||
const column = layer.columns[columnId] as LastValueIndexPatternColumn;
|
||||
return [
|
||||
...getInvalidFieldMessage(layer, columnId, indexPattern),
|
||||
...getInvalidSortFieldMessage(column.params.sortField, columnId, indexPattern),
|
||||
...getInvalidSortFieldMessages(column.params.sortField, columnId, indexPattern),
|
||||
...getColumnReducedTimeRangeError(layer, columnId, indexPattern),
|
||||
];
|
||||
},
|
||||
|
@ -331,11 +331,8 @@ export const lastValueOperation: OperationDefinition<
|
|||
});
|
||||
|
||||
const dateFields = getDateFields(indexPattern);
|
||||
const isSortFieldInvalid = !!getInvalidSortFieldMessage(
|
||||
currentColumn.params.sortField,
|
||||
'',
|
||||
indexPattern
|
||||
);
|
||||
const isSortFieldInvalid =
|
||||
getInvalidSortFieldMessages(currentColumn.params.sortField, '', indexPattern).length > 0;
|
||||
|
||||
const usingTopValues = Object.keys(layer.columns).some(
|
||||
(_columnId) => layer.columns[_columnId].operationType === 'terms'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue