Skip to content

Commit b1add5c

Browse files
committed
feat(indexd): add public key filtering for hosts and contracts
1 parent 8dfbe56 commit b1add5c

File tree

16 files changed

+390
-12
lines changed

16 files changed

+390
-12
lines changed

.changeset/purple-impalas-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'indexd': minor
3+
---
4+
5+
Added public key filtering for hosts and contracts. Closes https://github.com/SiaFoundation/indexd/issues/752
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
CommandGroup,
3+
CommandItemNav,
4+
CommandItemSearch,
5+
} from '../../../../../CmdRoot/Item'
6+
import { Page } from '../../../../../CmdRoot/types'
7+
import { useDialog } from '../../../../../../contexts/dialog'
8+
9+
export const contractsFilterPublicKeyPage = {
10+
namespace: 'contracts/filterPublicKey',
11+
label: 'Contracts filter by public key',
12+
}
13+
14+
export function PublicKeyCmdGroup({
15+
select,
16+
currentPage,
17+
}: {
18+
currentPage: Page
19+
select: () => void
20+
}) {
21+
const { openDialog } = useDialog()
22+
return (
23+
<CommandGroup
24+
currentPage={currentPage}
25+
commandPage={contractsFilterPublicKeyPage}
26+
>
27+
<CommandItemSearch
28+
currentPage={currentPage}
29+
commandPage={contractsFilterPublicKeyPage}
30+
onSelect={() => {
31+
select()
32+
openDialog('contractsFilterPublicKey')
33+
}}
34+
>
35+
Filter by host public key
36+
</CommandItemSearch>
37+
</CommandGroup>
38+
)
39+
}
40+
41+
export function PublicKeyCmdNav({
42+
select,
43+
currentPage,
44+
parentPage,
45+
commandPage,
46+
}: {
47+
currentPage: Page
48+
parentPage?: Page
49+
commandPage: Page
50+
select: () => void
51+
}) {
52+
const { openDialog } = useDialog()
53+
return (
54+
<CommandItemNav
55+
currentPage={currentPage}
56+
parentPage={parentPage}
57+
commandPage={commandPage}
58+
onSelect={() => {
59+
select()
60+
openDialog('contractsFilterPublicKey')
61+
}}
62+
>
63+
{contractsFilterPublicKeyPage.label}
64+
</CommandItemNav>
65+
)
66+
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { Page } from '../../../../../CmdRoot/types'
22
import { StatusCmdGroup } from './Status'
3+
import { PublicKeyCmdGroup } from './PublicKey'
34
import { ContractFilter } from '../../../types'
45

56
type Props = {
67
currentPage: Page
7-
select: (filter: ContractFilter) => void
8+
select: (filter?: ContractFilter) => void
89
}
910

1011
export function ContractFilterCmdGroups({ currentPage, select }: Props) {
1112
return (
12-
<StatusCmdGroup currentPage={currentPage} select={select} />
13+
<>
14+
<StatusCmdGroup currentPage={currentPage} select={select} />
15+
<PublicKeyCmdGroup currentPage={currentPage} select={select} />
16+
</>
1317
)
1418
}

apps/indexd/components/Data/Contracts/ContractsCmd/ContractsFilterCmd/ContractFilterNav/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CommandItemNav } from '../../../../../CmdRoot/Item'
22
import { Page } from '../../../../../CmdRoot/types'
33
import { contractsFilterStatusPage } from '../ContractFilterCmdGroups/Status'
4+
import { PublicKeyCmdNav } from '../ContractFilterCmdGroups/PublicKey'
45
import { ContractFilter } from '../../../types'
56

