Skip to content

Commit

Permalink
refactor(renterd): autopilot move from configured to enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Nov 27, 2024
1 parent d8297d1 commit 82976a7
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 351 deletions.
7 changes: 7 additions & 0 deletions .changeset/dirty-pianos-laugh.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
---

The configured boolean was removed from AutopilotState.
5 changes: 5 additions & 0 deletions .changeset/five-fireants-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

Uploading files is no longer disabled if the user has not configured their settings.
5 changes: 5 additions & 0 deletions .changeset/forty-months-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The configuration page navbar now has a switch for enabling or disabling autopilot.
5 changes: 5 additions & 0 deletions .changeset/honest-rats-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The configuration no longer fills Sia Central network averages for max prices during first time configuration.
5 changes: 5 additions & 0 deletions .changeset/selfish-lemons-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The file explorer warnings now include a warning for when autopilot is disabled, the warning relating to configuration status was removed.
5 changes: 5 additions & 0 deletions .changeset/shy-chicken-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The onboarding bar no longer shows depending on the status of configuration but the first step still suggests configuring settings and enabling autopilot.
5 changes: 5 additions & 0 deletions .changeset/sweet-chicken-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

If the autopilot is disabling a warning will appear on the bottom dock. The widget includes a switch for re-enabling the autopilot.
10 changes: 9 additions & 1 deletion apps/renterd/components/Config/ConfigNav.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { ConfigEnabledSwitch } from '../ConfigEnabledSwitch'

export function ConfigNav() {
return <div className="pl-1"></div>
return (
<div className="pl-1">
<div className="flex items-center gap-2">
<ConfigEnabledSwitch size="small" />
</div>
</div>
)
}
39 changes: 39 additions & 0 deletions apps/renterd/components/ConfigEnabledSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Switch, Tooltip } from '@siafoundation/design-system'
import {
useAutopilotConfig,
useAutopilotConfigUpdate,
} from '@siafoundation/renterd-react'
import { useCallback } from 'react'

type Props = {
size: 'small' | 'medium'
}

export function ConfigEnabledSwitch({ size }: Props) {
const autopilotConfigUpdate = useAutopilotConfigUpdate()
const autopilotConfig = useAutopilotConfig()

const toggleEnabled = useCallback(() => {
if (!autopilotConfig.data) {
return
}
autopilotConfigUpdate.put({
payload: {
...autopilotConfig.data,
enabled: !autopilotConfig.data?.enabled,
},
})
}, [autopilotConfig.data, autopilotConfigUpdate])

return (
<Tooltip content="Enable or disable the system autopilot which handles forming contracts and maintaining files.">
<div>
<Switch
size={size}
checked={!!autopilotConfig.data?.enabled}
onCheckedChange={toggleEnabled}
/>
</div>
</Tooltip>
)
}
2 changes: 2 additions & 0 deletions apps/renterd/components/DockedControls.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react'
import { OnboardingBar } from './OnboardingBar'
import { TransfersBar } from './TransfersBar'
import { EnabledBar } from './EnabledBar'

export function DockedControls({ children }: { children?: React.ReactNode }) {
return (
<div className="flex flex-col gap-2">
{children}
<TransfersBar />
<OnboardingBar />
<EnabledBar />
</div>
)
}
38 changes: 38 additions & 0 deletions apps/renterd/components/EnabledBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { AppDockedControl, Panel, Text } from '@siafoundation/design-system'
import { useAutopilotConfig } from '@siafoundation/renterd-react'
import { ConfigEnabledSwitch } from './ConfigEnabledSwitch'
import { Warning24 } from '@carbon/icons-react'

