Skip to content

Commit 175aca2

Browse files
authored
refactor: clickable entity table rows (#191)
1 parent 444195a commit 175aca2

File tree

8 files changed

+133
-40
lines changed
  • src/components/pages/console
    • confidential/ConfidentialsTabContent
    • domain/DomainsTabContent
    • function/FunctionsTabContent
    • gpuInstance/GpuInstancesTabContent
    • instance/InstancesTabContent
    • sshKey/SSHKeysTabContent
    • volume/VolumesTabContent
    • website/WebsitesTabContent

8 files changed

+133
-40
lines changed

src/components/pages/console/confidential/ConfidentialsTabContent/cmp.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { memo } from 'react'
1+
import React, { memo, useCallback } from 'react'
22
import tw from 'twin.macro'
3+
import { useRouter } from 'next/router'
34
import { ConfidentialsTabContentProps } from './types'
45
import ButtonLink from '@/components/common/ButtonLink'
56
import {
@@ -8,7 +9,8 @@ import {
89
humanReadableSize,
910
} from '@/helpers/utils'
1011
import EntityTable from '@/components/common/EntityTable'
11-
import { Icon } from '@aleph-front/core'
12+
import { Button, Icon } from '@aleph-front/core'
13+
import { Confidential } from '@/domain/confidential'
1214

1315
const CreateConfidentialButton = ({
1416
children,
@@ -27,6 +29,13 @@ CreateConfidentialButton.displayName = 'CreateConfidentialButton'
2729

2830
export const ConfidentialsTabContent = memo(
2931
({ data }: ConfidentialsTabContentProps) => {
32+
const router = useRouter()
33+
const handleRowClick = useCallback(
34+
(confidential: Confidential) => {
35+
router.push(`/console/computing/confidential/${confidential.id}`)
36+
},
37+
[router],
38+
)
3039
return (
3140
<>
3241
{data.length > 0 ? (
@@ -36,6 +45,8 @@ export const ConfidentialsTabContent = memo(
3645
borderType="none"
3746
rowNoise
3847
rowKey={(row) => row.id}
48+
rowProps={(row) => ({ onClick: () => handleRowClick(row) })}
49+
clickableRows
3950
data={data}
4051
columns={[
4152
{
@@ -78,13 +89,13 @@ export const ConfidentialsTabContent = memo(
7889
label: '',
7990
align: 'right',
8091
render: (row) => (
81-
<ButtonLink
92+
<Button
8293
kind="functional"
8394
variant="secondary"
84-
href={`/console/computing/confidential/${row.id}`}
95+
onClick={() => handleRowClick(row)}
8596
>
8697
<Icon name="angle-right" size="lg" />
87-
</ButtonLink>
98+
</Button>
8899
),
89100
cellProps: () => ({
90101
css: tw`pl-3!`,

src/components/pages/console/domain/DomainsTabContent/cmp.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
import React, { memo } from 'react'
1+
import React, { memo, useCallback } from 'react'
22
import tw from 'twin.macro'
3+
import { useRouter } from 'next/router'
34
import { DomainsTabContentProps } from './types'
45
import ButtonLink from '@/components/common/ButtonLink'
56
import EntityTable from '@/components/common/EntityTable'
6-
import { Icon } from '@aleph-front/core'
7+
import { Button, Icon } from '@aleph-front/core'
78
import IconText from '@/components/common/IconText'
89
import { Text } from '../../common'
910
import { EntityDomainType, EntityDomainTypeName } from '@/helpers/constants'
1011
import { useDomainsEntityNames } from '@/hooks/common/useDomainsEntityNames'
12+
import { Domain } from '@/domain/domain'
1113

1214
export const DomainsTabContent = ({
1315
data,
1416
cta = true,
1517
}: DomainsTabContentProps) => {
18+
const router = useRouter()
19+
const handleRowClick = useCallback(
20+
(domain: Domain) => {
21+
router.push(`/console/settings/domain/${domain.id}`)
22+
},
23+
[router],
24+
)
1625
const entityNames = useDomainsEntityNames(data)
1726

1827
return (
@@ -24,8 +33,10 @@ export const DomainsTabContent = ({
2433
rowKey={(row) => row.id}
2534
data={data}
2635
rowProps={(row) => ({
36+
onClick: () => handleRowClick(row),
2737
css: row.confirmed ? '' : tw`opacity-60`,
2838
})}
39+
clickableRows
2940
columns={[
3041
{
3142
label: 'Name',
@@ -67,13 +78,13 @@ export const DomainsTabContent = ({
6778
label: '',
6879
align: 'right',
6980
render: (row) => (
70-
<ButtonLink
81+
<Button
7182
kind="functional"
7283
variant="secondary"
73-
href={`/console/settings/domain/${row.id}`}
84+
onClick={() => handleRowClick(row)}
7485
>
7586
<Icon name="angle-right" size="lg" />
76-
</ButtonLink>
87+
</Button>
7788
),
7889
cellProps: () => ({
7990
css: tw`pl-3!`,

src/components/pages/console/function/FunctionsTabContent/cmp.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
import React from 'react'
1+
import React, { useCallback } from 'react'
22
import tw from 'twin.macro'
3+
import { useRouter } from 'next/router'
34
import { FunctionsTabContentProps } from './types'
45
import ButtonLink from '@/components/common/ButtonLink'
56
import { convertByteUnits, ellipseAddress } from '@/helpers/utils'
67
import EntityTable from '@/components/common/EntityTable'
7-
import { Icon } from '@aleph-front/core'
8+
import { Button, Icon } from '@aleph-front/core'
89
import { NAVIGATION_URLS } from '@/helpers/constants'
10+
import { Program } from '@/domain/program'
911

1012
export const FunctionsTabContent = React.memo(
1113
({ data }: FunctionsTabContentProps) => {
14+
const router = useRouter()
15+
const handleRowClick = useCallback(
16+
(program: Program) => {
17+
router.push(
18+
`${NAVIGATION_URLS.console.computing.functions.home}/${program.id}`,
19+
)
20+
},
21+
[router],
22+
)
1223
return (
1324
<>
1425
{data.length > 0 ? (
@@ -20,8 +31,10 @@ export const FunctionsTabContent = React.memo(
2031
rowKey={(row) => row.id}
2132
data={data}
2233
rowProps={(row) => ({
34+
onClick: () => handleRowClick(row),
2335
css: row.confirmed ? '' : tw`opacity-60`,
2436
})}
37+
clickableRows
2538
columns={[
2639
{
2740
label: 'Name',
@@ -73,13 +86,13 @@ export const FunctionsTabContent = React.memo(
7386
label: '',
7487
align: 'right',
7588
render: (row) => (
76-
<ButtonLink
89+
<Button
7790
kind="functional"
7891
variant="secondary"
79-
href={`${NAVIGATION_URLS.console.computing.functions.home}/${row.id}`}
92+
onClick={() => handleRowClick(row)}
8093
>
8194
<Icon name="angle-right" size="lg" />
82-
</ButtonLink>
95+
</Button>
8396
),
8497
cellProps: () => ({
8598
css: tw`pl-3!`,

src/components/pages/console/gpuInstance/GpuInstancesTabContent/cmp.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React from 'react'
1+
import React, { useCallback } from 'react'
22
import tw from 'twin.macro'
3+
import { useRouter } from 'next/router'
34
import { GpuInstancesTabContentProps } from './types'
45
import ButtonLink from '@/components/common/ButtonLink'
56
import {
@@ -8,10 +9,18 @@ import {
89
humanReadableSize,
910
} from '@/helpers/utils'
1011
import EntityTable from '@/components/common/EntityTable'
11-
import { Icon } from '@aleph-front/core'
12+
import { Button, Icon } from '@aleph-front/core'
13+
import { GpuInstance } from '@/domain/gpuInstance'
1214

1315
export const GpuInstancesTabContent = React.memo(
1416
({ data }: GpuInstancesTabContentProps) => {
17+
const router = useRouter()
18+
const handleRowClick = useCallback(
19+
(gpuInstance: GpuInstance) => {
20+
router.push(`/console/computing/gpu-instance/${gpuInstance.id}`)
21+
},
22+
[router],
23+
)
1524
return (
1625
<>
1726
{data.length > 0 ? (
@@ -21,6 +30,8 @@ export const GpuInstancesTabContent = React.memo(
2130
borderType="none"
2231
rowNoise
2332
rowKey={(row) => row.id}
33+
rowProps={(row) => ({ onClick: () => handleRowClick(row) })}
34+
clickableRows
2435
data={data}
2536
columns={[
2637
{
@@ -63,13 +74,13 @@ export const GpuInstancesTabContent = React.memo(
6374
label: '',
6475
align: 'right',
6576
render: (row) => (
66-
<ButtonLink
77+
<Button
6778
kind="functional"
6879
variant="secondary"
69-
href={`/console/computing/gpu-instance/${row.id}`}
80+
onClick={() => handleRowClick(row)}
7081
>
7182
<Icon name="angle-right" size="lg" />
72-
</ButtonLink>
83+
</Button>
7384
),
7485
cellProps: () => ({
7586
css: tw`pl-3!`,

src/components/pages/console/instance/InstancesTabContent/cmp.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React from 'react'
1+
import React, { useCallback } from 'react'
22
import tw from 'twin.macro'
3+
import { useRouter } from 'next/router'
34
import { InstancesTabContentProps } from './types'
45
import ButtonLink from '@/components/common/ButtonLink'
56
import {
@@ -8,10 +9,19 @@ import {
89
humanReadableSize,
910
} from '@/helpers/utils'
1011
import EntityTable from '@/components/common/EntityTable'
11-
import { Icon } from '@aleph-front/core'
12+
import { Button, Icon } from '@aleph-front/core'
13+
import { Instance } from '@/domain/instance'
1214

1315
export const InstancesTabContent = React.memo(
1416
({ data }: InstancesTabContentProps) => {
17+
const router = useRouter()
18+
const handleRowClick = useCallback(
19+
(instance: Instance) => {
20+
router.push(`/console/computing/instance/${instance.id}`)
21+
},
22+
[router],
23+
)
24+
1525
return (
1626
<>
1727
{data.length > 0 ? (
@@ -21,6 +31,8 @@ export const InstancesTabContent = React.memo(
2131
borderType="none"
2232
rowNoise
2333
rowKey={(row) => row.id}
34+
rowProps={(row) => ({ onClick: () => handleRowClick(row) })}
35+
clickableRows
2436
data={data}
2537
columns={[
2638
{
@@ -63,13 +75,13 @@ export const InstancesTabContent = React.memo(
6375
label: '',
6476
align: 'right',
6577
render: (row) => (
66-
<ButtonLink
78+
<Button
6779
kind="functional"
6880
variant="secondary"
69-
href={`/console/computing/instance/${row.id}`}
81+
onClick={() => handleRowClick(row)}
7082
>
7183
<Icon name="angle-right" size="lg" />
72-
</ButtonLink>
84+
</Button>
7385
),
7486
cellProps: () => ({
7587
css: tw`pl-3!`,

src/components/pages/console/sshKey/SSHKeysTabContent/cmp.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import React, { memo } from 'react'
1+
import React, { memo, useCallback } from 'react'
22
import tw from 'twin.macro'
3+
import { useRouter } from 'next/router'
34
import { SSHKeysTabContentProps } from './types'
45
import ButtonLink from '@/components/common/ButtonLink'
56
import EntityTable from '@/components/common/EntityTable'
6-
import { Icon } from '@aleph-front/core'
7+
import { Button, Icon } from '@aleph-front/core'
78
import { ellipseText } from '@/helpers/utils'
9+
import { SSHKey } from '@/domain/ssh'
810

911
export const SSHKeysTabContent = ({ data }: SSHKeysTabContentProps) => {
12+
const router = useRouter()
13+
const handleRowClick = useCallback(
14+
(sshKey: SSHKey) => {
15+
router.push(`/console/settings/ssh/${sshKey.id}`)
16+
},
17+
[router],
18+
)
1019
return (
1120
<>
1221
<div tw="overflow-auto max-w-full">
@@ -16,8 +25,10 @@ export const SSHKeysTabContent = ({ data }: SSHKeysTabContentProps) => {
1625
rowKey={(row) => row.key}
1726
data={data}
1827
rowProps={(row) => ({
28+
onClick: () => handleRowClick(row),
1929
css: row.confirmed ? '' : tw`opacity-60`,
2030
})}
31+
clickableRows
2132
columns={[
2233
{
2334
label: 'Label',
@@ -37,13 +48,13 @@ export const SSHKeysTabContent = ({ data }: SSHKeysTabContentProps) => {
3748
label: '',
3849
align: 'right',
3950
render: (row) => (
40-
<ButtonLink
51+
<Button
4152
kind="functional"
4253
variant="secondary"
43-
href={`/console/settings/ssh/${row.id}`}
54+
onClick={() => handleRowClick(row)}
4455
>
4556
<Icon name="angle-right" size="lg" />
46-
</ButtonLink>
57+
</Button>
4758
),
4859
cellProps: () => ({
4960
css: tw`pl-3!`,

src/components/pages/console/volume/VolumesTabContent/cmp.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
import React, { memo } from 'react'
1+
import React, { memo, useCallback } from 'react'
22
import tw from 'twin.macro'
3+
import { useRouter } from 'next/router'
34
import { VolumesTabContentProps } from './types'
45
import ButtonLink from '@/components/common/ButtonLink'
56
import { ellipseAddress, humanReadableSize } from '@/helpers/utils'
67
import EntityTable from '@/components/common/EntityTable'
7-
import { Icon } from '@aleph-front/core'
8+
import { Button, Icon } from '@aleph-front/core'
89
import { NAVIGATION_URLS } from '@/helpers/constants'
10+
import { Volume } from '@/domain/volume'
911

1012
export const VolumesTabContent = ({
1113
data,
1214
cta = true,
1315
}: VolumesTabContentProps) => {
16+
const router = useRouter()
17+
const handleRowClick = useCallback(
18+
(volume: Volume) => {
19+
router.push(
20+
`${NAVIGATION_URLS.console.storage.volumes.home}/${volume.id}`,
21+
)
22+
},
23+
[router],
24+
)
1425
return (
1526
<>
1627
<div tw="overflow-auto max-w-full">
@@ -20,8 +31,10 @@ export const VolumesTabContent = ({
2031
rowKey={(row) => row.id}
2132
data={data}
2233
rowProps={(row) => ({
34+
onClick: () => handleRowClick(row),
2335
css: row.confirmed ? '' : tw`opacity-60`,
2436
})}
37+
clickableRows
2538
columns={[
2639
{
2740
label: 'Name',
@@ -45,13 +58,13 @@ export const VolumesTabContent = ({
4558
label: '',
4659
align: 'right',
4760
render: (row) => (
48-
<ButtonLink
61+
<Button
4962
kind="functional"
5063
variant="secondary"
51-
href={`${NAVIGATION_URLS.console.storage.volumes.home}/${row.id}`}
64+
onClick={() => handleRowClick(row)}
5265
>
5366
<Icon name="angle-right" size="lg" />
54-
</ButtonLink>
67+
</Button>
5568
),
5669
cellProps: () => ({
5770
css: tw`pl-3!`,

0 commit comments

Comments
 (0)