Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
  • Loading branch information
ashwin-pc authored Feb 5, 2024
1 parent e2f48a2 commit 9781ac9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -166,7 +166,7 @@ export const DataGridTable = ({
sort={sort}
onSort={onSort}
onRemoveColumn={onRemoveColumn}
onReorderColumn={onMoveColumn}
onMoveColumn={onMoveColumn}
onAddColumn={onAddColumn}
onFilter={onFilter}
onClose={() => setInspectedHit(undefined)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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;
}

Expand All @@ -43,7 +43,7 @@ export const LegacyDiscoverTable = ({
sort,
onSort,
onRemoveColumn,
onReorderColumn,
onMoveColumn,
onAddColumn,
onFilter,
onClose,
Expand Down Expand Up @@ -123,7 +123,7 @@ export const LegacyDiscoverTable = ({
goToPage={goToPage}
startItem={currentRowCounts.startRow + 1}
endItem={currentRowCounts.endRow}
totalItems={rows.length}
totalItems={hits}
sampleSize={sampleSize}
/>
) : null}
Expand All @@ -134,7 +134,7 @@ export const LegacyDiscoverTable = ({
defaultSortOrder={defaultSortOrder}
indexPattern={indexPattern}
onChangeSortOrder={onSort}
onReorderColumn={onReorderColumn}
onMoveColumn={onMoveColumn}
onRemoveColumn={onRemoveColumn}
sortOrder={sort}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}

Expand All @@ -32,7 +33,7 @@ export function TableHeader({
defaultSortOrder,
indexPattern,
onChangeSortOrder,
onReorderColumn,
onMoveColumn,
onRemoveColumn,
sortOrder,
}: Props) {
Expand All @@ -47,7 +48,7 @@ export function TableHeader({
sortOrder={
sortOrder.length ? sortOrder : getDefaultSort(indexPattern, defaultSortOrder)
}
onReorderColumn={onReorderColumn}
onMoveColumn={onMoveColumn}
onRemoveColumn={onRemoveColumn}
onChangeSortOrder={onChangeSortOrder}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[];
}
Expand All @@ -43,7 +43,7 @@ export function TableHeaderColumn({
isSortable,
name,
onChangeSortOrder,
onReorderColumn,
onMoveColumn,
onRemoveColumn,
sortOrder,
}: Props) {
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 [];
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/discover/public/embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/discover/public/saved_searches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9781ac9

Please sign in to comment.