Fix bug where number rendered as date (#116224)
This commit is contained in:
parent
8ce1c1f9bb
commit
8c6ef2054f
4 changed files with 23 additions and 3 deletions
|
@ -376,7 +376,7 @@ export const exampleResult = {
|
||||||
source: 'custom',
|
source: 'custom',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
schemaFields: {},
|
schemaFields: { cats: 'text', dogs: 'text' },
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mostRecentIndexJob = {
|
export const mostRecentIndexJob = {
|
||||||
|
|
|
@ -45,6 +45,7 @@ describe('ExampleResultDetailCard', () => {
|
||||||
...exampleResult,
|
...exampleResult,
|
||||||
searchResultConfig: { detailFields: [{ fieldName: 'date', label: 'Date' }] },
|
searchResultConfig: { detailFields: [{ fieldName: 'date', label: 'Date' }] },
|
||||||
exampleDocuments: [{ date }],
|
exampleDocuments: [{ date }],
|
||||||
|
schemaFields: { date: 'date' },
|
||||||
});
|
});
|
||||||
const wrapper = shallow(<ExampleResultDetailCard />);
|
const wrapper = shallow(<ExampleResultDetailCard />);
|
||||||
|
|
||||||
|
@ -52,4 +53,17 @@ describe('ExampleResultDetailCard', () => {
|
||||||
new Date(Date.parse(date)).toLocaleString()
|
new Date(Date.parse(date)).toLocaleString()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows non-formatted value when not a date field', () => {
|
||||||
|
const value = '9999';
|
||||||
|
setMockValues({
|
||||||
|
...exampleResult,
|
||||||
|
searchResultConfig: { detailFields: [{ fieldName: 'value', label: 'Value' }] },
|
||||||
|
exampleDocuments: [{ value }],
|
||||||
|
schemaFields: { value: 'text' },
|
||||||
|
});
|
||||||
|
const wrapper = shallow(<ExampleResultDetailCard />);
|
||||||
|
|
||||||
|
expect(wrapper.find(EuiText).children().text()).toContain(value);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { useValues } from 'kea';
|
||||||
|
|
||||||
import { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
|
import { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
|
||||||
|
|
||||||
|
import { SchemaType } from '../../../../../shared/schema/types';
|
||||||
import { URL_LABEL } from '../../../../constants';
|
import { URL_LABEL } from '../../../../constants';
|
||||||
import { getAsLocalDateTimeString } from '../../../../utils';
|
import { getAsLocalDateTimeString } from '../../../../utils';
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ export const ExampleResultDetailCard: React.FC = () => {
|
||||||
titleFieldHover,
|
titleFieldHover,
|
||||||
urlFieldHover,
|
urlFieldHover,
|
||||||
exampleDocuments,
|
exampleDocuments,
|
||||||
|
schemaFields,
|
||||||
} = useValues(DisplaySettingsLogic);
|
} = useValues(DisplaySettingsLogic);
|
||||||
|
|
||||||
const result = exampleDocuments[0];
|
const result = exampleDocuments[0];
|
||||||
|
@ -63,7 +65,8 @@ export const ExampleResultDetailCard: React.FC = () => {
|
||||||
{detailFields.length > 0 ? (
|
{detailFields.length > 0 ? (
|
||||||
detailFields.map(({ fieldName, label }, index) => {
|
detailFields.map(({ fieldName, label }, index) => {
|
||||||
const value = result[fieldName];
|
const value = result[fieldName];
|
||||||
const dateValue = getAsLocalDateTimeString(value);
|
const fieldType = (schemaFields as { [key: string]: SchemaType })[fieldName];
|
||||||
|
const dateValue = fieldType === SchemaType.Date && getAsLocalDateTimeString(value);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -47,7 +47,7 @@ import { ExampleResultDetailCard } from './example_result_detail_card';
|
||||||
import { ResultDetail } from './result_detail';
|
import { ResultDetail } from './result_detail';
|
||||||
|
|
||||||
describe('ResultDetail', () => {
|
describe('ResultDetail', () => {
|
||||||
const { searchResultConfig, exampleDocuments } = exampleResult;
|
const { searchResultConfig, exampleDocuments, schemaFields } = exampleResult;
|
||||||
const availableFieldOptions = [
|
const availableFieldOptions = [
|
||||||
{
|
{
|
||||||
value: 'foo',
|
value: 'foo',
|
||||||
|
@ -70,6 +70,7 @@ describe('ResultDetail', () => {
|
||||||
searchResultConfig,
|
searchResultConfig,
|
||||||
availableFieldOptions,
|
availableFieldOptions,
|
||||||
exampleDocuments,
|
exampleDocuments,
|
||||||
|
schemaFields,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ describe('ResultDetail', () => {
|
||||||
},
|
},
|
||||||
availableFieldOptions,
|
availableFieldOptions,
|
||||||
exampleDocuments,
|
exampleDocuments,
|
||||||
|
schemaFields,
|
||||||
});
|
});
|
||||||
const wrapper = shallow(<ResultDetail />);
|
const wrapper = shallow(<ResultDetail />);
|
||||||
|
|
||||||
|
@ -122,6 +124,7 @@ describe('ResultDetail', () => {
|
||||||
},
|
},
|
||||||
availableFieldOptions,
|
availableFieldOptions,
|
||||||
exampleDocuments,
|
exampleDocuments,
|
||||||
|
schemaFields,
|
||||||
});
|
});
|
||||||
const wrapper = mount(<ResultDetail />);
|
const wrapper = mount(<ResultDetail />);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue