-
Notifications
You must be signed in to change notification settings - Fork 420
RI-7786: fix ClusterNodesTable #5265
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
5 commits
Select commit
Hold shift + click to select a range
edc52c6
RI-7786: fix ClusterNodesTable
KrumTy 4dd1331
RI-7786: simplify isMaxColumnFieldValue
KrumTy f783f60
RI-7786: show loading state only during initial load or missing data
KrumTy a3d13bf
RI-7786: remove leftover styles
KrumTy 0da6f0a
RI-7786: update styled divs
KrumTy 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
51 changes: 51 additions & 0 deletions
51
redisinsight/ui/src/mocks/factories/cluster/ClusterNodeDetails.factory.ts
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,51 @@ | ||
| import { Factory } from 'fishery' | ||
| import { faker } from '@faker-js/faker' | ||
| import { ClusterNodeDetails } from 'src/modules/cluster-monitor/models' | ||
|
|
||
| enum NodeRole { | ||
| Primary = 'primary', | ||
| Replica = 'replica', | ||
| } | ||
|
|
||
| enum HealthStatus { | ||
| Online = 'online', | ||
| Offline = 'offline', | ||
| Loading = 'loading', | ||
| } | ||
|
|
||
| export const ClusterNodeDetailsFactory = Factory.define<ClusterNodeDetails>( | ||
| () => ({ | ||
| id: faker.string.uuid(), | ||
| version: faker.system.semver(), | ||
| mode: faker.helpers.arrayElement(['standalone', 'cluster', 'sentinel']), | ||
| host: faker.internet.ip(), | ||
| port: faker.internet.port(), | ||
| role: faker.helpers.arrayElement([NodeRole.Primary, NodeRole.Replica]), | ||
| health: faker.helpers.arrayElement([ | ||
| HealthStatus.Online, | ||
| HealthStatus.Offline, | ||
| HealthStatus.Loading, | ||
| ]), | ||
| slots: ['0-5460'], | ||
| totalKeys: faker.number.int({ min: 0, max: 1000000 }), | ||
| usedMemory: faker.number.int({ min: 1000000, max: 100000000 }), | ||
| opsPerSecond: faker.number.int({ min: 0, max: 10000 }), | ||
| connectionsReceived: faker.number.int({ min: 0, max: 10000 }), | ||
| connectedClients: faker.number.int({ min: 0, max: 100 }), | ||
| commandsProcessed: faker.number.int({ min: 0, max: 1000000000 }), | ||
| networkInKbps: faker.number.float({ | ||
| min: 0, | ||
| max: 10000, | ||
| fractionDigits: 2, | ||
| }), | ||
| networkOutKbps: faker.number.float({ | ||
| min: 0, | ||
| max: 10000, | ||
| fractionDigits: 2, | ||
| }), | ||
| cacheHitRatio: faker.number.float({ min: 0, max: 1, fractionDigits: 2 }), | ||
| replicationOffset: faker.number.int({ min: 0, max: 1000000 }), | ||
| uptimeSec: faker.number.int({ min: 0, max: 10000000 }), | ||
| replicas: [], | ||
| }), | ||
| ) |
8 changes: 8 additions & 0 deletions
8
redisinsight/ui/src/pages/cluster-details/ClusterDetailsPage.styles.ts
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,8 @@ | ||
| import styled from 'styled-components' | ||
|
|
||
| export const ClusterDetailsPageWrapper = styled.div< | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >` | ||
| height: 100%; | ||
| padding: 0 1.6rem; | ||
| ` |
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
66 changes: 66 additions & 0 deletions
66
.../ui/src/pages/cluster-details/components/ClusterNodesTable/ClusterNodesTable.constants.ts
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,66 @@ | ||
| import { ColumnDef, SortingState } from 'uiSrc/components/base/layout/table' | ||
|
|
||
| import { ModifiedClusterNodes } from '../../ClusterDetailsPage' | ||
| import { ClusterNodesHostCell } from './components/ClusterNodesHostCell/ClusterNodesHostCell' | ||
| import { ClusterNodesNumericCell } from './components/ClusterNodesNumericCell/ClusterNodesNumericCell' | ||
|
|
||
| export const DEFAULT_SORTING: SortingState = [ | ||
| { | ||
| id: 'host', | ||
| desc: false, | ||
| }, | ||
| ] | ||
|
|
||
| export const DEFAULT_CLUSTER_NODES_COLUMNS: ColumnDef<ModifiedClusterNodes>[] = | ||
| [ | ||
| { | ||
| header: ({ table }) => `${table.options.data.length} Primary nodes`, | ||
| isHeaderCustom: true, | ||
| id: 'host', | ||
| accessorKey: 'host', | ||
| enableSorting: true, | ||
| cell: ClusterNodesHostCell, | ||
| }, | ||
| { | ||
| header: 'Commands/s', | ||
| id: 'opsPerSecond', | ||
| accessorKey: 'opsPerSecond', | ||
| enableSorting: true, | ||
| cell: ClusterNodesNumericCell, | ||
| }, | ||
| { | ||
| header: 'Network Input', | ||
| id: 'networkInKbps', | ||
| accessorKey: 'networkInKbps', | ||
| enableSorting: true, | ||
| cell: ClusterNodesNumericCell, | ||
| }, | ||
| { | ||
| header: 'Network Output', | ||
| id: 'networkOutKbps', | ||
| accessorKey: 'networkOutKbps', | ||
| enableSorting: true, | ||
| cell: ClusterNodesNumericCell, | ||
| }, | ||
| { | ||
| header: 'Total Memory', | ||
| id: 'usedMemory', | ||
| accessorKey: 'usedMemory', | ||
| enableSorting: true, | ||
| cell: ClusterNodesNumericCell, | ||
| }, | ||
| { | ||
| header: 'Total Keys', | ||
| id: 'totalKeys', | ||
| accessorKey: 'totalKeys', | ||
| enableSorting: true, | ||
| cell: ClusterNodesNumericCell, | ||
| }, | ||
| { | ||
| header: 'Clients', | ||
| id: 'connectedClients', | ||
| accessorKey: 'connectedClients', | ||
| enableSorting: true, | ||
| cell: ClusterNodesNumericCell, | ||
| }, | ||
| ] |
75 changes: 75 additions & 0 deletions
75
...ight/ui/src/pages/cluster-details/components/ClusterNodesTable/ClusterNodesTable.spec.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,75 @@ | ||
| import React from 'react' | ||
| import { getLetterByIndex } from 'uiSrc/utils' | ||
| import { rgb } from 'uiSrc/utils/colors' | ||
| import { render, screen } from 'uiSrc/utils/test-utils' | ||
|
|
||
| import ClusterNodesTable from './ClusterNodesTable' | ||
| import { ModifiedClusterNodes } from '../../ClusterDetailsPage' | ||
| import { ClusterNodeDetailsFactory } from 'uiSrc/mocks/factories/cluster/ClusterNodeDetails.factory' | ||
|
|
||
| const mockNodes = [ | ||
| ClusterNodeDetailsFactory.build({ | ||
| totalKeys: 1, | ||
| opsPerSecond: 1, | ||
| }), | ||
| ClusterNodeDetailsFactory.build({ | ||
| totalKeys: 4, | ||
| opsPerSecond: 1, | ||
| }), | ||
| ClusterNodeDetailsFactory.build({ | ||
| totalKeys: 10, | ||
| opsPerSecond: 0, | ||
| }), | ||
| ].map((d, index) => ({ | ||
| ...d, | ||
| letter: getLetterByIndex(index), | ||
| index, | ||
| color: [0, 0, 0], | ||
| })) as ModifiedClusterNodes[] | ||
|
|
||
| describe('ClusterNodesTable', () => { | ||
| it('should render', () => { | ||
| expect(render(<ClusterNodesTable nodes={mockNodes} />)).toBeTruthy() | ||
| }) | ||
|
|
||
| it('should render loading content', () => { | ||
| const { container } = render(<ClusterNodesTable nodes={[]} />) | ||
| expect(container).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should render table', () => { | ||
| const { container } = render(<ClusterNodesTable nodes={mockNodes} />) | ||
| expect(container).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByTestId('primary-nodes-table-loading'), | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should render table with 3 items', () => { | ||
| render(<ClusterNodesTable nodes={mockNodes} />) | ||
| expect(screen.getAllByTestId('node-letter')).toHaveLength(3) | ||
| }) | ||
|
|
||
| it('should highlight max value for total keys', () => { | ||
| render(<ClusterNodesTable nodes={mockNodes} />) | ||
| expect(screen.getByTestId('totalKeys-value-max')).toHaveTextContent( | ||
| mockNodes[2].totalKeys.toString(), | ||
| ) | ||
| }) | ||
|
|
||
| it('should not highlight max value for opsPerSecond with equals values', () => { | ||
| render(<ClusterNodesTable nodes={mockNodes} />) | ||
| expect( | ||
| screen.queryByTestId('opsPerSecond-value-max'), | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should render background color for each node', () => { | ||
| render(<ClusterNodesTable nodes={mockNodes} />) | ||
| mockNodes.forEach(({ letter, color }) => { | ||
| expect(screen.getByTestId(`node-color-${letter}`)).toHaveStyle({ | ||
| 'background-color': rgb(color), | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
22 changes: 22 additions & 0 deletions
22
redisinsight/ui/src/pages/cluster-details/components/ClusterNodesTable/ClusterNodesTable.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,22 @@ | ||
| import React from 'react' | ||
|
|
||
| import { Table } from 'uiSrc/components/base/layout/table' | ||
|
|
||
| import { | ||
| DEFAULT_CLUSTER_NODES_COLUMNS, | ||
| DEFAULT_SORTING, | ||
| } from './ClusterNodesTable.constants' | ||
| import { ClusterNodesEmptyState } from './components/ClusterNodesEmptyState/ClusterNodesEmptyState' | ||
| import { ClusterNodesTableProps } from './ClusterNodesTable.types' | ||
|
|
||
| const ClusterNodesTable = ({ nodes }: ClusterNodesTableProps) => ( | ||
| <Table | ||
| columns={DEFAULT_CLUSTER_NODES_COLUMNS} | ||
| data={nodes} | ||
| defaultSorting={DEFAULT_SORTING} | ||
| emptyState={ClusterNodesEmptyState} | ||
| maxHeight="20rem" | ||
| /> | ||
| ) | ||
|
|
||
| export default ClusterNodesTable |
10 changes: 10 additions & 0 deletions
10
...ight/ui/src/pages/cluster-details/components/ClusterNodesTable/ClusterNodesTable.types.ts
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,10 @@ | ||
| import { CellContext } from 'uiSrc/components/base/layout/table' | ||
| import { ModifiedClusterNodes } from '../../ClusterDetailsPage' | ||
|
|
||
| export type ClusterNodesTableProps = { | ||
| nodes: ModifiedClusterNodes[] | ||
| } | ||
|
|
||
| export type ClusterNodesTableCell = ( | ||
| props: CellContext<ModifiedClusterNodes, unknown>, | ||
| ) => React.ReactElement<any, any> | null |
8 changes: 8 additions & 0 deletions
8
...ents/ClusterNodesTable/components/ClusterNodesEmptyState/ClusterNodesEmptyState.styles.ts
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,8 @@ | ||
| import styled from 'styled-components' | ||
|
|
||
| export const EmptyStateWrapper = styled.div< | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >` | ||
| margin-top: 40px; | ||
| width: 100%; | ||
| ` |
11 changes: 11 additions & 0 deletions
11
...components/ClusterNodesTable/components/ClusterNodesEmptyState/ClusterNodesEmptyState.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,11 @@ | ||
| import React from 'react' | ||
|
|
||
| import { LoadingContent } from 'uiSrc/components' | ||
|
|
||
| import * as S from './ClusterNodesEmptyState.styles' | ||
|
|
||
| export const ClusterNodesEmptyState = () => ( | ||
| <S.EmptyStateWrapper data-testid="primary-nodes-table-loading"> | ||
| <LoadingContent lines={4} /> | ||
| </S.EmptyStateWrapper> | ||
| ) |
10 changes: 10 additions & 0 deletions
10
...mponents/ClusterNodesTable/components/ClusterNodesHostCell/ClusterNodesHostCell.styles.ts
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,10 @@ | ||
| import styled from 'styled-components' | ||
|
|
||
| export const LineIndicator = styled.div<{ $backgroundColor: string }>` | ||
| position: absolute; | ||
| left: 0; | ||
| top: 1px; | ||
| bottom: 1px; | ||
| width: 3px; | ||
| background-color: ${({ $backgroundColor }) => $backgroundColor}; | ||
| ` |
29 changes: 29 additions & 0 deletions
29
...ils/components/ClusterNodesTable/components/ClusterNodesHostCell/ClusterNodesHostCell.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,29 @@ | ||
| import React from 'react' | ||
|
|
||
| import { rgb } from 'uiSrc/utils/colors' | ||
| import { Text } from 'uiSrc/components/base/text' | ||
| import { Row } from 'uiSrc/components/base/layout/flex' | ||
| import { ClusterNodesTableCell } from 'uiSrc/pages/cluster-details/components/ClusterNodesTable/ClusterNodesTable.types' | ||
|
|
||
| import * as S from './ClusterNodesHostCell.styles' | ||
|
|
||
| export const ClusterNodesHostCell: ClusterNodesTableCell = ({ | ||
| row: { | ||
| original: { letter, port, color, host }, | ||
| }, | ||
| }) => ( | ||
| <> | ||
| <S.LineIndicator | ||
| data-testid={`node-color-${letter}`} | ||
| $backgroundColor={rgb(color)} | ||
| /> | ||
| <Row justify="between"> | ||
| <Text variant="semiBold" data-testid="node-letter"> | ||
| {letter} | ||
| </Text> | ||
| <Text variant="regular"> | ||
| {host}:{port} | ||
| </Text> | ||
| </Row> | ||
| </> | ||
| ) | ||
Oops, something went wrong.
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.