-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-11159. Improve Containers page UI #7267
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
259 changes: 259 additions & 0 deletions
259
...main/resources/webapps/recon/ozone-recon-web/src/v2/components/tables/containersTable.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,259 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import React, { useRef } from 'react'; | ||
| import filesize from 'filesize'; | ||
| import { AxiosError } from 'axios'; | ||
| import { Popover, Table } from 'antd'; | ||
| import { | ||
| ColumnsType, | ||
| TablePaginationConfig | ||
| } from 'antd/es/table'; | ||
| import { NodeIndexOutlined } from '@ant-design/icons'; | ||
|
|
||
| import { getFormattedTime } from '@/v2/utils/momentUtils'; | ||
| import { showDataFetchError } from '@/utils/common'; | ||
| import { AxiosGetHelper } from '@/utils/axiosRequestHelper'; | ||
| import { | ||
| Container, ContainerKeysResponse, ContainerReplica, | ||
| ContainerTableProps, | ||
| ExpandedRowState, KeyResponse | ||
| } from '@/v2/types/container.types'; | ||
|
|
||
| const size = filesize.partial({ standard: 'iec' }); | ||
|
|
||
| export const COLUMNS: ColumnsType<Container> = [ | ||
| { | ||
| title: 'Container ID', | ||
| dataIndex: 'containerID', | ||
| key: 'containerID', | ||
| sorter: (a: Container, b: Container) => a.containerID - b.containerID | ||
| }, | ||
| { | ||
| title: 'No. of Keys', | ||
| dataIndex: 'keys', | ||
| key: 'keys', | ||
| sorter: (a: Container, b: Container) => a.keys - b.keys | ||
| }, | ||
devabhishekpal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| title: 'Actual/Expected Replica(s)', | ||
| dataIndex: 'expectedReplicaCount', | ||
| key: 'expectedReplicaCount', | ||
| render: (expectedReplicaCount: number, record: Container) => { | ||
| const actualReplicaCount = record.actualReplicaCount; | ||
| return ( | ||
| <span> | ||
| {actualReplicaCount} / {expectedReplicaCount} | ||
| </span> | ||
| ); | ||
| } | ||
| }, | ||
| { | ||
| title: 'Datanodes', | ||
| dataIndex: 'replicas', | ||
| key: 'replicas', | ||
| render: (replicas: ContainerReplica[]) => { | ||
| const renderDatanodes = (replicas: ContainerReplica[]) => { | ||
| return replicas?.map((replica: any, idx: number) => ( | ||
| <div key={idx} className='datanode-container-v2'> | ||
| <NodeIndexOutlined /> {replica.datanodeHost} | ||
| </div> | ||
| )) | ||
| } | ||
|
|
||
| return ( | ||
| <Popover | ||
| content={renderDatanodes(replicas)} | ||
| title='Datanodes' | ||
| placement='bottomRight' | ||
| trigger='hover'> | ||
| <strong>{replicas.length}</strong> datanodes | ||
| </Popover> | ||
| ) | ||
| } | ||
| }, | ||
| { | ||
| title: 'Pipeline ID', | ||
| dataIndex: 'pipelineID', | ||
| key: 'pipelineID' | ||
| }, | ||
| { | ||
| title: 'Unhealthy Since', | ||
| dataIndex: 'unhealthySince', | ||
| key: 'unhealthySince', | ||
| render: (unhealthySince: number) => getFormattedTime(unhealthySince, 'lll'), | ||
| sorter: (a: Container, b: Container) => a.unhealthySince - b.unhealthySince | ||
| } | ||
| ]; | ||
|
|
||
| const KEY_TABLE_COLUMNS: ColumnsType<KeyResponse> = [ | ||
| { | ||
| title: 'Volume', | ||
| dataIndex: 'Volume', | ||
| key: 'Volume' | ||
| }, | ||
| { | ||
| title: 'Bucket', | ||
| dataIndex: 'Bucket', | ||
| key: 'Bucket' | ||
| }, | ||
| { | ||
| title: 'Key', | ||
devabhishekpal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dataIndex: 'Key', | ||
| key: 'Key' | ||
| }, | ||
| { | ||
| title: 'Size', | ||
| dataIndex: 'DataSize', | ||
| key: 'DataSize', | ||
| render: (dataSize: number) => <div>{size(dataSize)}</div> | ||
| }, | ||
| { | ||
| title: 'Date Created', | ||
| dataIndex: 'CreationTime', | ||
| key: 'CreationTime', | ||
| render: (date: string) => getFormattedTime(date, 'lll') | ||
| }, | ||
| { | ||
| title: 'Date Modified', | ||
| dataIndex: 'ModificationTime', | ||
| key: 'ModificationTime', | ||
| render: (date: string) => getFormattedTime(date, 'lll') | ||
| }, | ||
| { | ||
| title: 'Path', | ||
| dataIndex: 'CompletePath', | ||
| key: 'path' | ||
| } | ||
| ]; | ||
|
|
||
| const ContainerTable: React.FC<ContainerTableProps> = ({ | ||
| data, | ||
| loading, | ||
| selectedColumns, | ||
| expandedRow, | ||
| expandedRowSetter, | ||
| searchColumn = 'containerID', | ||
| searchTerm = '' | ||
| }) => { | ||
|
|
||
| const cancelSignal = useRef<AbortController>(); | ||
|
|
||
| function filterSelectedColumns() { | ||
| const columnKeys = selectedColumns.map((column) => column.value); | ||
| return COLUMNS.filter( | ||
| (column) => columnKeys.indexOf(column.key as string) >= 0 | ||
| ); | ||
| } | ||
|
|
||
| function loadRowData(containerID: number) { | ||
| const { request, controller } = AxiosGetHelper( | ||
| `/api/v1/containers/${containerID}/keys`, | ||
ArafatKhan2198 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cancelSignal.current | ||
| ); | ||
| cancelSignal.current = controller; | ||
|
|
||
| request.then(response => { | ||
| const containerKeysResponse: ContainerKeysResponse = response.data; | ||
| expandedRowSetter({ | ||
| ...expandedRow, | ||
| [containerID]: { | ||
| ...expandedRow[containerID], | ||
| loading: false, | ||
| dataSource: containerKeysResponse.keys, | ||
| totalCount: containerKeysResponse.totalCount | ||
| } | ||
| }); | ||
| }).catch(error => { | ||
| expandedRowSetter({ | ||
| ...expandedRow, | ||
| [containerID]: { | ||
| ...expandedRow[containerID], | ||
| loading: false | ||
| } | ||
| }); | ||
| showDataFetchError((error as AxiosError).toString()); | ||
| }); | ||
| } | ||
|
|
||
| function getFilteredData(data: Container[]) { | ||
|
|
||
| return data?.filter( | ||
| (container: Container) => { | ||
| return (searchColumn === 'containerID') | ||
| ? container[searchColumn].toString().includes(searchTerm) | ||
| : container[searchColumn].includes(searchTerm) | ||
| } | ||
| ) ?? []; | ||
| } | ||
|
|
||
| function onRowExpandClick(expanded: boolean, record: Container) { | ||
| if (expanded) { | ||
| loadRowData(record.containerID); | ||
| } | ||
| else { | ||
| cancelSignal.current && cancelSignal.current.abort(); | ||
| } | ||
| } | ||
|
|
||
| function expandedRowRender(record: Container) { | ||
| const containerId = record.containerID | ||
| const containerKeys: ExpandedRowState = expandedRow[containerId]; | ||
| const dataSource = containerKeys?.dataSource ?? []; | ||
| const paginationConfig: TablePaginationConfig = { | ||
| showTotal: (total: number, range) => `${range[0]}-${range[1]} of ${total} Keys` | ||
| } | ||
|
|
||
| return ( | ||
| <Table | ||
| loading={containerKeys?.loading ?? true} | ||
| dataSource={dataSource} | ||
| columns={KEY_TABLE_COLUMNS} | ||
| pagination={paginationConfig} | ||
| rowKey={(record: KeyResponse) => `${record.Volume}/${record.Bucket}/${record.Key}`} | ||
| locale={{ filterTitle: '' }} /> | ||
| ) | ||
| }; | ||
|
|
||
| const paginationConfig: TablePaginationConfig = { | ||
| showTotal: (total: number, range) => ( | ||
| `${range[0]}-${range[1]} of ${total} Containers` | ||
| ), | ||
| showSizeChanger: true | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <Table | ||
| rowKey='containerID' | ||
| dataSource={getFilteredData(data)} | ||
| columns={filterSelectedColumns()} | ||
| loading={loading} | ||
| pagination={paginationConfig} | ||
| scroll={{ x: 'max-content', scrollToFirstRowOnChange: true }} | ||
| locale={{ filterTitle: '' }} | ||
| expandable={{ | ||
| expandRowByClick: true, | ||
| expandedRowRender: expandedRowRender, | ||
| onExpand: onRowExpandClick | ||
| }} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default ContainerTable; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.