Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enterprise Search] Added Thumbnails to Search UI #104199

Merged
merged 7 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -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}
Copy link
Member

Choose a reason for hiding this comment

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

Just to check, we don't anticipate adding a default value for this the same way we do for title and url right? Might be worth checking with the Crawler folks perhaps to see if they scrape a page thumbnail image?...

Copy link
Member Author

Choose a reason for hiding this comment

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

I can check with them

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add defaulting to a future PR.

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: 1px;
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
}
.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: 'Used to show a thumbnail image' }
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
);
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',
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
None = '',
}