diff --git a/redisinsight/ui/src/pages/home/components/form/DbInfo.styles.ts b/redisinsight/ui/src/pages/home/components/form/DbInfo.styles.ts new file mode 100644 index 0000000000..c5faa1ebae --- /dev/null +++ b/redisinsight/ui/src/pages/home/components/form/DbInfo.styles.ts @@ -0,0 +1,10 @@ +import styled from 'styled-components' +import { Group } from 'uiSrc/components/base/layout/list' + +export const DbInfoGroup = styled(Group)` + background-color: ${({ theme }) => + theme.semantic.color.background.neutral200}; + border: 1px solid ${({ theme }) => theme.semantic.color.border.neutral400}; + padding: ${({ theme }) => theme.core.space.space100}; + border-radius: 5px; +` diff --git a/redisinsight/ui/src/pages/home/components/form/DbInfo.tsx b/redisinsight/ui/src/pages/home/components/form/DbInfo.tsx index a576bbc269..8108da3262 100644 --- a/redisinsight/ui/src/pages/home/components/form/DbInfo.tsx +++ b/redisinsight/ui/src/pages/home/components/form/DbInfo.tsx @@ -2,21 +2,21 @@ import React from 'react' import { useSelector } from 'react-redux' import { capitalize } from 'lodash' -import { ColorText, Text } from 'uiSrc/components/base/text' +import { Text } from 'uiSrc/components/base/text' import { DatabaseListModules, RiTooltip } from 'uiSrc/components' import { BuildType } from 'uiSrc/constants/env' import { appInfoSelector } from 'uiSrc/slices/app/info' import { ConnectionType } from 'uiSrc/slices/interfaces' import { Nullable } from 'uiSrc/utils' -import { - Group as ListGroup, - Item as ListGroupItem, -} from 'uiSrc/components/base/layout/list' +import { Item as ListGroupItem } from 'uiSrc/components/base/layout/list' import { RiIcon } from 'uiSrc/components/base/icons/RiIcon' import { Endpoint } from 'apiSrc/common/models' import { AdditionalRedisModule } from 'apiSrc/modules/database/models/additional.redis.module' import styles from '../styles.module.scss' +import { DbInfoGroup } from './DbInfo.styles' +import { Row } from 'uiSrc/components/base/layout/flex' +import { DbInfoLabelValue } from './types' export interface Props { connectionType?: ConnectionType @@ -29,6 +29,59 @@ export interface Props { isFromCloud: boolean } +export const ListGroupItemLabelValue = ({ + label, + value, + dataTestId, + additionalContent, +}: { + label: string + value: string | React.ReactNode + dataTestId?: string + additionalContent?: React.ReactNode +}) => ( + + {label} + + {value} + + {additionalContent} + + } + /> +) + +const AppendEndpoints = ({ + nodes, + host, + port, +}: { + nodes: Endpoint[] + host: string + port: string +}) => ( + + {nodes?.map(({ host: eHost, port: ePort }) => ( +
  • + + {eHost}:{ePort}; + +
  • + ))} + + } + > + +
    +) + const DbInfo = (props: Props) => { const { connectionType, @@ -43,121 +96,61 @@ const DbInfo = (props: Props) => { const { server } = useSelector(appInfoSelector) - const AppendEndpoints = () => ( - - {nodes?.map(({ host: eHost, port: ePort }) => ( -
  • - - {eHost}:{ePort}; - -
  • - ))} - - } - > - -
    - ) + const dbInfo: DbInfoLabelValue[] = [ + { + label: 'Connection Type:', + value: capitalize(connectionType), + dataTestId: 'connection-type', + hide: isFromCloud, + }, + { + label: 'Database Name from Provider:', + value: nameFromProvider, + dataTestId: 'db-name-from-provider', + hide: !nameFromProvider, + }, + { + label: 'Host:', + value: host, + dataTestId: 'db-info-host', + additionalContent: !!nodes?.length && ( + + ), + }, + { + label: 'Port:', + value: port, + dataTestId: 'db-info-port', + hide: (server?.buildType !== BuildType.RedisStack) && !isFromCloud, + }, + { + label: 'Database Index:', + value: db?.toString(), + dataTestId: 'db-index', + hide: !db, + }, + { + label: 'Capabilities:', + value: , + dataTestId: 'capabilities', + hide: !modules?.length, + }, + ] return ( - - {!isFromCloud && ( - - Connection Type: - - {capitalize(connectionType)} - - - } - /> - )} - - {nameFromProvider && ( - - Database Name from Provider: - - {nameFromProvider} - - - } - /> - )} - - {!!nodes?.length && } - - Host: - - {host} - - - - } - /> - {(server?.buildType === BuildType.RedisStack || isFromCloud) && ( - - Port: - - {port} - - - } - /> - )} - - {!!db && ( - - Database Index: - - {db} - - - } - /> - )} - - {!!modules?.length && ( - - Capabilities: - - - } - /> - )} - + + {dbInfo + .filter((item) => !item.hide) + .map((item) => ( + + ))} + ) } diff --git a/redisinsight/ui/src/pages/home/components/form/sentinel/DbInfoSentinel.styles.ts b/redisinsight/ui/src/pages/home/components/form/sentinel/DbInfoSentinel.styles.ts new file mode 100644 index 0000000000..81808f2459 --- /dev/null +++ b/redisinsight/ui/src/pages/home/components/form/sentinel/DbInfoSentinel.styles.ts @@ -0,0 +1,12 @@ +import styled from 'styled-components' + +import { IconButton } from 'uiSrc/components/base/forms/buttons' + +export const StyledCopyButton = styled(IconButton)` + margin-bottom: 3px; + opacity: 0; + + :hover { + opacity: 1; + } +` diff --git a/redisinsight/ui/src/pages/home/components/form/sentinel/DbInfoSentinel.tsx b/redisinsight/ui/src/pages/home/components/form/sentinel/DbInfoSentinel.tsx index 1d24ae8c2b..38ca470179 100644 --- a/redisinsight/ui/src/pages/home/components/form/sentinel/DbInfoSentinel.tsx +++ b/redisinsight/ui/src/pages/home/components/form/sentinel/DbInfoSentinel.tsx @@ -3,15 +3,15 @@ import { capitalize } from 'lodash' import { ConnectionType } from 'uiSrc/slices/interfaces' import { Nullable } from 'uiSrc/utils' -import { ColorText, Text } from 'uiSrc/components/base/text' -import { - Group as ListGroup, - Item as ListGroupItem, -} from 'uiSrc/components/base/layout/list' import { SentinelMaster } from 'apiSrc/modules/redis-sentinel/models/sentinel-master' -import SentinelHostPort from './SentinelHostPort' -import styles from '../../styles.module.scss' +import { RiTooltip } from 'uiSrc/components/base/tooltip' +import { CopyIcon } from 'uiSrc/components/base/icons' + +import { DbInfoGroup } from '../DbInfo.styles' +import { ListGroupItemLabelValue } from '../DbInfo' +import { StyledCopyButton } from './DbInfoSentinel.styles' +import { DbInfoLabelValue } from '../types' export interface Props { host?: string @@ -21,49 +21,70 @@ export interface Props { sentinelMaster?: SentinelMaster } +const handleCopy = (text = '') => { + navigator.clipboard.writeText(text) +} + +const CopyButtonTooltip = ({ + host, + port, +}: { + host?: string + port?: string +}) => ( + + handleCopy(`${host}:${port}`)} + /> + +) + const DbInfoSentinel = (props: Props) => { const { connectionType, nameFromProvider, sentinelMaster, host, port } = props - return ( - - - Connection Type: - - {capitalize(connectionType)} - - - } - /> - {sentinelMaster?.name && ( - - Primary Group Name: - - {sentinelMaster?.name} - - - } - /> - )} + const dbInfo: DbInfoLabelValue[] = [ + { + label: 'Connection Type:', + value: capitalize(connectionType), + dataTestId: 'connection-type', + }, + { + label: 'Primary Group Name:', + value: sentinelMaster?.name, + dataTestId: 'primary-group-name', + hide: !sentinelMaster?.name, + }, + { + label: 'Database Name from Provider:', + value: nameFromProvider, + dataTestId: 'db-name-from-provider', + hide: !nameFromProvider, + }, + { + label: 'Sentinel Host & Port:', + value: `${host}:${port}`, + dataTestId: 'host-and-port', + additionalContent: , + hide: !host || !port, + }, + ] - {nameFromProvider && ( - - Database Name from Provider: - - {nameFromProvider} - - - } - /> - )} - - {host && port && } - + return ( + + {dbInfo + .filter((item) => !item.hide) + .map((item) => ( + + ))} + ) } diff --git a/redisinsight/ui/src/pages/home/components/form/sentinel/SentinelHostPort.tsx b/redisinsight/ui/src/pages/home/components/form/sentinel/SentinelHostPort.tsx deleted file mode 100644 index 436fc5b086..0000000000 --- a/redisinsight/ui/src/pages/home/components/form/sentinel/SentinelHostPort.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import React from 'react' - -import { RiTooltip } from 'uiSrc/components' -import { ColorText, Text } from 'uiSrc/components/base/text' -import { IconButton } from 'uiSrc/components/base/forms/buttons' -import { CopyIcon } from 'uiSrc/components/base/icons' -import styles from '../../styles.module.scss' - -export interface Props { - host: string - port: string -} - -const SentinelHostPort = (props: Props) => { - const { host, port } = props - - const handleCopy = (text = '') => { - navigator.clipboard.writeText(text) - } - - return ( - - Sentinel Host & Port: -
    - {`${host}:${port}`} - - handleCopy(`${host}:${port}`)} - /> - -
    -
    - ) -} - -export default SentinelHostPort diff --git a/redisinsight/ui/src/pages/home/components/form/sentinel/index.ts b/redisinsight/ui/src/pages/home/components/form/sentinel/index.ts index c8557bafd5..9598b57ada 100644 --- a/redisinsight/ui/src/pages/home/components/form/sentinel/index.ts +++ b/redisinsight/ui/src/pages/home/components/form/sentinel/index.ts @@ -1,11 +1,5 @@ import DbInfoSentinel from './DbInfoSentinel' import PrimaryGroupSentinel from './PrimaryGroupSentinel' import SentinelMasterDatabase from './SentinelMasterDatabase' -import SentinelHostPort from './SentinelHostPort' -export { - DbInfoSentinel, - PrimaryGroupSentinel, - SentinelMasterDatabase, - SentinelHostPort, -} +export { DbInfoSentinel, PrimaryGroupSentinel, SentinelMasterDatabase } diff --git a/redisinsight/ui/src/pages/home/components/form/types.ts b/redisinsight/ui/src/pages/home/components/form/types.ts new file mode 100644 index 0000000000..b6cb891c33 --- /dev/null +++ b/redisinsight/ui/src/pages/home/components/form/types.ts @@ -0,0 +1,7 @@ +export interface DbInfoLabelValue { + label: string + value: string | React.ReactNode + dataTestId?: string + additionalContent?: React.ReactNode + hide?: boolean +} diff --git a/redisinsight/ui/src/pages/home/components/manual-connection/manual-connection-form/components/CloneConnection.tsx b/redisinsight/ui/src/pages/home/components/manual-connection/manual-connection-form/components/CloneConnection.tsx index 8dde9309fb..096c09ddd4 100644 --- a/redisinsight/ui/src/pages/home/components/manual-connection/manual-connection-form/components/CloneConnection.tsx +++ b/redisinsight/ui/src/pages/home/components/manual-connection/manual-connection-form/components/CloneConnection.tsx @@ -3,7 +3,6 @@ import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry' import { FlexItem, Row } from 'uiSrc/components/base/layout/flex' import { Spacer } from 'uiSrc/components/base/layout/spacer' import { SecondaryButton } from 'uiSrc/components/base/forms/buttons' -import { CopyIcon } from 'uiSrc/components/base/icons' export interface Props { id?: string @@ -28,8 +27,7 @@ const CloneConnection = (props: Props) => {