diff --git a/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx b/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx index d2ba5150084b..f64e42dd4015 100644 --- a/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx +++ b/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx @@ -23,7 +23,7 @@ import { UI_SETTINGS } from '../../../../../data/common'; import { LegacyDiscoverTable } from '../default_discover_table/default_discover_table'; import { toolbarVisibility } from './constants'; import { getDataGridTableSetting } from '../utils/local_storage'; -import { SortOrder } from '../default_discover_table/helper'; +import { SortDirection, SortOrder } from '../../../saved_searches/types'; export interface DataGridTableProps { columns: string[]; @@ -74,7 +74,7 @@ export const DataGridTable = ({ services.uiSettings.get(SAMPLE_SIZE_SETTING), services.uiSettings.get(UI_SETTINGS.SHORT_DOTS_ENABLE), services.uiSettings.get(DOC_HIDE_TIME_COLUMN_SETTING), - services.uiSettings.get(SORT_DEFAULT_ORDER_SETTING, 'desc'), + services.uiSettings.get(SORT_DEFAULT_ORDER_SETTING, 'desc') as SortDirection, ]; }, [services.uiSettings]); const pagination = usePagination({ rowCount, pageSizeLimit }); @@ -166,7 +166,7 @@ export const DataGridTable = ({ sort={sort} onSort={onSort} onRemoveColumn={onRemoveColumn} - onReorderColumn={onMoveColumn} + onMoveColumn={onMoveColumn} onAddColumn={onAddColumn} onFilter={onFilter} onClose={() => setInspectedHit(undefined)} diff --git a/src/plugins/discover/public/application/components/default_discover_table/default_discover_table.tsx b/src/plugins/discover/public/application/components/default_discover_table/default_discover_table.tsx index 8c51adbd2a03..fe8092ed8c9c 100644 --- a/src/plugins/discover/public/application/components/default_discover_table/default_discover_table.tsx +++ b/src/plugins/discover/public/application/components/default_discover_table/default_discover_table.tsx @@ -13,8 +13,8 @@ import { DocViewFilterFn, OpenSearchSearchHit } from '../../doc_views/doc_views_ import { TableRow } from './table_rows'; import { IndexPattern } from '../../../opensearch_dashboards_services'; import { Pagination } from './pagination'; -import { SortOrder } from './helper'; import { getLegacyDisplayedColumns } from './helper'; +import { SortDirection, SortOrder } from '../../../saved_searches/types'; export interface DefaultDiscoverTableProps { columns: string[]; @@ -24,14 +24,14 @@ export interface DefaultDiscoverTableProps { sort: SortOrder[]; onSort: (s: SortOrder[]) => void; onRemoveColumn: (column: string) => void; - onReorderColumn: (colName: string, destination: number) => void; + onMoveColumn: (colName: string, destination: number) => void; onAddColumn: (column: string) => void; onFilter: DocViewFilterFn; onClose: () => void; sampleSize: number; isShortDots: boolean; hideTimeColumn: boolean; - defaultSortOrder: string; + defaultSortOrder: SortDirection; showPagination?: boolean; } @@ -43,7 +43,7 @@ export const LegacyDiscoverTable = ({ sort, onSort, onRemoveColumn, - onReorderColumn, + onMoveColumn, onAddColumn, onFilter, onClose, @@ -123,7 +123,7 @@ export const LegacyDiscoverTable = ({ goToPage={goToPage} startItem={currentRowCounts.startRow + 1} endItem={currentRowCounts.endRow} - totalItems={rows.length} + totalItems={hits} sampleSize={sampleSize} /> ) : null} @@ -134,7 +134,7 @@ export const LegacyDiscoverTable = ({ defaultSortOrder={defaultSortOrder} indexPattern={indexPattern} onChangeSortOrder={onSort} - onReorderColumn={onReorderColumn} + onMoveColumn={onMoveColumn} onRemoveColumn={onRemoveColumn} sortOrder={sort} /> diff --git a/src/plugins/discover/public/application/components/default_discover_table/helper.tsx b/src/plugins/discover/public/application/components/default_discover_table/helper.tsx index 71df56fe8383..82ac73acd784 100644 --- a/src/plugins/discover/public/application/components/default_discover_table/helper.tsx +++ b/src/plugins/discover/public/application/components/default_discover_table/helper.tsx @@ -31,7 +31,6 @@ import { IndexPattern } from '../../../opensearch_dashboards_services'; import { shortenDottedString } from '../../helpers'; -export type SortOrder = [string, string]; export interface LegacyDisplayedColumn { name: string; displayName: string; diff --git a/src/plugins/discover/public/application/components/default_discover_table/table_header.tsx b/src/plugins/discover/public/application/components/default_discover_table/table_header.tsx index 75ae73a82434..52ef078387c8 100644 --- a/src/plugins/discover/public/application/components/default_discover_table/table_header.tsx +++ b/src/plugins/discover/public/application/components/default_discover_table/table_header.tsx @@ -14,16 +14,17 @@ import './_table_header.scss'; import React from 'react'; import { IndexPattern } from '../../../opensearch_dashboards_services'; import { TableHeaderColumn } from './table_header_column'; -import { SortOrder, LegacyDisplayedColumn } from './helper'; +import { LegacyDisplayedColumn } from './helper'; import { getDefaultSort } from '../../view_components/utils/get_default_sort'; +import { SortDirection, SortOrder } from '../../../saved_searches/types'; interface Props { displayedColumns: LegacyDisplayedColumn[]; - defaultSortOrder: string; + defaultSortOrder: SortDirection; indexPattern: IndexPattern; onChangeSortOrder?: (sortOrder: SortOrder[]) => void; onRemoveColumn?: (name: string) => void; - onReorderColumn?: (colName: string, destination: number) => void; + onMoveColumn?: (colName: string, destination: number) => void; sortOrder: SortOrder[]; } @@ -32,7 +33,7 @@ export function TableHeader({ defaultSortOrder, indexPattern, onChangeSortOrder, - onReorderColumn, + onMoveColumn, onRemoveColumn, sortOrder, }: Props) { @@ -47,7 +48,7 @@ export function TableHeader({ sortOrder={ sortOrder.length ? sortOrder : getDefaultSort(indexPattern, defaultSortOrder) } - onReorderColumn={onReorderColumn} + onMoveColumn={onMoveColumn} onRemoveColumn={onRemoveColumn} onChangeSortOrder={onChangeSortOrder} /> diff --git a/src/plugins/discover/public/application/components/default_discover_table/table_header_column.tsx b/src/plugins/discover/public/application/components/default_discover_table/table_header_column.tsx index 44eba17f1dfe..9316eb81817e 100644 --- a/src/plugins/discover/public/application/components/default_discover_table/table_header_column.tsx +++ b/src/plugins/discover/public/application/components/default_discover_table/table_header_column.tsx @@ -14,7 +14,7 @@ import './_table_header.scss'; import React, { ReactNode } from 'react'; import { i18n } from '@osd/i18n'; import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; -import { SortOrder } from './helper'; +import { SortOrder } from '../../../saved_searches/types'; interface Props { colLeftIdx: number; // idx of the column to the left, -1 if moving is not possible @@ -24,7 +24,7 @@ interface Props { isSortable?: boolean; name: string; onChangeSortOrder?: (sortOrder: SortOrder[]) => void; - onReorderColumn?: (colName: string, destination: number) => void; + onMoveColumn?: (colName: string, destination: number) => void; onRemoveColumn?: (name: string) => void; sortOrder: SortOrder[]; } @@ -43,7 +43,7 @@ export function TableHeaderColumn({ isSortable, name, onChangeSortOrder, - onReorderColumn, + onMoveColumn, onRemoveColumn, sortOrder, }: Props) { @@ -137,13 +137,13 @@ export function TableHeaderColumn({ }, // Move Left Button { - active: colLeftIdx >= 0 && typeof onReorderColumn === 'function', + active: colLeftIdx >= 0 && typeof onMoveColumn === 'function', ariaLabel: i18n.translate('discover.docTable.tableHeader.moveColumnLeftButtonAriaLabel', { defaultMessage: 'Move {columnName} column to the left', values: { columnName: name }, }), className: 'fa fa-angle-double-left osdDocTableHeader__move', - onClick: () => onReorderColumn && onReorderColumn(name, colLeftIdx), + onClick: () => onMoveColumn && onMoveColumn(name, colLeftIdx), testSubject: `docTableMoveLeftHeader-${name}`, tooltip: i18n.translate('discover.docTable.tableHeader.moveColumnLeftButtonTooltip', { defaultMessage: 'Move column to the left', @@ -152,13 +152,13 @@ export function TableHeaderColumn({ }, // Move Right Button { - active: colRightIdx >= 0 && typeof onReorderColumn === 'function', + active: colRightIdx >= 0 && typeof onMoveColumn === 'function', ariaLabel: i18n.translate('discover.docTable.tableHeader.moveColumnRightButtonAriaLabel', { defaultMessage: 'Move {columnName} column to the right', values: { columnName: name }, }), className: 'fa fa-angle-double-right osdDocTableHeader__move', - onClick: () => onReorderColumn && onReorderColumn(name, colRightIdx), + onClick: () => onMoveColumn && onMoveColumn(name, colRightIdx), testSubject: `docTableMoveRightHeader-${name}`, tooltip: i18n.translate('discover.docTable.tableHeader.moveColumnRightButtonTooltip', { defaultMessage: 'Move column to the right', diff --git a/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx b/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx index e2fee8506e1f..17f9f26e8b54 100644 --- a/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx +++ b/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx @@ -58,15 +58,11 @@ export const DiscoverTable = ({ rows }: Props) => { dispatch(removeColumn(col)); }; - const onReorderColumn = (col: string, source: number, destination: number) => { + const onMoveColumn = (col: string, destination: number) => { if (indexPattern && capabilities.discover?.save) { popularizeField(indexPattern, col, indexPatterns); } - dispatch(reorderColumn({ source: source - 1, destination: destination - 1 })); - }; - - const onMoveColumn = (colName: string, destination: number) => { - dispatch(moveColumn({ columnName: colName, destination })); + dispatch(moveColumn({ columnName: col, destination })); }; const onSetColumns = (cols: string[]) => dispatch(setColumns({ columns: cols })); @@ -112,7 +108,6 @@ export const DiscoverTable = ({ rows }: Props) => { onFilter={onAddFilter as DocViewFilterFn} onMoveColumn={onMoveColumn} onRemoveColumn={onRemoveColumn} - onReorderColumn={onReorderColumn} onSetColumns={onSetColumns} onSort={onSetSort} sort={sort} diff --git a/src/plugins/discover/public/application/view_components/utils/get_sort_for_search_source.ts b/src/plugins/discover/public/application/view_components/utils/get_sort_for_search_source.ts index b19128a432e0..4eba4d833944 100644 --- a/src/plugins/discover/public/application/view_components/utils/get_sort_for_search_source.ts +++ b/src/plugins/discover/public/application/view_components/utils/get_sort_for_search_source.ts @@ -31,8 +31,7 @@ import { OpenSearchQuerySortValue, IndexPattern } from '../../../opensearch_dashboards_services'; import { getSort } from './get_sort'; import { getDefaultSort } from './get_default_sort'; - -export type SortOrder = [string, string]; +import { SortDirection, SortOrder } from '../../../saved_searches/types'; /** * Prepares sort for search source, that's sending the request to OpenSearch @@ -44,7 +43,7 @@ export type SortOrder = [string, string]; export function getSortForSearchSource( sort?: SortOrder[], indexPattern?: IndexPattern, - defaultDirection: string = 'desc' + defaultDirection: SortDirection = 'desc' ): OpenSearchQuerySortValue[] { if (!sort || !indexPattern) { return []; diff --git a/src/plugins/discover/public/embeddable/types.ts b/src/plugins/discover/public/embeddable/types.ts index 24a1aac92b49..855f2d96e47b 100644 --- a/src/plugins/discover/public/embeddable/types.ts +++ b/src/plugins/discover/public/embeddable/types.ts @@ -34,7 +34,7 @@ import { EmbeddableOutput, IEmbeddable, } from 'src/plugins/embeddable/public'; -import { Filter, IIndexPattern, TimeRange, Query } from '../../../../data/public'; +import { Filter, IIndexPattern, TimeRange, Query } from 'src/plugins/data/public'; import { SortOrder } from '../saved_searches/types'; import { SavedSearch } from '../saved_searches'; diff --git a/src/plugins/discover/public/saved_searches/types.ts b/src/plugins/discover/public/saved_searches/types.ts index f67df00a900c..73cb25774c4a 100644 --- a/src/plugins/discover/public/saved_searches/types.ts +++ b/src/plugins/discover/public/saved_searches/types.ts @@ -31,7 +31,8 @@ import { SavedObject } from '../../../saved_objects/public'; import { ISearchSource } from '../../../data/public'; -export type SortOrder = [string, 'asc' | 'desc']; +export type SortDirection = 'asc' | 'desc'; +export type SortOrder = [string, SortDirection]; export interface SavedSearch extends Pick< SavedObject,