diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts
index 48cbf4ba00d8..7222edad5682 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts
@@ -376,7 +376,7 @@ export const exampleResult = {
source: 'custom',
},
],
- schemaFields: {},
+ schemaFields: { cats: 'text', dogs: 'text' },
};
export const mostRecentIndexJob = {
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx
index 5a15ef641be9..eeb7f6b54f2c 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx
@@ -45,6 +45,7 @@ describe('ExampleResultDetailCard', () => {
...exampleResult,
searchResultConfig: { detailFields: [{ fieldName: 'date', label: 'Date' }] },
exampleDocuments: [{ date }],
+ schemaFields: { date: 'date' },
});
const wrapper = shallow();
@@ -52,4 +53,17 @@ describe('ExampleResultDetailCard', () => {
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();
+
+ expect(wrapper.find(EuiText).children().text()).toContain(value);
+ });
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.tsx
index 8b0a72ac23e3..734e370e4c53 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.tsx
@@ -12,6 +12,7 @@ import { useValues } from 'kea';
import { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
+import { SchemaType } from '../../../../../shared/schema/types';
import { URL_LABEL } from '../../../../constants';
import { getAsLocalDateTimeString } from '../../../../utils';
@@ -26,6 +27,7 @@ export const ExampleResultDetailCard: React.FC = () => {
titleFieldHover,
urlFieldHover,
exampleDocuments,
+ schemaFields,
} = useValues(DisplaySettingsLogic);
const result = exampleDocuments[0];
@@ -63,7 +65,8 @@ export const ExampleResultDetailCard: React.FC = () => {
{detailFields.length > 0 ? (
detailFields.map(({ fieldName, label }, index) => {
const value = result[fieldName];
- const dateValue = getAsLocalDateTimeString(value);
+ const fieldType = (schemaFields as { [key: string]: SchemaType })[fieldName];
+ const dateValue = fieldType === SchemaType.Date && getAsLocalDateTimeString(value);
return (
{
- const { searchResultConfig, exampleDocuments } = exampleResult;
+ const { searchResultConfig, exampleDocuments, schemaFields } = exampleResult;
const availableFieldOptions = [
{
value: 'foo',
@@ -70,6 +70,7 @@ describe('ResultDetail', () => {
searchResultConfig,
availableFieldOptions,
exampleDocuments,
+ schemaFields,
});
});
@@ -94,6 +95,7 @@ describe('ResultDetail', () => {
},
availableFieldOptions,
exampleDocuments,
+ schemaFields,
});
const wrapper = shallow();
@@ -122,6 +124,7 @@ describe('ResultDetail', () => {
},
availableFieldOptions,
exampleDocuments,
+ schemaFields,
});
const wrapper = mount();