Skip to content

Commit b6fe67a

Browse files
committed
Refactor Sentinel databases column definitions
- Extracted column definitions to separate files - Updated useSentinelDatabasesConfig.tsx with new structure
1 parent 40cd5e7 commit b6fe67a

File tree

10 files changed

+245
-162
lines changed

10 files changed

+245
-162
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react'
2+
import {
3+
CopyTextContainer,
4+
CopyPublicEndpointText,
5+
CopyBtn,
6+
} from 'uiSrc/components/auto-discover'
7+
import { RiTooltip } from 'uiSrc/components'
8+
import { type ColumnDef } from 'uiSrc/components/base/layout/table'
9+
import { ModifiedSentinelMaster } from 'uiSrc/slices/interfaces'
10+
11+
const handleCopy = (text = '') => {
12+
return navigator.clipboard.writeText(text)
13+
}
14+
15+
export const AddressColumn = (): ColumnDef<ModifiedSentinelMaster> => {
16+
return {
17+
header: 'Address',
18+
id: 'host',
19+
accessorKey: 'host',
20+
enableSorting: true,
21+
cell: ({
22+
row: {
23+
original: { host, port },
24+
},
25+
}) => {
26+
const text = `${host}:${port}`
27+
return (
28+
<CopyTextContainer>
29+
<CopyPublicEndpointText>{text}</CopyPublicEndpointText>
30+
<RiTooltip
31+
position="right"
32+
content="Copy"
33+
anchorClassName="copyPublicEndpointTooltip"
34+
>
35+
<CopyBtn
36+
aria-label="Copy public endpoint"
37+
onClick={() => handleCopy(text)}
38+
tabIndex={-1}
39+
/>
40+
</RiTooltip>
41+
</CopyTextContainer>
42+
)
43+
},
44+
}
45+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react'
2+
import { InputFieldSentinel } from 'uiSrc/components'
3+
import { SentinelInputFieldType } from 'uiSrc/components/input-field-sentinel/InputFieldSentinel'
4+
import { type ColumnDef } from 'uiSrc/components/base/layout/table'
5+
import { ModifiedSentinelMaster } from 'uiSrc/slices/interfaces'
6+
7+
export const AliasColumn = (
8+
handleChangedInput: (name: string, value: string) => void,
9+
): ColumnDef<ModifiedSentinelMaster> => {
10+
return {
11+
header: 'Database Alias*',
12+
id: 'alias',
13+
accessorKey: 'alias',
14+
enableSorting: true,
15+
size: 200,
16+
cell: ({
17+
row: {
18+
original: { id, alias, name },
19+
},
20+
}) => (
21+
<div role="presentation">
22+
<InputFieldSentinel
23+
name={`alias-${id}`}
24+
value={alias || name}
25+
placeholder="Enter Database Alias"
26+
inputType={SentinelInputFieldType.Text}
27+
onChangedInput={handleChangedInput}
28+
maxLength={500}
29+
/>
30+
</div>
31+
),
32+
}
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react'
2+
import { InputFieldSentinel, RiTooltip } from 'uiSrc/components'
3+
import { SentinelInputFieldType } from 'uiSrc/components/input-field-sentinel/InputFieldSentinel'
4+
import { type ColumnDef } from 'uiSrc/components/base/layout/table'
5+
import { ModifiedSentinelMaster } from 'uiSrc/slices/interfaces'
6+
import { RiIcon } from 'uiSrc/components/base/icons'
7+
8+
export const DbIndexColumn = (
9+
handleChangedInput: (name: string, value: string) => void,
10+
): ColumnDef<ModifiedSentinelMaster> => {
11+
return {
12+
header: 'Database Index',
13+
id: 'db',
14+
accessorKey: 'db',
15+
size: 140,
16+
cell: ({
17+
row: {
18+
original: { db = 0, id },
19+
},
20+
}) => (
21+
<div role="presentation">
22+
<InputFieldSentinel
23+
min={0}
24+
value={`${db}` || '0'}
25+
name={`db-${id}`}
26+
placeholder="Enter Index"
27+
inputType={SentinelInputFieldType.Number}
28+
onChangedInput={handleChangedInput}
29+
append={
30+
<RiTooltip
31+
anchorClassName="inputAppendIcon"
32+
position="left"
33+
content="Select the Redis logical database to work with in Browser and Workbench."
34+
>
35+
<RiIcon type="InfoIcon" style={{ cursor: 'pointer' }} />
36+
</RiTooltip>
37+
}
38+
/>
39+
</div>
40+
),
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { type ColumnDef } from 'uiSrc/components/base/layout/table'
2+
import { ModifiedSentinelMaster } from 'uiSrc/slices/interfaces'
3+
4+
export const NumberOfReplicasColumn = (): ColumnDef<ModifiedSentinelMaster> => {
5+
return {
6+
header: '# of replicas',
7+
id: 'numberOfSlaves',
8+
accessorKey: 'numberOfSlaves',
9+
enableSorting: true,
10+
size: 120,
11+
}
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import { InputFieldSentinel } from 'uiSrc/components'
3+
import { SentinelInputFieldType } from 'uiSrc/components/input-field-sentinel/InputFieldSentinel'
4+
import { type ColumnDef } from 'uiSrc/components/base/layout/table'
5+
import { ModifiedSentinelMaster } from 'uiSrc/slices/interfaces'
6+
7+
export const PasswordColumn = (
8+
handleChangedInput: (name: string, value: string) => void,
9+
): ColumnDef<ModifiedSentinelMaster> => {
10+
return {
11+
header: 'Password',
12+
id: 'password',
13+
accessorKey: 'password',
14+
cell: ({
15+
row: {
16+
original: { password, id },
17+
},
18+
}) => (
19+
<div role="presentation">
20+
<InputFieldSentinel
21+
value={password}
22+
name={`password-${id}`}
23+
placeholder="Enter Password"
24+
inputType={SentinelInputFieldType.Password}
25+
onChangedInput={handleChangedInput}
26+
/>
27+
</div>
28+
),
29+
}
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react'
2+
import { CellText } from 'uiSrc/components/auto-discover'
3+
import { type ColumnDef } from 'uiSrc/components/base/layout/table'
4+
import { ModifiedSentinelMaster } from 'uiSrc/slices/interfaces'
5+
6+
export const PrimaryGroupColumn = (): ColumnDef<ModifiedSentinelMaster> => {
7+
return {
8+
header: 'Primary Group',
9+
id: 'name',
10+
accessorKey: 'name',
11+
enableSorting: true,
12+
size: 200,
13+
cell: ({
14+
row: {
15+
original: { name },
16+
},
17+
}) => <CellText data-testid={`primary-group_${name}`}>{name}</CellText>,
18+
}
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ModifiedSentinelMaster } from 'uiSrc/slices/interfaces'
2+
import { getSelectionColumn } from 'uiSrc/pages/autodiscover-cloud/utils'
3+
4+
export const SelectionColumn = () => {
5+
return getSelectionColumn<ModifiedSentinelMaster>()
6+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import { InputFieldSentinel } from 'uiSrc/components'
3+
import { SentinelInputFieldType } from 'uiSrc/components/input-field-sentinel/InputFieldSentinel'
4+
import { type ColumnDef } from 'uiSrc/components/base/layout/table'
5+
import { ModifiedSentinelMaster } from 'uiSrc/slices/interfaces'
6+
7+
export const UsernameColumn = (
8+
handleChangedInput: (name: string, value: string) => void,
9+
): ColumnDef<ModifiedSentinelMaster> => {
10+
return {
11+
header: 'Username',
12+
id: 'username',
13+
accessorKey: 'username',
14+
cell: ({
15+
row: {
16+
original: { username, id },
17+
},
18+
}) => (
19+
<div role="presentation">
20+
<InputFieldSentinel
21+
value={username}
22+
name={`username-${id}`}
23+
placeholder="Enter Username"
24+
inputType={SentinelInputFieldType.Text}
25+
onChangedInput={handleChangedInput}
26+
/>
27+
</div>
28+
),
29+
}
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export * from './PrimaryGroupColumn'
2+
export * from './AliasColumn'
3+
export * from './AddressColumn'
4+
export * from './NumberOfReplicasColumn'
5+
export * from './UsernameColumn'
6+
export * from './PasswordColumn'
7+
export * from './DbIndexColumn'
8+
export * from './SelectionColumn'

0 commit comments

Comments
 (0)