67
export const commandPage = {
@@ -12,16 +13,18 @@ type Props = {
1213
currentPage: Page
1314
parentPage?: Page
1415
pushPage: (page: Page) => void
15-
select: (filter: ContractFilter) => void
16+
select: (filter?: ContractFilter) => void
1617
}
1718

1819
export function ContractFilterNav({
1920
currentPage,
2021
parentPage,
2122
pushPage,
23+
select,
2224
}: Props) {
2325
return (
24-
<CommandItemNav
26+
<>
27+
<CommandItemNav
2528
currentPage={currentPage}
2629
parentPage={parentPage}
2730
commandPage={commandPage}
@@ -31,5 +34,12 @@ export function ContractFilterNav({
3134
>
3235
{contractsFilterStatusPage.label}
3336
</CommandItemNav>
37+
<PublicKeyCmdNav
38+
currentPage={currentPage}
39+
parentPage={parentPage}
40+
commandPage={commandPage}
41+
select={select}
42+
/>
43+
</>
3444
)
3545
}

apps/indexd/components/Data/Contracts/ContractsCmd/ContractsFilterCmd/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ export function ContractsFilterCmd({
2121
const { addColumnFilter } = useContractsParams()
2222

2323
const select = useCallback(
24-
(filter: ContractFilter) => {
24+
(filter?: ContractFilter) => {
2525
if (beforeSelect) {
2626
beforeSelect()
2727
}
28-
addColumnFilter(filter)
28+
if (filter) {
29+
addColumnFilter(filter)
30+
}
2931
if (afterSelect) {
3032
afterSelect()
3133
}

apps/indexd/components/Data/Contracts/types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AdminContractsSortBy, Contract } from '@siafoundation/indexd-types'
2+
import { truncate } from '@siafoundation/design-system'
23
import { CurrencyOption } from '@siafoundation/react-core'
34
import BigNumber from 'bignumber.js'
45
import {
@@ -17,7 +18,15 @@ export type ContractFilterRevisable = {
1718
value: boolean
1819
}
1920

20-
export type ContractFilter = ContractFilterStatus | ContractFilterRevisable
21+
export type ContractFilterPublicKey = {
22+
id: 'hostkey'
23+
value: string
24+
}
25+
26+
export type ContractFilter =
27+
| ContractFilterStatus
28+
| ContractFilterRevisable
29+
| ContractFilterPublicKey
2130
export type ContractFilters = ContractFilter[]
2231

2332
export type ContractSorts = DataTableSortColumn<AdminContractsSortBy>[]
@@ -29,6 +38,9 @@ export function getFilterLabel(filter: ContractFilter): string {
2938
if (filter.id === 'revisable') {
3039
return filter.value ? 'Revisable' : 'Not revisable'
3140
}
41+
if (filter.id === 'hostkey') {
42+
return `Public key is ${truncate(filter.value, 20)}`
43+
}
3244
return ''
3345
}
3446

apps/indexd/components/Data/Contracts/useContracts.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export function useContracts() {
2626
if (revisable !== undefined) {
2727
filters.revisable = revisable
2828
}
29+
const hostkey = columnFilters.find((f) => f.id === 'hostkey')?.value
30+
if (hostkey !== undefined) {
31+
filters.hostkey = [hostkey]
32+
}
2933
// Map all active sorts to API sortby and desc arrays.
3034
if (columnSorts.length > 0) {
3135
const sortby: AdminContractsSortBy[] = []
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
CommandGroup,
3+
CommandItemNav,
4+
CommandItemSearch,
5+
} from '../../../../../CmdRoot/Item'
6+
import { Page } from '../../../../../CmdRoot/types'
7+
import { useDialog } from '../../../../../../contexts/dialog'
8+
9+
export const hostsFilterPublicKeyPage = {
10+
namespace: 'hosts/filterPublicKey',
11+
label: 'Hosts filter by public key',
12+
}
13+
14+
export function PublicKeyCmdGroup({
15+
select,
16+
currentPage,
17+
}: {
18+
currentPage: Page
19+
select: () => void
20+
}) {
21+
const { openDialog } = useDialog()
22+
return (
23+
<CommandGroup
24+
currentPage={currentPage}
25+
commandPage={hostsFilterPublicKeyPage}
26+
>
27+
<CommandItemSearch
28+
currentPage={currentPage}
29+
commandPage={hostsFilterPublicKeyPage}
30+
onSelect={() => {
31+
select()
32+
openDialog('hostsFilterPublicKey')
33+
}}
34+
>
35+
Filter by public key
36+
</CommandItemSearch>
37+
</CommandGroup>
38+
)
39+
}
40+
41+
export function PublicKeyCmdNav({
42+
select,
43+
currentPage,
44+
parentPage,
45+
commandPage,
46+
}: {
47+
currentPage: Page
48+
parentPage?: Page
49+
commandPage: Page
50+
select: () => void
51+
}) {
52+
const { openDialog } = useDialog()
53+
return (
54+
<CommandItemNav
55+
currentPage={currentPage}
56+
parentPage={parentPage}
57+
commandPage={commandPage}
58+
onSelect={() => {
59+
select()
60+
openDialog('hostsFilterPublicKey')
61+
}}
62+
>
63+
{hostsFilterPublicKeyPage.label}
64+
</CommandItemNav>
65+
)
66+
}

apps/indexd/components/Data/Hosts/HostsCmd/HostsFilterCmd/HostFilterCmdGroups/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { Page } from '../../../../../CmdRoot/types'
22
import { UsableCmdGroup } from './Usable'
33
import { BlockedCmdGroup } from './Blocked'
44
import { ActiveContractsCmdGroup } from './ActiveContracts'
5+
import { PublicKeyCmdGroup } from './PublicKey'
56
import { HostFilter } from '../../../types'
67

78
type Props = {
89
currentPage: Page
9-
select: (filter: HostFilter) => void
10+
select: (filter?: HostFilter) => void
1011
}
1112

1213
export function HostFilterCmdGroups({ currentPage, select }: Props) {
@@ -15,6 +16,7 @@ export function HostFilterCmdGroups({ currentPage, select }: Props) {
1516
<UsableCmdGroup currentPage={currentPage} select={select} />
1617
<BlockedCmdGroup currentPage={currentPage} select={select} />
1718
<ActiveContractsCmdGroup currentPage={currentPage} select={select} />
19+
<PublicKeyCmdGroup currentPage={currentPage} select={select} />
1820
</>
1921
)
2022
}

apps/indexd/components/Data/Hosts/HostsCmd/HostsFilterCmd/HostFilterNav/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Page } from '../../../../../CmdRoot/types'
33
import { hostsFilterUsablePage } from '../HostFilterCmdGroups/Usable'
44
import { hostsFilterBlockedPage } from '../HostFilterCmdGroups/Blocked'
55
import { hostsFilterActiveContractsPage } from '../HostFilterCmdGroups/ActiveContracts'
6+
import { PublicKeyCmdNav } from '../HostFilterCmdGroups/PublicKey'
67
import { HostFilter } from '../../../types'
78

89
export const commandPage = {
@@ -14,10 +15,15 @@ type Props = {
1415
currentPage: Page
1516
parentPage?: Page
1617
pushPage: (page: Page) => void
17-
select: (filter: HostFilter) => void
18+
select: (filter?: HostFilter) => void
1819
}
1920

20-
export function HostFilterNav({ currentPage, parentPage, pushPage }: Props) {
21+
export function HostFilterNav({
22+
currentPage,
23+
parentPage,
24+
pushPage,
25+
select,
26+
}: Props) {
2127
return (
2228
<>
2329
<CommandItemNav
@@ -50,6 +56,12 @@ export function HostFilterNav({ currentPage, parentPage, pushPage }: Props) {
5056
>
5157
{hostsFilterActiveContractsPage.label}
5258
</CommandItemNav>
59+
<PublicKeyCmdNav
60+
currentPage={currentPage}
61+
parentPage={parentPage}
62+
commandPage={commandPage}
63+
select={select}
64+
/>
5365
</>
5466
)
5567
}

0 commit comments

Comments
 (0)