From 1bf589b997a308f6b0ef4e9cc5e9c12cd3bf14b1 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Thu, 2 Mar 2023 16:35:19 -0500 Subject: [PATCH] appease typescript --- .../engine_search_preview.tsx | 17 ++---------- .../search_ui_components.tsx | 27 ++++++++++++------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engine/engine_search_preview/engine_search_preview.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engine/engine_search_preview/engine_search_preview.tsx index ce2cdb5f1d794..0d92ce8609807 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engine/engine_search_preview/engine_search_preview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engine/engine_search_preview/engine_search_preview.tsx @@ -47,7 +47,7 @@ import { ResultView, ResultsPerPageView, ResultsView, - SortingView, + Sorting, } from './search_ui_components'; class InternalEngineTransporter implements Transporter { @@ -142,20 +142,7 @@ export const EngineSearchPreview: React.FC = () => { - - {/* */} + = ({ ); -export const SortingView: React.FC = withSearch(({ setSort, sortList }) => ({ - setSort, - sortList: sortList.length === 0 ? [{ direction: '', field: '' }] : sortList, -}))(({ sortableFields, sortList: [{ direction, field }], setSort }) => { +export const Sorting = withSearch< + { sortableFields: string[] }, + Pick +>(({ setSort, sortList }) => ({ setSort, sortList }))(({ sortableFields, sortList, setSort }) => { + const [{ direction, field }] = !sortList?.length ? [{ direction: '', field: '' }] : sortList; const relevance = i18n.translate( 'xpack.enterpriseSearch.content.engine.searchPreivew.sortingView.relevanceLabel', { defaultMessage: 'Relevance' } @@ -254,11 +256,11 @@ export const SortingView: React.FC = withSearch(({ setSort, so singleSelection={{ asPlainText: true }} options={[ { label: relevance, value: '' }, - ...sortableFields.map((f) => ({ label: f, value: f })), + ...sortableFields.map((f: string) => ({ label: f, value: f })), ]} selectedOptions={[{ label: !!field ? field : relevance, value: field }]} onChange={([{ value }]) => - setSort(value === '' ? [] : [{ direction: 'asc', field: value }]) + setSort(value === '' ? [] : [{ direction: 'asc', field: value }], 'asc') } /> @@ -276,18 +278,25 @@ export const SortingView: React.FC = withSearch(({ setSort, so setSort([{ direction: evt.target.value, field }])} + onChange={(evt) => { + switch (evt.target.value) { + case 'asc': + return setSort([{ direction: 'asc', field }], 'asc'); + case 'desc': + return setSort([{ direction: 'desc', field }], 'desc'); + } + }} value={direction} options={[ { - label: i18n.translate( + text: i18n.translate( 'xpack.enterpriseSearch.content.engine.searchPreview.sortingView.ascLabel', { defaultMessage: 'Ascending' } ), value: 'asc', }, { - label: i18n.translate( + text: i18n.translate( 'xpack.enterpriseSearch.content.engine.searchPreview.sortingView.descLabel', { defaultMessage: 'Descending' } ),