Skip to content

Commit

Permalink
[Enterprise Search] Added Thumbnails to Search UI (elastic#104199)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonStoltz authored and kibanamachine committed Jul 14, 2021
1 parent 78ec8c0 commit 9882047
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('SearchUIForm', () => {
onSortFieldsChange: jest.fn(),
onTitleFieldChange: jest.fn(),
onUrlFieldChange: jest.fn(),
onThumbnailFieldChange: jest.fn(),
};

beforeAll(() => {
Expand All @@ -52,6 +53,7 @@ describe('SearchUIForm', () => {
expect(wrapper.find('[data-test-subj="selectFilters"]').exists()).toBe(true);
expect(wrapper.find('[data-test-subj="selectSort"]').exists()).toBe(true);
expect(wrapper.find('[data-test-subj="selectUrl"]').exists()).toBe(true);
expect(wrapper.find('[data-test-subj="selectThumbnail"]').exists()).toBe(true);
});

describe('title field', () => {
Expand Down Expand Up @@ -112,6 +114,35 @@ describe('SearchUIForm', () => {
});
});

describe('thumbnail field', () => {
beforeEach(() => jest.clearAllMocks());
const subject = () => shallow(<SearchUIForm />).find('[data-test-subj="selectThumbnail"]');

it('renders with its value set from state', () => {
setMockValues({
...values,
thumbnailField: 'foo',
});

expect(subject().prop('value')).toBe('foo');
});

it('updates state with new value when changed', () => {
subject().simulate('change', { target: { value: 'foo' } });
expect(actions.onThumbnailFieldChange).toHaveBeenCalledWith('foo');
});

it('updates active field in state on focus', () => {
subject().simulate('focus');
expect(actions.onActiveFieldChange).toHaveBeenCalledWith(ActiveField.Thumb);
});

it('removes active field in state on blur', () => {
subject().simulate('blur');
expect(actions.onActiveFieldChange).toHaveBeenCalledWith(ActiveField.None);
});
});

describe('filters field', () => {
beforeEach(() => jest.clearAllMocks());
const subject = () => shallow(<SearchUIForm />).find('[data-test-subj="selectFilters"]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
URL_FIELD_LABEL,
URL_FIELD_HELP_TEXT,
GENERATE_PREVIEW_BUTTON_LABEL,
THUMBNAIL_FIELD_LABEL,
THUMBNAIL_FIELD_HELP_TEXT,
} from '../i18n';
import { SearchUILogic } from '../search_ui_logic';
import { ActiveField } from '../types';
Expand All @@ -36,6 +38,7 @@ export const SearchUIForm: React.FC = () => {
validFacetFields,
titleField,
urlField,
thumbnailField,
facetFields,
sortFields,
} = useValues(SearchUILogic);
Expand All @@ -45,11 +48,13 @@ export const SearchUIForm: React.FC = () => {
onSortFieldsChange,
onTitleFieldChange,
onUrlFieldChange,
onThumbnailFieldChange,
} = useActions(SearchUILogic);

const previewHref = generatePreviewUrl({
titleField,
urlField,
thumbnailField,
facets: facetFields,
sortFields,
});
Expand All @@ -69,6 +74,7 @@ export const SearchUIForm: React.FC = () => {
const facetOptionFields = formatMultiOptions(validFacetFields);
const selectedTitleOption = formatSelectOption(titleField);
const selectedURLOption = formatSelectOption(urlField);
const selectedThumbnailOption = formatSelectOption(thumbnailField);
const selectedSortOptions = formatMultiOptions(sortFields);
const selectedFacetOptions = formatMultiOptions(facetFields);

Expand Down Expand Up @@ -112,7 +118,6 @@ export const SearchUIForm: React.FC = () => {
data-test-subj="selectSort"
/>
</EuiFormRow>

<EuiFormRow label={URL_FIELD_LABEL} helpText={URL_FIELD_HELP_TEXT} fullWidth>
<EuiSelect
disabled={dataLoading}
Expand All @@ -126,6 +131,19 @@ export const SearchUIForm: React.FC = () => {
data-test-subj="selectUrl"
/>
</EuiFormRow>
<EuiFormRow label={THUMBNAIL_FIELD_LABEL} helpText={THUMBNAIL_FIELD_HELP_TEXT} fullWidth>
<EuiSelect
disabled={dataLoading}
options={optionFields}
value={selectedThumbnailOption && selectedThumbnailOption.value}
onChange={(e) => onThumbnailFieldChange(e.target.value)}
fullWidth
onFocus={() => onActiveFieldChange(ActiveField.Thumb)}
onBlur={() => onActiveFieldChange(ActiveField.None)}
hasNoInitialSelection
data-test-subj="selectThumbnail"
/>
</EuiFormRow>
<EuiButton
disabled={dataLoading}
type="submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,27 @@
}
}
}
&.activeThumb {
#results {
.outerBox {
fill: $euiColorEmptyShade;
stroke: $euiColorPrimary;
stroke-width: $euiBorderWidthThin;
}
.url {
fill: $euiColorPrimary;
opacity: .1;
}
.titleBox {
fill: $euiColorEmptyShade;
}
.titleCopy {
fill: $euiColorPrimary;
opacity: .1;
}
.shoe {
fill: $euiColorPrimary;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ export const URL_FIELD_LABEL = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.searchUI.urlFieldLabel',
{ defaultMessage: 'URL field (Optional)' }
);
export const THUMBNAIL_FIELD_LABEL = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.searchUI.thumbnailFieldLabel',
{ defaultMessage: 'Thumbnail field (Optional)' }
);
export const URL_FIELD_HELP_TEXT = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.searchUI.urlFieldHelpText',
{ defaultMessage: "Used as a result's link target, if applicable" }
);
export const THUMBNAIL_FIELD_HELP_TEXT = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.searchUI.thumbnailFieldHelpText',
{ defaultMessage: 'Provide an image URL to show a thumbnail image' }
);
export const GENERATE_PREVIEW_BUTTON_LABEL = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.searchUI.generatePreviewButtonLabel',
{ defaultMessage: 'Generate search experience' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('SearchUILogic', () => {
validFacetFields: [],
titleField: '',
urlField: '',
thumbnailField: '',
facetFields: [],
sortFields: [],
activeField: ActiveField.None,
Expand Down Expand Up @@ -93,6 +94,17 @@ describe('SearchUILogic', () => {
});
});

describe('onThumbnailFieldChange', () => {
it('sets the thumbnailField value', () => {
mount({ thumbnailField: '' });
SearchUILogic.actions.onThumbnailFieldChange('foo');
expect(SearchUILogic.values).toEqual({
...DEFAULT_VALUES,
thumbnailField: 'foo',
});
});
});

describe('onFacetFieldsChange', () => {
it('sets the facetFields value', () => {
mount({ facetFields: [] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface InitialFieldValues {
validSortFields: string[];
validFacetFields: string[];
urlField?: string;
thumbnailField?: string;
titleField?: string;
}
interface SearchUIActions {
Expand All @@ -30,6 +31,7 @@ interface SearchUIActions {
onSortFieldsChange(sortFields: string[]): { sortFields: string[] };
onTitleFieldChange(titleField: string): { titleField: string };
onUrlFieldChange(urlField: string): { urlField: string };
onThumbnailFieldChange(thumbnailField: string): { thumbnailField: string };
}

interface SearchUIValues {
Expand All @@ -39,6 +41,7 @@ interface SearchUIValues {
validFacetFields: string[];
titleField: string;
urlField: string;
thumbnailField: string;
facetFields: string[];
sortFields: string[];
activeField: ActiveField;
Expand All @@ -54,6 +57,7 @@ export const SearchUILogic = kea<MakeLogicType<SearchUIValues, SearchUIActions>>
onSortFieldsChange: (sortFields) => ({ sortFields }),
onTitleFieldChange: (titleField) => ({ titleField }),
onUrlFieldChange: (urlField) => ({ urlField }),
onThumbnailFieldChange: (thumbnailField) => ({ thumbnailField }),
}),
reducers: () => ({
dataLoading: [
Expand All @@ -79,6 +83,12 @@ export const SearchUILogic = kea<MakeLogicType<SearchUIValues, SearchUIActions>>
onFieldDataLoaded: (_, { urlField }) => urlField || '',
},
],
thumbnailField: [
'',
{
onThumbnailFieldChange: (_, { thumbnailField }) => thumbnailField,
},
],
facetFields: [[], { onFacetFieldsChange: (_, { facetFields }) => facetFields }],
sortFields: [[], { onSortFieldsChange: (_, { sortFields }) => sortFields }],
activeField: [ActiveField.None, { onActiveFieldChange: (_, { activeField }) => activeField }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export enum ActiveField {
Filter = 'Filter',
Sort = 'Sort',
Url = 'Url',
Thumb = 'Thumb',
None = '',
}

0 comments on commit 9882047

Please sign in to comment.