-
Notifications
You must be signed in to change notification settings - Fork 88
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
[Enhancement] #848 increase column width and page size #934
base: main
Are you sure you want to change the base?
Changes from all commits
f419eba
b262a01
e84dd3f
05ce5c0
c2763be
65a68ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,5 +72,8 @@ | |
}, | ||
"engines": { | ||
"yarn": "^1.21.1" | ||
}, | ||
"dependencies": { | ||
"@opensearch-project/oui": "^1.4.0" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,23 +8,26 @@ 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, | ||||||
EuiTableSelectionType, | ||||||
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"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You are using wrong component here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IndexDetail inside IndexDetail page is a super heavy component and should not be rendered inside a cell of data grid. |
||||||
|
||||||
interface IndicesProps extends RouteComponentProps { | ||||||
indexService: IndexService; | ||||||
|
@@ -60,6 +64,7 @@ interface IndicesState { | |||||
|
||||||
export default class Indices extends Component<IndicesProps, IndicesState> { | ||||||
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<IndicesProps, IndicesState> { | |||||
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<IndicesProps, IndicesState> { | |||||
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<ManagedCatIndex> = { | ||||||
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<ManagedCatIndex> = { | ||||||
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 <IndexDetail {...this.props} index={rowData.index} />; | ||||||
Comment on lines
+252
to
+253
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loading this IndexDetail component is the cause of endless call. @kohinoor98 can you reach out to @SuZhou-Joe the writter for some guidance here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, will do. Thanks @bowenlan-amzn |
||||||
|
||||||
case "health": | ||||||
const color = rowData.health ? HEALTH_TO_COLOR[rowData.health] : "subdued"; | ||||||
return ( | ||||||
<EuiHealth color={color} className="indices-health"> | ||||||
{rowData.health || rowData.status} | ||||||
</EuiHealth> | ||||||
); | ||||||
|
||||||
case "data_stream": | ||||||
return rowData.data_stream ? ( | ||||||
<EuiLink href={`#${ROUTES.CREATE_DATA_STREAM}/${rowData.data_stream}`}>{rowData.data_stream}</EuiLink> | ||||||
) : ( | ||||||
"-" | ||||||
); | ||||||
|
||||||
case "managed": | ||||||
return renderNumber(rowData.managed); | ||||||
|
||||||
case "status": | ||||||
return <span className="camel-first-letter">{rowData.extraStatus || rowData.status}</span>; | ||||||
|
||||||
case "store.size": | ||||||
return renderNumber(rowData["store.size"]); | ||||||
|
||||||
case "pri.store.size": | ||||||
return renderNumber(rowData["pri.store.size"]); | ||||||
|
||||||
case "docs.count": | ||||||
return <span title={rowData["docs.count"].toString()}>{rowData["docs.count"] || "-"}</span>; | ||||||
|
||||||
case "docs.deleted": | ||||||
return <span title={rowData["docs.deleted"].toString()}>{rowData["docs.deleted"] || "-"}</span>; | ||||||
|
||||||
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 ( | ||||||
<ContentPanel | ||||||
|
@@ -283,18 +352,14 @@ export default class Indices extends Component<IndicesProps, IndicesState> { | |||||
|
||||||
<EuiHorizontalRule margin="xs" /> | ||||||
|
||||||
<EuiBasicTable | ||||||
columns={indicesColumns(isDataStreamColumnVisible, { | ||||||
history, | ||||||
})} | ||||||
loading={this.state.loadingIndices} | ||||||
isSelectable={true} | ||||||
itemId="index" | ||||||
items={indices} | ||||||
noItemsMessage={<IndexEmptyPrompt filterIsApplied={filterIsApplied} loading={loadingIndices} resetFilters={this.resetFilters} />} | ||||||
onChange={this.onTableChange} | ||||||
<OuiDataGrid | ||||||
aria-labelledby={gridLabelId} | ||||||
columns={columns} | ||||||
columnVisibility={{ visibleColumns: columns.map((column) => column.id), setVisibleColumns: () => {} }} | ||||||
rowCount={totalIndices} | ||||||
inMemory={{ level: "sorting" }} | ||||||
renderCellValue={renderCellValue} | ||||||
pagination={pagination} | ||||||
selection={selection} | ||||||
sorting={sorting} | ||||||
/> | ||||||
</ContentPanel> | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The theme and its css should already be imported in OSD core, I do not think we should explicitly import theme.css in a plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup @SuZhou-Joe. I got rid of
OUI
(faced issues with the library and documentation) entirely and switched toEuiDataGrid
.I am still working on the pagination part for the table. I will push the latest code with screenshots as I get some time to test for edge cases.
Thanks,
KC