From f669717bdcc8b9808a0a90f5ce4d8d72f4483495 Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Fri, 18 Aug 2023 15:28:56 -0400 Subject: [PATCH] feat: renterd autopilot and not enough contract onboarding --- .changeset/dull-readers-sit.md | 5 + .changeset/odd-pillows-try.md | 5 + apps/renterd/components/Files/EmptyState.tsx | 79 +++++++ .../components/Files/FilesActionsMenu.tsx | 7 +- .../components/Files/FilesExplorer.tsx | 22 +- .../FilesStatsMenu/FilesStatsMenuWarnings.tsx | 198 ++++++++++-------- .../checks/useAutopilotNotConfigured.tsx | 17 ++ .../Files/checks/useContractSetMismatch.tsx | 15 ++ .../checks/useDefaultContractSetNotSet.tsx | 9 + .../Files/checks/useNotEnoughContracts.tsx | 22 ++ .../renterd/components/Files/useCanUpload.tsx | 8 + apps/renterd/contexts/hosts/index.tsx | 2 +- libs/react-renterd/src/worker.ts | 2 +- 13 files changed, 284 insertions(+), 107 deletions(-) create mode 100644 .changeset/dull-readers-sit.md create mode 100644 .changeset/odd-pillows-try.md create mode 100644 apps/renterd/components/Files/EmptyState.tsx create mode 100644 apps/renterd/components/Files/checks/useAutopilotNotConfigured.tsx create mode 100644 apps/renterd/components/Files/checks/useContractSetMismatch.tsx create mode 100644 apps/renterd/components/Files/checks/useDefaultContractSetNotSet.tsx create mode 100644 apps/renterd/components/Files/checks/useNotEnoughContracts.tsx create mode 100644 apps/renterd/components/Files/useCanUpload.tsx diff --git a/.changeset/dull-readers-sit.md b/.changeset/dull-readers-sit.md new file mode 100644 index 000000000..bc4f2da89 --- /dev/null +++ b/.changeset/dull-readers-sit.md @@ -0,0 +1,5 @@ +--- +'renterd': minor +--- + +File upload and directory creation are now disabled until enough contracts are formed. diff --git a/.changeset/odd-pillows-try.md b/.changeset/odd-pillows-try.md new file mode 100644 index 000000000..dc077238c --- /dev/null +++ b/.changeset/odd-pillows-try.md @@ -0,0 +1,5 @@ +--- +'renterd': minor +--- + +New users are now more clearly instructed to configure autopilot and to wait for enough contracts before files can be uploaded. diff --git a/apps/renterd/components/Files/EmptyState.tsx b/apps/renterd/components/Files/EmptyState.tsx new file mode 100644 index 000000000..18175ca67 --- /dev/null +++ b/apps/renterd/components/Files/EmptyState.tsx @@ -0,0 +1,79 @@ +import { CloudUpload32, LinkButton, Text } from '@siafoundation/design-system' +import { routes } from '../../config/routes' +import { useFiles } from '../../contexts/files' +import { useAutopilotNotConfigured } from './checks/useAutopilotNotConfigured' +import { useNotEnoughContracts } from './checks/useNotEnoughContracts' +import { StateError } from './StateError' +import { StateNoneMatching } from './StateNoneMatching' +import { StateNoneYet } from './StateNoneYet' + +export function EmptyState() { + const { dataState, activeDirectoryPath } = useFiles() + + const autopilotNotConfigured = useAutopilotNotConfigured() + const notEnoughContracts = useNotEnoughContracts() + + if (dataState === 'noneMatchingFilters') { + return + } + + if (dataState === 'error') { + return + } + + // only show on root directory and when there are no files + if ( + activeDirectoryPath === '/' && + dataState === 'noneYet' && + autopilotNotConfigured.active + ) { + return ( +
+ + + +
+ + Before you can upload files you must configure autopilot. Autopilot + finds contracts with hosts based on the settings you choose. + Autopilot also repairs your data as hosts come and go. + + + Configure autopilot → + +
+
+ ) + } + + // only show on root directory and when there are no files + if ( + activeDirectoryPath === '/' && + dataState === 'noneYet' && + notEnoughContracts.active + ) { + return ( +
+ + + +
+ + There are not enough contracts to upload data yet. Redundancy is + configured to use {notEnoughContracts.required} shards which means + at least that many contracts are required. + + + {notEnoughContracts.count}/{notEnoughContracts.required} + +
+
+ ) + } + + if (dataState === 'noneYet') { + return + } + + return null +} diff --git a/apps/renterd/components/Files/FilesActionsMenu.tsx b/apps/renterd/components/Files/FilesActionsMenu.tsx index aeab2e015..8694f8482 100644 --- a/apps/renterd/components/Files/FilesActionsMenu.tsx +++ b/apps/renterd/components/Files/FilesActionsMenu.tsx @@ -8,13 +8,17 @@ import { useFiles } from '../../contexts/files' import { useDropzone } from 'react-dropzone' import { FilesViewDropdownMenu } from './FilesViewDropdownMenu' import { useDialog } from '../../contexts/dialog' +import { useCanUpload } from './useCanUpload' export function FilesActionsMenu() { const { openDialog } = useDialog() const { uploadFiles } = useFiles() + const canUpload = useCanUpload() + const { getRootProps, getInputProps } = useDropzone({ noDrag: true, + noClick: !canUpload, onDrop: uploadFiles, }) @@ -23,11 +27,12 @@ export function FilesActionsMenu() { -