Skip to content

Commit

Permalink
refactor(renterd): typescript strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Sep 20, 2024
1 parent 8c93f0a commit d710788
Show file tree
Hide file tree
Showing 106 changed files with 1,204 additions and 780 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"GOOS": "js",
"GOARCH": "wasm"
}
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion apps/hostd/contexts/config/fields.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/no-unescaped-entities */
import { blocksToMonths } from '@siafoundation/units'
import { ConfigFields } from '@siafoundation/design-system'
import { ConfigFields, Maybe } from '@siafoundation/design-system'
import BigNumber from 'bignumber.js'
import {
ConfigViewMode,
Expand Down
7 changes: 4 additions & 3 deletions apps/hostd/dialogs/VolumeCreateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function getFields(
validation: {
required: 'required',
validate: {
req: (value) => value !== '\\' || 'directory within a drive required',
req: (value: string) =>
value !== '\\' || 'directory within a drive required',
},
},
},
Expand All @@ -80,11 +81,11 @@ function getFields(
validation: {
required: 'required',
validate: {
between: (value: number) => {
between: (value: BigNumber) => {
const error = `Must be between ${humanBytes(
GBToBytes(minSizeGB)
)} and ${humanBytes(GBToBytes(maxSizeGB), { fixed: 3 })}`
return (value <= maxSizeGB && value >= minSizeGB) || error
return (value.lte(maxSizeGB) && value.gte(minSizeGB)) || error
},
nospace: () =>
maxSizeGB > minSizeGB || 'not enough space in directory',
Expand Down
7 changes: 6 additions & 1 deletion apps/renterd/components/Alerts/AlertsFilterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export function AlertsFilterMenu() {
{!dataState && !!pageCount && (
<Button
tip={severityFilter ? `dismiss ${pageCount}` : 'dismiss all'}
onClick={() => dismissMany(datasetPage.map((a) => a.id))}
onClick={() => {
if (!datasetPage) {
return
}
dismissMany(datasetPage.map((a) => a.id))
}}
>
<Checkmark16 />
Dismiss ({pageCount})
Expand Down
2 changes: 0 additions & 2 deletions apps/renterd/components/Alerts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function Alerts() {
toggleSort,
limit,
dataState,
cellContext,
} = useAlerts()

return (
Expand All @@ -35,7 +34,6 @@ export function Alerts() {
>
<div className="p-6 min-w-fit">
<Table
context={cellContext}
isLoading={dataState === 'loading'}
emptyState={
dataState === 'noneMatchingFilters' ? (
Expand Down
8 changes: 4 additions & 4 deletions apps/renterd/components/CmdRoot/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export function CommandItemNav({
}: React.ComponentProps<typeof Command.Item> & {
currentPage?: Page
parentPage?: Page
commandPage: Page
commandPage?: Page
}) {
const search = useCommandState((state) => state.search)
// show if user is on parent page and not searching
if (parentPage?.namespace === currentPage?.namespace && !search)
return (
<Command.Item
className={cx(itemStyles(), 'group', className)}
value={`${commandPage?.label} ${props.children.toString()}`}
value={`${commandPage?.label} ${props.children?.toString() || ''}`}
{...props}
/>
)
Expand All @@ -48,7 +48,7 @@ export function CommandItemSearch({
return (
<Command.Item
className={cx(itemStyles(), 'group', className)}
value={`${commandPage.label} ${props.children.toString()}`}
value={`${commandPage.label} ${props.children?.toString() || ''}`}
{...props}
/>
)
Expand Down Expand Up @@ -76,7 +76,7 @@ export function CommandItemRootAndSearch({
return (
<Command.Item
className={cx(itemStyles(), 'group', className)}
value={`${commandPage.label} ${props.children.toString()}`}
value={`${commandPage.label} ${props.children?.toString() || ''}`}
{...props}
/>
)
Expand Down
48 changes: 42 additions & 6 deletions apps/renterd/components/Contracts/ContractContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ export function ContractContextMenuContent({
<DropdownMenuItem
disabled={!hostAddress}
onSelect={() => {
if (!hostAddress) {
return
}
resetContractsFilters()
setContractsFilter(addressContainsFilter(hostAddress))
router.push(routes.contracts.index)
Expand All @@ -131,6 +134,9 @@ export function ContractContextMenuContent({
<DropdownMenuItem
disabled={!hostKey}
onSelect={() => {
if (!hostKey) {
return
}
resetContractsFilters()
setContractsFilter(publicKeyContainsFilter(hostKey))
router.push(routes.contracts.index)
Expand All @@ -145,7 +151,12 @@ export function ContractContextMenuContent({
{blocklist.data?.find((l) => l === hostAddress) ? (
<DropdownMenuItem
disabled={!hostAddress}
onSelect={() => blocklistUpdate([], [hostAddress])}
onSelect={() => {
if (!hostAddress) {
return
}
blocklistUpdate([], [hostAddress])
}}
>
<DropdownMenuLeftSlot>
<ListChecked16 />
Expand All @@ -155,7 +166,12 @@ export function ContractContextMenuContent({
) : (
<DropdownMenuItem
disabled={!hostAddress}
onSelect={() => blocklistUpdate([hostAddress], [])}
onSelect={() => {
if (!hostAddress) {
return
}
blocklistUpdate([hostAddress], [])
}}
>
<DropdownMenuLeftSlot>
<ListChecked16 />
Expand All @@ -166,7 +182,12 @@ export function ContractContextMenuContent({
{allowlist.data?.find((l) => l === hostKey) ? (
<DropdownMenuItem
disabled={!hostKey}
onSelect={() => allowlistUpdate([], [hostKey])}
onSelect={() => {
if (!hostKey) {
return
}
allowlistUpdate([], [hostKey])
}}
>
<DropdownMenuLeftSlot>
<ListChecked16 />
Expand All @@ -176,7 +197,12 @@ export function ContractContextMenuContent({
) : (
<DropdownMenuItem
disabled={!hostKey}
onSelect={() => allowlistUpdate([hostKey], [])}
onSelect={() => {
if (!hostKey) {
return
}
allowlistUpdate([hostKey], [])
}}
>
<DropdownMenuLeftSlot>
<ListChecked16 />
Expand All @@ -199,7 +225,12 @@ export function ContractContextMenuContent({
</DropdownMenuItem>
<DropdownMenuItem
disabled={!hostKey}
onSelect={() => copyToClipboard(hostKey, 'host public key')}
onSelect={() => {
if (!hostKey) {
return
}
copyToClipboard(hostKey, 'host public key')
}}
>
<DropdownMenuLeftSlot>
<Copy16 />
Expand All @@ -208,7 +239,12 @@ export function ContractContextMenuContent({
</DropdownMenuItem>
<DropdownMenuItem
disabled={!hostAddress}
onSelect={() => copyToClipboard(hostAddress, 'host address')}
onSelect={() => {
if (!hostAddress) {
return
}
copyToClipboard(hostAddress, 'host address')
}}
>
<DropdownMenuLeftSlot>
<Copy16 />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function AddressCmdNav({
commandPage,
}: {
currentPage: Page
parentPage: Page
parentPage?: Page
commandPage: Page
select: () => void
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function ContractSetCmdNav({
commandPage,
}: {
currentPage: Page
parentPage: Page
parentPage?: Page
commandPage: Page
select: () => void
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function PublicKeyCmdNav({
commandPage,
}: {
currentPage: Page
parentPage: Page
parentPage?: Page
commandPage: Page
select: () => void
}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { ExpiryCmdGroup } from './Expiry'
import { ContractData } from '../../../../../contexts/contracts/types'
import { FormationCmdGroup } from './Formation'
import { RenewCmdGroup } from './Renew'
import { Page } from '../../../../CmdRoot/types'
import { ClientFilterItem } from '@siafoundation/design-system'
import { AddressCmdGroup } from './Address'
import { PublicKeyCmdGroup } from './PublicKey'
import { ContractSetCmdGroup } from './ContractSet'

type Props = {
currentPage: Page
select?: (filter?: ClientFilterItem<ContractData>) => void
select: () => void
}

export function ContractFilterCmdGroups({ currentPage, select }: Props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function contractSetsIncludeFilter(contractSet: string) {
value: contractSet,
label: `contract in set ${contractSet}`,
fn: (d: ContractData) => {
return d.contractSets?.includes(contractSet)
return !!d.contractSets?.includes(contractSet)
},
}
}
Expand Down Expand Up @@ -80,6 +80,9 @@ export function ContractsFilterContractSetDialog({

const onValid = useCallback(
(values: Values) => {
if (!values.contractSet) {
return
}
setFilter(contractSetsIncludeFilter(values.contractSet))
closeAndReset()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function ContractsFilterMenu() {
const [pages, setPages] = useState<Page[]>([])
const currentPage = pages[pages.length - 1]
const rootPage = pages.length === 0
const rootRef = useRef(null)
const rootRef = useRef<HTMLDivElement>(null)
const inputRef = useRef<HTMLInputElement>(null)

const pushPage = useCallback(
Expand All @@ -35,8 +35,8 @@ export function ContractsFilterMenu() {
}, [setPages])

useEffect(() => {
const handleClickOutside = (event) => {
if (rootRef.current && !rootRef.current.contains(event.target)) {
const handleClickOutside = (event: Event) => {
if (rootRef.current && !rootRef.current.contains(event.target as Node)) {
setOpen(false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function FilesHealthColumnContents({
displayHealth={displayHealth}
label={label}
minShards={slabs.find((s) => s.minShards)?.minShards}
totalShards={slabs.find((s) => s.shards)?.shards.length}
totalShards={slabs.find((s) => s.shards)?.shards?.length}
>
{slabs.map((slab) => (
<div key={slab.id} className="flex justify-between gap-2">
Expand All @@ -96,7 +96,7 @@ export function FilesHealthColumnContents({
</Text>
<Text size="12" className="flex items-center">
{slab.isPartialSlab
? `${slab.contractSetShards}/${slab.shards.length}`
? `${slab.contractSetShards}/${slab.shards?.length}`
: 'partial slab'}
</Text>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export function FilesSearchCmd({
currentPage={currentPage}
key={key}
onSelect={() => {
beforeSelect()
beforeSelect?.()
navigateToModeSpecificFiltering(searchBucket + key)
afterSelect()
afterSelect?.()
}}
value={key}
>
Expand Down
4 changes: 2 additions & 2 deletions apps/renterd/components/Files/FilesCmd/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function FilesCmd({
router.push(routes.buckets.index)
}
closeDialog()
afterSelect()
afterSelect?.()
}}
>
View files
Expand All @@ -64,7 +64,7 @@ export function FilesCmd({
commandPage={commandPage}
onSelect={() => {
pushPage(filesSearchPage)
afterSelect()
afterSelect?.()
}}
>
Search files
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Button, Text } from '@siafoundation/design-system'
import { Add16, BucketIcon } from '@siafoundation/react-icons'
import { useDialog } from '../../../contexts/dialog'

export function StateNoneYetBuckets() {
const { openDialog } = useDialog()
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px] cursor-pointer">
<Text>
<BucketIcon className="scale-[200%]" />
</Text>
<div className="flex flex-col gap-3 items-center">
<Text color="subtle" className="text-center max-w-[500px]">
Create a bucket to get started. Buckets are distinct storage areas
that you can use to organize your files.
</Text>
<Button
onClick={() => openDialog('filesCreateBucket')}
tip="Create bucket"
>
<Add16 />
Create bucket
</Button>
</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CloudUpload32 } from '@siafoundation/react-icons'
import { routes } from '../../../config/routes'
import { useFilesManager } from '../../../contexts/filesManager'

export function StateNoneYet() {
export function StateNoneYetFiles() {
const {
activeBucketName: activeBucket,
activeDirectory,
Expand Down
Loading

0 comments on commit d710788

Please sign in to comment.