Skip to content

Commit

Permalink
refactor(renterd): migrate hosts apis
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Sep 16, 2024
1 parent 12d274b commit 0274a25
Show file tree
Hide file tree
Showing 24 changed files with 384 additions and 279 deletions.
6 changes: 6 additions & 0 deletions .changeset/early-bobcats-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'renterd': patch
'@siafoundation/renterd-react': patch
---

Fixed a bug optimistically updating last scan information when initiating a host scan.
5 changes: 5 additions & 0 deletions .changeset/eighty-eagles-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The hosts explorer now uses the new combined hosts API.
7 changes: 7 additions & 0 deletions .changeset/fair-carrots-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Added the bus list autopilots API.
7 changes: 7 additions & 0 deletions .changeset/late-onions-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Added new combined hosts API.
7 changes: 7 additions & 0 deletions .changeset/tiny-mails-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Removed deprecated search hosts and autopilot hosts APIs.
25 changes: 25 additions & 0 deletions apps/renterd-e2e/src/specs/hosts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test, expect } from '@playwright/test'
import { navigateToHosts } from '../fixtures/navigate'
import { afterTest, beforeTest } from '../fixtures/beforeTest'
import { getHostRowByIndex } from '../fixtures/hosts'

test.beforeEach(async ({ page }) => {
await beforeTest(page, {
hostdCount: 3,
})
})

test.afterEach(async () => {
await afterTest()
})

test('hosts explorer shows all hosts', async ({ page }) => {
await navigateToHosts({ page })

const row1 = await getHostRowByIndex(page, 0)
const row2 = await getHostRowByIndex(page, 1)
const row3 = await getHostRowByIndex(page, 2)
await expect(row1).toBeVisible()
await expect(row2).toBeVisible()
await expect(row3).toBeVisible()
})
9 changes: 9 additions & 0 deletions apps/renterd/contexts/app/useAutopilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { useAutopilotState } from '@siafoundation/renterd-react'
import { useEffect, useState } from 'react'

export function useAutopilot() {
// // Assume there is only one autopilot.
// const autopilots = useAutopilots({
// config: {
// swr: {
// revalidateOnFocus: false,
// },
// },
// })
// const id = autopilots.data?.[0]?.id
const state = useAutopilotState({
config: {
swr: {
Expand Down
6 changes: 3 additions & 3 deletions apps/renterd/contexts/config/useOnValid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { transformUp } from './transformUp'
import { delay, useMutate } from '@siafoundation/react-core'
import { Resources } from './resources'
import { useSyncContractSet } from './useSyncContractSet'
import { autopilotHostsRoute } from '@siafoundation/renterd-types'
import { busHostsRoute } from '@siafoundation/renterd-types'

export function useOnValid({
resources,
Expand Down Expand Up @@ -133,9 +133,9 @@ export function useOnValid({
if (firstTimeSettingConfig) {
const refreshHostsAfterDelay = async () => {
await delay(5_000)
mutate((key) => key.startsWith(autopilotHostsRoute))
mutate((key) => key.startsWith(busHostsRoute))
await delay(5_000)
mutate((key) => key.startsWith(autopilotHostsRoute))
mutate((key) => key.startsWith(busHostsRoute))
}
refreshHostsAfterDelay()
}
Expand Down
21 changes: 10 additions & 11 deletions apps/renterd/contexts/hosts/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { format, formatDistance, formatRelative } from 'date-fns'
import { HostContextMenu } from '../../components/Hosts/HostContextMenu'
import { useWorkflows } from '@siafoundation/react-core'
import {
AutopilotHost,
HostPriceTable,
HostSettings,
RhpScanPayload,
workerRhpScanRoute,
} from '@siafoundation/renterd-types'
Expand Down Expand Up @@ -135,15 +136,15 @@ export const columns: HostsTableColumn[] = (
return (
<Tooltip
side="right"
content={data.usable ? 'Host is usable' : 'Host is not usable'}
content={data.isUsable ? 'Host is usable' : 'Host is not usable'}
>
<div className="flex gap-2 items-center">
<div className="mt-[5px]">
<Text
aria-label={data.usable ? 'usable' : 'not usable'}
color={data.usable ? 'green' : 'red'}
aria-label={data.isUsable ? 'usable' : 'not usable'}
color={data.isUsable ? 'green' : 'red'}
>
{data.usable ? (
{data.isUsable ? (
<CheckboxCheckedFilled16 />
) : (
<WarningSquareFilled16 />
Expand Down Expand Up @@ -182,15 +183,15 @@ export const columns: HostsTableColumn[] = (
<Tooltip
side="right"
content={
data.gouging
data.isGouging
? 'Host is price gouging'
: 'Host is not price gouging'
}
>
<div className="flex gap-2 items-center">
<div className="mt-[5px]">
<Text color={!data.gouging ? 'subtle' : 'red'}>
{!data.gouging ? (
<Text color={!data.isGouging ? 'subtle' : 'red'}>
{!data.isGouging ? (
<UndefinedFilled16 />
) : (
<WarningSquareFilled16 />
Expand Down Expand Up @@ -1078,9 +1079,7 @@ function getFullLabelAndTip(col: HostsTableColumn): {
}
}

type Key =
| keyof AutopilotHost['host']['priceTable']
| keyof AutopilotHost['host']['settings']
type Key = keyof HostPriceTable | keyof HostSettings

function makeRenderSc(section: 'priceTable' | 'settings', name: Key) {
return memo(function RenderPriceTableNumber({ data }: { data: HostData }) {
Expand Down
Loading

0 comments on commit 0274a25

Please sign in to comment.