Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/purple-impalas-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'indexd': minor
---

Added public key filtering for hosts and contracts. Closes https://github.com/SiaFoundation/indexd/issues/752
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
CommandGroup,
CommandItemNav,
CommandItemSearch,
} from '../../../../../CmdRoot/Item'
import { Page } from '../../../../../CmdRoot/types'
import { useDialog } from '../../../../../../contexts/dialog'

export const contractsFilterPublicKeyPage = {
namespace: 'contracts/filterPublicKey',
label: 'Contracts filter by public key',
}

export function PublicKeyCmdGroup({
select,
currentPage,
}: {
currentPage: Page
select: () => void
}) {
const { openDialog } = useDialog()
return (
<CommandGroup
currentPage={currentPage}
commandPage={contractsFilterPublicKeyPage}
>
<CommandItemSearch
currentPage={currentPage}
commandPage={contractsFilterPublicKeyPage}
onSelect={() => {
select()
openDialog('contractsFilterPublicKey')
}}
>
Filter by host public key
</CommandItemSearch>
</CommandGroup>
)
}

export function PublicKeyCmdNav({
select,
currentPage,
parentPage,
commandPage,
}: {
currentPage: Page
parentPage?: Page
commandPage: Page
select: () => void
}) {
const { openDialog } = useDialog()
return (
<CommandItemNav
currentPage={currentPage}
parentPage={parentPage}
commandPage={commandPage}
onSelect={() => {
select()
openDialog('contractsFilterPublicKey')
}}
>
{contractsFilterPublicKeyPage.label}
</CommandItemNav>
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Page } from '../../../../../CmdRoot/types'
import { StatusCmdGroup } from './Status'
import { PublicKeyCmdGroup } from './PublicKey'
import { ContractFilter } from '../../../types'

type Props = {
currentPage: Page
select: (filter: ContractFilter) => void
select: (filter?: ContractFilter) => void
}

export function ContractFilterCmdGroups({ currentPage, select }: Props) {
return (
<StatusCmdGroup currentPage={currentPage} select={select} />
<>
<StatusCmdGroup currentPage={currentPage} select={select} />
<PublicKeyCmdGroup currentPage={currentPage} select={select} />
</>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CommandItemNav } from '../../../../../CmdRoot/Item'
import { Page } from '../../../../../CmdRoot/types'
import { contractsFilterStatusPage } from '../ContractFilterCmdGroups/Status'
import { PublicKeyCmdNav } from '../ContractFilterCmdGroups/PublicKey'
import { ContractFilter } from '../../../types'

export const commandPage = {
Expand All @@ -12,16 +13,18 @@ type Props = {
currentPage: Page
parentPage?: Page
pushPage: (page: Page) => void
select: (filter: ContractFilter) => void
select: (filter?: ContractFilter) => void
}

export function ContractFilterNav({
currentPage,
parentPage,
pushPage,
select,
}: Props) {
return (
<CommandItemNav
<>
<CommandItemNav
currentPage={currentPage}
parentPage={parentPage}
commandPage={commandPage}
Expand All @@ -31,5 +34,12 @@ export function ContractFilterNav({
>
{contractsFilterStatusPage.label}
</CommandItemNav>
<PublicKeyCmdNav
currentPage={currentPage}
parentPage={parentPage}
commandPage={commandPage}
select={select}
/>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export function ContractsFilterCmd({
const { addColumnFilter } = useContractsParams()

const select = useCallback(
(filter: ContractFilter) => {
(filter?: ContractFilter) => {
if (beforeSelect) {
beforeSelect()
}
addColumnFilter(filter)
if (filter) {
addColumnFilter(filter)
}
if (afterSelect) {
afterSelect()
}
Expand Down
14 changes: 13 additions & 1 deletion apps/indexd/components/Data/Contracts/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AdminContractsSortBy, Contract } from '@siafoundation/indexd-types'
import { truncate } from '@siafoundation/design-system'
import { CurrencyOption } from '@siafoundation/react-core'
import BigNumber from 'bignumber.js'
import {
Expand All @@ -17,7 +18,15 @@ export type ContractFilterRevisable = {
value: boolean
}

export type ContractFilter = ContractFilterStatus | ContractFilterRevisable
export type ContractFilterPublicKey = {
id: 'hostkey'
value: string
}

export type ContractFilter =
| ContractFilterStatus
| ContractFilterRevisable
| ContractFilterPublicKey
export type ContractFilters = ContractFilter[]

export type ContractSorts = DataTableSortColumn<AdminContractsSortBy>[]
Expand All @@ -29,6 +38,9 @@ export function getFilterLabel(filter: ContractFilter): string {
if (filter.id === 'revisable') {
return filter.value ? 'Revisable' : 'Not revisable'
}
if (filter.id === 'hostkey') {
return `Public key is ${truncate(filter.value, 20)}`
}
return ''
}

Expand Down
4 changes: 4 additions & 0 deletions apps/indexd/components/Data/Contracts/useContracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function useContracts() {
if (revisable !== undefined) {
filters.revisable = revisable
}
const hostkey = columnFilters.find((f) => f.id === 'hostkey')?.value
if (hostkey !== undefined) {
filters.hostkey = [hostkey]
}
// Map all active sorts to API sortby and desc arrays.
if (columnSorts.length > 0) {
const sortby: AdminContractsSortBy[] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
CommandGroup,
CommandItemNav,
CommandItemSearch,
} from '../../../../../CmdRoot/Item'
import { Page } from '../../../../../CmdRoot/types'
import { useDialog } from '../../../../../../contexts/dialog'

export const hostsFilterPublicKeyPage = {
namespace: 'hosts/filterPublicKey',
label: 'Hosts filter by public key',
}

export function PublicKeyCmdGroup({
select,
currentPage,
}: {
currentPage: Page
select: () => void
}) {
const { openDialog } = useDialog()
return (
<CommandGroup
currentPage={currentPage}
commandPage={hostsFilterPublicKeyPage}
>
<CommandItemSearch
currentPage={currentPage}
commandPage={hostsFilterPublicKeyPage}
onSelect={() => {
select()
openDialog('hostsFilterPublicKey')
}}
>
Filter by public key
</CommandItemSearch>
</CommandGroup>
)
}

export function PublicKeyCmdNav({
select,
currentPage,
parentPage,
commandPage,
}: {
currentPage: Page
parentPage?: Page
commandPage: Page
select: () => void
}) {
const { openDialog } = useDialog()
return (
<CommandItemNav
currentPage={currentPage}
parentPage={parentPage}
commandPage={commandPage}
onSelect={() => {
select()
openDialog('hostsFilterPublicKey')
}}
>
{hostsFilterPublicKeyPage.label}
</CommandItemNav>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { Page } from '../../../../../CmdRoot/types'
import { UsableCmdGroup } from './Usable'
import { BlockedCmdGroup } from './Blocked'
import { ActiveContractsCmdGroup } from './ActiveContracts'
import { PublicKeyCmdGroup } from './PublicKey'
import { HostFilter } from '../../../types'

type Props = {
currentPage: Page
select: (filter: HostFilter) => void
select: (filter?: HostFilter) => void
}

export function HostFilterCmdGroups({ currentPage, select }: Props) {
Expand All @@ -15,6 +16,7 @@ export function HostFilterCmdGroups({ currentPage, select }: Props) {
<UsableCmdGroup currentPage={currentPage} select={select} />
<BlockedCmdGroup currentPage={currentPage} select={select} />
<ActiveContractsCmdGroup currentPage={currentPage} select={select} />
<PublicKeyCmdGroup currentPage={currentPage} select={select} />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Page } from '../../../../../CmdRoot/types'
import { hostsFilterUsablePage } from '../HostFilterCmdGroups/Usable'
import { hostsFilterBlockedPage } from '../HostFilterCmdGroups/Blocked'
import { hostsFilterActiveContractsPage } from '../HostFilterCmdGroups/ActiveContracts'
import { PublicKeyCmdNav } from '../HostFilterCmdGroups/PublicKey'
import { HostFilter } from '../../../types'

export const commandPage = {
Expand All @@ -14,10 +15,15 @@ type Props = {
currentPage: Page
parentPage?: Page
pushPage: (page: Page) => void
select: (filter: HostFilter) => void
select: (filter?: HostFilter) => void
}

export function HostFilterNav({ currentPage, parentPage, pushPage }: Props) {
export function HostFilterNav({
currentPage,
parentPage,
pushPage,
select,
}: Props) {
return (
<>
<CommandItemNav
Expand Down Expand Up @@ -50,6 +56,12 @@ export function HostFilterNav({ currentPage, parentPage, pushPage }: Props) {
>
{hostsFilterActiveContractsPage.label}
</CommandItemNav>
<PublicKeyCmdNav
currentPage={currentPage}
parentPage={parentPage}
commandPage={commandPage}
select={select}
/>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export function HostsFilterCmd({
const { addColumnFilter } = useHostsParams()

const select = useCallback(
(filter: HostFilter) => {
(filter?: HostFilter) => {
if (beforeSelect) {
beforeSelect()
}
addColumnFilter(filter)
if (filter) {
addColumnFilter(filter)
}
if (afterSelect) {
afterSelect()
}
Expand Down
9 changes: 9 additions & 0 deletions apps/indexd/components/Data/Hosts/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AdminHostsSortBy, Host } from '@siafoundation/indexd-types'
import { truncate } from '@siafoundation/design-system'
import { CurrencyOption } from '@siafoundation/react-core'
import BigNumber from 'bignumber.js'
import {
Expand All @@ -21,10 +22,16 @@ export type HostFilterActiveContracts = {
value: boolean
}

export type HostFilterPublicKey = {
id: 'hostkey'
value: string
}

export type HostFilter =
| HostFilterUsable
| HostFilterBlocked
| HostFilterActiveContracts
| HostFilterPublicKey
export type HostFilters = HostFilter[]

export type HostSorts = DataTableSortColumn<AdminHostsSortBy>[]
Expand All @@ -37,6 +44,8 @@ export function getFilterLabel(filter: HostFilter): string {
return filter.value ? 'Blocked' : 'Not Blocked'
case 'activecontracts':
return filter.value ? 'Active Contracts' : 'No Active Contracts'
case 'hostkey':
return `Public key is ${truncate(filter.value, 20)}`
default:
return ''
}
Expand Down
4 changes: 4 additions & 0 deletions apps/indexd/components/Data/Hosts/useHosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export function useHosts() {
if (activecontracts !== undefined) {
filters.activecontracts = activecontracts
}
const hostkey = columnFilters.find((f) => f.id === 'hostkey')?.value
if (hostkey !== undefined) {
filters.hostkey = [hostkey]
}
// Map all active sorts to API sortby and desc arrays.
if (columnSorts.length > 0) {
const sortby: AdminHostsSortBy[] = []
Expand Down
Loading
Loading