export function EnabledBar() {
const autopilotConfig = useAutopilotConfig()

if (!autopilotConfig.data) {
return <AppDockedControl />
}

if (autopilotConfig.data.enabled) {
return <AppDockedControl />
}

return (
<AppDockedControl>
<div className="flex justify-center">
<Panel className="w-[400px] flex flex-col gap-2 max-h-[600px] p-3">
<div className="flex gap-1 items-center">
<Text size="18" weight="medium" color="contrast">
<Warning24 />
</Text>
<Text size="18" weight="medium" color="contrast">
Autopilot is currently disabled
</Text>
<div className="flex-1" />
<ConfigEnabledSwitch size="medium" />
</div>
<Text size="12" color="subtle">
Enable autopilot to form contracts and maintain files.
</Text>
</Panel>
</div>
</AppDockedControl>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Button,
Code,
Paragraph,
Popover,
Separator,
Expand All @@ -9,12 +8,12 @@ import {
import { Warning16 } from '@siafoundation/react-icons'
import { useMemo } from 'react'
import { useSyncStatus } from '../../../hooks/useSyncStatus'
import { useAutopilotNotConfigured } from '../checks/useAutopilotNotConfigured'
import { useAutopilotNotEnabled } from '../checks/useAutopilotNotConfigured'
import { useNotEnoughContracts } from '../checks/useNotEnoughContracts'

export function FilesStatsMenuWarnings() {
const syncStatus = useSyncStatus()
const autopilotNotConfigured = useAutopilotNotConfigured()
const autopilotNotEnabled = useAutopilotNotEnabled()
const notEnoughContracts = useNotEnoughContracts()

const syncStatusEl = useMemo(() => {
Expand All @@ -34,24 +33,22 @@ export function FilesStatsMenuWarnings() {
return null
}, [syncStatus.isSynced])

const autopilotNotConfiguredEl = useMemo(() => {
if (autopilotNotConfigured.active) {
const autopilotNotEnabledEl = useMemo(() => {
if (autopilotNotEnabled.active) {
return (
<div key="autopilotNotConfigured" className="flex flex-col gap-1">
<Text size="12" font="mono" weight="medium" color="amber">
Uploads are disabled until settings are configured.
Autopilot is currently disabled.
</Text>
<Paragraph size="12">
Before you can upload files you must configure your settings. Once
configured, <Code>renterd</Code> will find contracts with hosts
based on the settings you choose. <Code>renterd</Code> will also
repair your data as hosts come and go.
Files and contracts will not be automatically maintained while
autopilot is disabled.
</Paragraph>
</div>
)
}
return null
}, [autopilotNotConfigured.active])
}, [autopilotNotEnabled.active])

const notEnoughContractsEl = useMemo(() => {
if (notEnoughContracts.active) {
Expand All @@ -73,10 +70,10 @@ export function FilesStatsMenuWarnings() {

const warningList = useMemo(
() =>
[syncStatusEl, autopilotNotConfiguredEl, notEnoughContractsEl].filter(
[syncStatusEl, autopilotNotEnabledEl, notEnoughContractsEl].filter(
Boolean
),
[syncStatusEl, autopilotNotConfiguredEl, notEnoughContractsEl]
[syncStatusEl, autopilotNotEnabledEl, notEnoughContractsEl]
)

if (warningList.length)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useAutopilotState } from '@siafoundation/renterd-react'
import { useAutopilotConfig } from '@siafoundation/renterd-react'

export function useAutopilotNotConfigured() {
const autopilotState = useAutopilotState()
export function useAutopilotNotEnabled() {
const autopilotConfig = useAutopilotConfig()
return {
active: !autopilotState.data?.configured,
active: !autopilotConfig.data?.enabled,
}
}
9 changes: 1 addition & 8 deletions apps/renterd/components/Files/useCanUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { useSyncStatus } from '../../hooks/useSyncStatus'
import { useFilesManager } from '../../contexts/filesManager'
import { useAutopilotNotConfigured } from './checks/useAutopilotNotConfigured'
import { useNotEnoughContracts } from './checks/useNotEnoughContracts'

export function useCanUpload() {
const { isViewingABucket } = useFilesManager()
const syncStatus = useSyncStatus()
const autopilotNotConfigured = useAutopilotNotConfigured()
const notEnoughContracts = useNotEnoughContracts()
return (
isViewingABucket &&
!autopilotNotConfigured.active &&
!notEnoughContracts.active &&
syncStatus.isSynced
)
return isViewingABucket && !notEnoughContracts.active && syncStatus.isSynced
}
12 changes: 6 additions & 6 deletions apps/renterd/components/FilesDirectory/EmptyState/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Code, LinkButton, Text } from '@siafoundation/design-system'
import { CloudUpload32 } from '@siafoundation/react-icons'
import { routes } from '../../../config/routes'
import { useFilesDirectory } from '../../../contexts/filesDirectory'
import { useAutopilotNotConfigured } from '../../Files/checks/useAutopilotNotConfigured'
import { useAutopilotNotEnabled } from '../../Files/checks/useAutopilotNotConfigured'
import { useNotEnoughContracts } from '../../Files/checks/useNotEnoughContracts'
import { StateError } from './StateError'
import { StateNoneMatching } from './StateNoneMatching'
Expand All @@ -14,7 +14,7 @@ export function EmptyState() {
const { isViewingRootOfABucket, isViewingBuckets } = useFilesManager()
const { dataState } = useFilesDirectory()

const autopilotNotConfigured = useAutopilotNotConfigured()
const autopilotNotEnabled = useAutopilotNotEnabled()
const notEnoughContracts = useNotEnoughContracts()

if (dataState === 'noneMatchingFilters') {
Expand All @@ -29,7 +29,7 @@ export function EmptyState() {
if (
isViewingRootOfABucket &&
dataState === 'noneYet' &&
autopilotNotConfigured.active
autopilotNotEnabled.active
) {
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px] cursor-pointer">
Expand All @@ -38,9 +38,9 @@ export function EmptyState() {
</Text>
<div className="flex flex-col gap-6 justify-center items-center">
<Text color="subtle" className="text-center max-w-[500px]">
Before you can upload files you must configure your settings. Once
configured, <Code>renterd</Code> will find contracts with hosts
based on the settings you choose. <Code>renterd</Code> will also
Before you can upload files you must configure and enable your
settings. Once enabled, <Code>renterd</Code> will find contracts
with hosts based on the settings. <Code>renterd</Code> will also
repair your data as hosts come and go.
</Text>
<LinkButton variant="accent" href={routes.config.index}>
Expand Down
26 changes: 7 additions & 19 deletions apps/renterd/components/OnboardingBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useSyncStatus } from '../hooks/useSyncStatus'
import { routes } from '../config/routes'
import { useDialog } from '../contexts/dialog'
import { useNotEnoughContracts } from './Files/checks/useNotEnoughContracts'
import { useAutopilotState, useWallet } from '@siafoundation/renterd-react'
import { useWallet } from '@siafoundation/renterd-react'
import BigNumber from 'bignumber.js'
import { humanSiacoin } from '@siafoundation/units'
import { useAppSettings } from '@siafoundation/react-core'
Expand All @@ -28,7 +28,6 @@ import { useSpendingEstimate } from '../contexts/config/useSpendingEstimate'

export function OnboardingBar() {
const { isUnlockedAndAuthedRoute } = useAppSettings()
const autopilotState = useAutopilotState()
const { openDialog } = useDialog()
const wallet = useWallet()
const [maximized, setMaximized] = useLocalStorageState<boolean>(
Expand All @@ -50,7 +49,7 @@ export function OnboardingBar() {
wallet.data ? wallet.data.confirmed + wallet.data.unconfirmed : 0
)

const step1Configured = autopilotState.data?.configured
const step1Configured = true
const step2Synced = syncStatus.isSynced
const step3Funded = walletBalance.gt(0)
const step4Contracts = !notEnoughContracts.active
Expand Down Expand Up @@ -97,27 +96,16 @@ export function OnboardingBar() {
size="14"
underline="hover"
>
Step 1: Configure your storage settings
Step 1: Configure and enable your storage settings
</Link>
}
description={
'Specify how much data you plan to store and your target price.'
'Specify your estimated usage and maximum pricing values and then enable the settings.'
}
action={
step1Configured ? (
<Text color="green">
<CheckmarkFilled16 />
</Text>
) : (
<>
<Link href={routes.config.index}>
<Launch16 />
</Link>
<Text color="amber">
<RadioButton16 />
</Text>
</>
)
<Link href={routes.config.index}>
<Launch16 />
</Link>
}
/>
<Section
Expand Down
Loading

0 comments on commit 82976a7

Please sign in to comment.