-
Notifications
You must be signed in to change notification settings - Fork 5
/
ChainsTable.tsx
81 lines (77 loc) · 2.35 KB
/
ChainsTable.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { ActionIcon, Flex, TextInput } from "@mantine/core"
import { useParams } from "@remix-run/react"
import { useMemo } from "react"
import { LuTrash2 } from "react-icons/lu"
import Chain from "~/components/Chain"
import CopyTextButton from "~/components/CopyTextButton"
import { DataTable } from "~/components/DataTable"
import { Blockchain } from "~/models/portal/sdk"
import { getAppEndpointUrl } from "~/utils/chainUtils"
type ChainsTableProps = {
blockchains: Blockchain[]
selectedBlockchainsIds: string[]
onDeleteChain: (chainId: string) => void
readOnly?: boolean
}
const ChainsTable = ({
blockchains,
selectedBlockchainsIds,
onDeleteChain,
readOnly,
}: ChainsTableProps) => {
const { appId } = useParams()
const selectedBlockChains = useMemo(
() =>
blockchains.filter(({ id: blockchainID }) =>
selectedBlockchainsIds.some((id) => blockchainID === id),
),
[blockchains, selectedBlockchainsIds],
)
return (
selectedBlockChains && (
<DataTable
data={selectedBlockChains.map((chain) => {
return {
chain: {
element: <Chain chain={chain} />,
value: `${chain?.description} ${chain?.blockchain}`,
cellProps: {
style: { minWidth: "250px" },
width: "30%",
},
},
endpointUrl: {
element: (
<TextInput readOnly miw={300} value={getAppEndpointUrl(chain, appId)} />
),
},
action: {
element: (
<Flex gap="lg" justify="flex-end">
<CopyTextButton value={getAppEndpointUrl(chain, appId)} />
{!readOnly && (
<ActionIcon
aria-label={`Delete ${chain.description}`}
radius="xl"
size={40}
variant="outline"
onClick={() => onDeleteChain(chain.id)}
>
<LuTrash2 size={18} />
</ActionIcon>
)}
</Flex>
),
cellProps: {
style: { minWidth: "130px" },
width: "130px",
},
},
}
})}
paginate={false}
/>
)
)
}
export default ChainsTable