diff --git a/package.json b/package.json index 7c079c666..94e53eada 100644 --- a/package.json +++ b/package.json @@ -72,5 +72,8 @@ }, "engines": { "yarn": "^1.21.1" + }, + "dependencies": { + "@opensearch-project/oui": "^1.4.0" } -} \ No newline at end of file +} diff --git a/public/index.ts b/public/index.ts index 058e4d57b..2167bfb7d 100644 --- a/public/index.ts +++ b/public/index.ts @@ -6,6 +6,7 @@ import { PluginInitializerContext } from "opensearch-dashboards/public"; import { IndexManagementPlugin } from "./plugin"; import { Action, UIAction } from "../models/interfaces"; +import "@opensearch-project/oui/dist/oui_theme_light.css"; // export for other plugins to register action export { Action, UIAction } from "../models/interfaces"; diff --git a/public/pages/Indices/containers/Indices/Indices.tsx b/public/pages/Indices/containers/Indices/Indices.tsx index 95adba12e..091672e26 100644 --- a/public/pages/Indices/containers/Indices/Indices.tsx +++ b/public/pages/Indices/containers/Indices/Indices.tsx @@ -8,11 +8,9 @@ import _ from "lodash"; import { RouteComponentProps } from "react-router-dom"; import queryString from "query-string"; import { - EuiBasicTable, EuiHorizontalRule, // @ts-ignore Criteria, - EuiTableSortingType, Direction, // @ts-ignore Pagination, @@ -20,11 +18,16 @@ import { ArgsWithError, ArgsWithQuery, Query, + EuiHealth, + EuiLink, } from "@elastic/eui"; + +import { OuiDataGrid, OuiDataGridPaginationProps, OuiDataGridSorting, OuiText, OuiTitle } from "@opensearch-project/oui"; + import { ContentPanel, ContentPanelActions } from "../../../../components/ContentPanel"; import IndexControls from "../../components/IndexControls"; import IndexEmptyPrompt from "../../components/IndexEmptyPrompt"; -import { DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_QUERY_PARAMS, indicesColumns } from "../../utils/constants"; +import { DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_QUERY_PARAMS, HEALTH_TO_COLOR, indicesColumns, renderNumber } from "../../utils/constants"; import IndexService from "../../../../services/IndexService"; import CommonService from "../../../../services/CommonService"; import { DataStream, ManagedCatIndex } from "../../../../../server/models/interfaces"; @@ -37,6 +40,7 @@ import { SECURITY_EXCEPTION_PREFIX } from "../../../../../server/utils/constants import IndicesActions from "../IndicesActions"; import { destroyListener, EVENT_MAP, listenEvent } from "../../../../JobHandler"; import "./index.scss"; +import IndexDetail from "../../../IndexDetail/containers/IndexDetail"; interface IndicesProps extends RouteComponentProps { indexService: IndexService; @@ -60,6 +64,7 @@ interface IndicesState { export default class Indices extends Component { static contextType = CoreServicesContext; + constructor(props: IndicesProps) { super(props); const { from, size, search, sortField, sortDirection, showDataStreams } = getURLQueryParams(this.props.location); @@ -194,6 +199,16 @@ export default class Indices extends Component { this.setState({ search: DEFAULT_QUERY_PARAMS.search, query: Query.parse(DEFAULT_QUERY_PARAMS.search) }); }; + onSort = (sortingColumns: string | any[]) => { + const sort = sortingColumns.length > 0 ? sortingColumns[0] : undefined; + if (sort) { + this.setState({ + sortField: sort.id, + sortDirection: sort.direction, + }); + } + }; + render() { const { totalIndices, @@ -211,25 +226,79 @@ export default class Indices extends Component { const filterIsApplied = !!search; const page = Math.floor(from / size); - const pagination: Pagination = { + const pagination: OuiDataGridPaginationProps = { pageIndex: page, pageSize: size, pageSizeOptions: DEFAULT_PAGE_SIZE_OPTIONS, - totalItemCount: totalIndices, + onChangeItemsPerPage: (newSize) => this.setState({ size: newSize }), + onChangePage: (newPage) => this.setState({ from: newPage * size }), }; - const sorting: EuiTableSortingType = { - sort: { - direction: sortDirection, - field: sortField, - }, + const sorting: OuiDataGridSorting = { + onSort: this.onSort, + columns: this.state.sortField ? [{ id: this.state.sortField, direction: this.state.sortDirection }] : [], }; const selection: EuiTableSelectionType = { onSelectionChange: this.onSelectionChange, }; - const { history } = this.props; + const renderCellValue = ({ rowIndex, columnId }) => { + const rowData = this.state.indices[rowIndex]; + + console.log(rowData); + + switch (columnId) { + case "index": + return ; + + case "health": + const color = rowData.health ? HEALTH_TO_COLOR[rowData.health] : "subdued"; + return ( + + {rowData.health || rowData.status} + + ); + + case "data_stream": + return rowData.data_stream ? ( + {rowData.data_stream} + ) : ( + "-" + ); + + case "managed": + return renderNumber(rowData.managed); + + case "status": + return {rowData.extraStatus || rowData.status}; + + case "store.size": + return renderNumber(rowData["store.size"]); + + case "pri.store.size": + return renderNumber(rowData["pri.store.size"]); + + case "docs.count": + return {rowData["docs.count"] || "-"}; + + case "docs.deleted": + return {rowData["docs.deleted"] || "-"}; + + case "pri": + return rowData.pri.toString(); + + case "rep": + return rowData.rep.toString(); + + default: + return rowData[columnId] ?? "-"; + } + }; + + const columns = indicesColumns(isDataStreamColumnVisible, { history: this.props.history }); + + const gridLabelId = "tableIndexMangementPlugin"; return ( { - } - onChange={this.onTableChange} + column.id), setVisibleColumns: () => {} }} + rowCount={totalIndices} + inMemory={{ level: "sorting" }} + renderCellValue={renderCellValue} pagination={pagination} - selection={selection} sorting={sorting} /> diff --git a/public/pages/Indices/containers/Indices/__snapshots__/Indices.test.tsx.snap b/public/pages/Indices/containers/Indices/__snapshots__/Indices.test.tsx.snap index 6eba9f596..eb114a055 100644 --- a/public/pages/Indices/containers/Indices/__snapshots__/Indices.test.tsx.snap +++ b/public/pages/Indices/containers/Indices/__snapshots__/Indices.test.tsx.snap @@ -303,7 +303,7 @@ exports[` spec renders the component 1`] = ` data-test-subj="tableHeaderCell_index_0" role="columnheader" scope="col" - style="width: 250px;" + style="width: 320px;" >