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 11, 2024
1 parent ff5dc11 commit 9c5242c
Show file tree
Hide file tree
Showing 19 changed files with 318 additions and 297 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.
12 changes: 11 additions & 1 deletion apps/renterd/contexts/app/useAutopilot.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { secondsInMilliseconds } from '@siafoundation/units'
import { useAutopilotState } from '@siafoundation/renterd-react'
import { useAutopilotState, useAutopilots } 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 Expand Up @@ -31,6 +40,7 @@ export function useAutopilot() {
}, [state])

return {
id: id || 'autopilot',
status,
state,
}
Expand Down
78 changes: 39 additions & 39 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 @@ -198,7 +199,7 @@ export const columns: HostsTableColumn[] = (
</Text>
</div>
<div className="flex flex-col">
{Object.entries(data.gougingBreakdown)
{Object.entries(data.gouging)
.filter(([_, reason]) => reason && typeof reason === 'string')
.map(([key, reason]) => (
<Text key={key} size="10" noWrap>
Expand Down Expand Up @@ -451,29 +452,30 @@ export const columns: HostsTableColumn[] = (
/>
),
},
{
id: 'ap_scoreOverall',
label: 'overall score',
category: 'autopilot',
contentClassName: 'w-[120px] justify-end',
render: ({ data, context }) => {
if (!context.isAutopilotConfigured) {
return (
<Tooltip content="Autopilot is not configured">
<Text color="verySubtle">-</Text>
</Tooltip>
)
}
return (
<ValueNum
size="12"
value={data.score}
variant="value"
format={(v) => v.toPrecision(2)}
/>
)
},
},
// TODO?
// {
// id: 'ap_scoreOverall',
// label: 'overall score',
// category: 'autopilot',
// contentClassName: 'w-[120px] justify-end',
// render: ({ data, context }) => {
// if (!context.isAutopilotConfigured) {
// return (
// <Tooltip content="Autopilot is not configured">
// <Text color="verySubtle">-</Text>
// </Tooltip>
// )
// }
// return (
// <ValueNum
// size="12"
// value={data.score}
// variant="value"
// format={(v) => v.toPrecision(2)}
// />
// )
// },
// },
{
id: 'ap_scoreAge',
label: 'age score',
Expand All @@ -490,7 +492,7 @@ export const columns: HostsTableColumn[] = (
return (
<ValueNum
size="12"
value={data.scoreBreakdown.age}
value={data.score.age}
variant="value"
format={(v) => v.toPrecision(2)}
/>
Expand All @@ -513,7 +515,7 @@ export const columns: HostsTableColumn[] = (
return (
<ValueNum
size="12"
value={data.scoreBreakdown.collateral}
value={data.score.collateral}
variant="value"
format={(v) => v.toPrecision(2)}
/>
Expand All @@ -536,7 +538,7 @@ export const columns: HostsTableColumn[] = (
return (
<ValueNum
size="12"
value={data.scoreBreakdown.interactions}
value={data.score.interactions}
variant="value"
format={(v) => v.toPrecision(2)}
/>
Expand All @@ -559,7 +561,7 @@ export const columns: HostsTableColumn[] = (
return (
<ValueNum
size="12"
value={data.scoreBreakdown.prices}
value={data.score.prices}
variant="value"
format={(v) => v.toPrecision(2)}
/>
Expand All @@ -582,7 +584,7 @@ export const columns: HostsTableColumn[] = (
return (
<ValueNum
size="12"
value={data.scoreBreakdown.storageRemaining}
value={data.score.storageRemaining}
variant="value"
format={(v) => v.toPrecision(2)}
/>
Expand All @@ -605,7 +607,7 @@ export const columns: HostsTableColumn[] = (
return (
<ValueNum
size="12"
value={data.scoreBreakdown.uptime}
value={data.score.uptime}
variant="value"
format={(v) => v.toPrecision(2)}
/>
Expand All @@ -628,7 +630,7 @@ export const columns: HostsTableColumn[] = (
return (
<ValueNum
size="12"
value={data.scoreBreakdown.version}
value={data.score.version}
variant="value"
format={(v) =>
context.isAutopilotConfigured ? '-' : v.toPrecision(2)
Expand Down Expand Up @@ -1078,9 +1080,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 9c5242c

Please sign in to comment.