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 c1cf50f commit 9b405a7
Show file tree
Hide file tree
Showing 97 changed files with 819 additions and 519 deletions.
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
10 changes: 7 additions & 3 deletions apps/renterd/components/FilesDirectory/EmptyState/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { useAutopilotNotConfigured } from '../../Files/checks/useAutopilotNotCon
import { useNotEnoughContracts } from '../../Files/checks/useNotEnoughContracts'
import { StateError } from './StateError'
import { StateNoneMatching } from './StateNoneMatching'
import { StateNoneYet } from './StateNoneYet'
import { StateNoneYetFiles } from './StateNoneYetFiles'
import { useFilesManager } from '../../../contexts/filesManager'
import { StateNoneYetBuckets } from './StateNoneYetBuckets'

export function EmptyState() {
const { isViewingRootOfABucket } = useFilesManager()
const { isViewingRootOfABucket, isViewingBuckets } = useFilesManager()
const { dataState } = useFilesDirectory()

const autopilotNotConfigured = useAutopilotNotConfigured()
Expand Down Expand Up @@ -76,7 +77,10 @@ export function EmptyState() {
}

if (dataState === 'noneYet') {
return <StateNoneYet />
if (isViewingBuckets) {
return <StateNoneYetBuckets />
}
return <StateNoneYetFiles />
}

return null
Expand Down
Loading

0 comments on commit 9b405a7

Please sign in to comment.