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 30, 2024
1 parent 7105060 commit d68542c
Show file tree
Hide file tree
Showing 94 changed files with 791 additions and 522 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
12 changes: 6 additions & 6 deletions apps/renterd/components/Files/FilesCmd/FilesSearchCmd/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const filesSearchAllPage = {
empty: FileSearchEmpty,
}

export function getFilesSearchBucketPage(activeBucketName: string) {
export function getFilesSearchBucketPage(activeBucketName?: string) {
return {
namespace: 'files/search/bucket',
label: 'Search files in current bucket',
Expand Down Expand Up @@ -44,9 +44,9 @@ export function FilesSearchCmd({
const { activeBucketName, navigateToModeSpecificFiltering } =
useFilesManager()
const activePage =
mode === 'global'
? filesSearchAllPage
: getFilesSearchBucketPage(activeBucketName)
mode === 'bucket' && activeBucketName
? getFilesSearchBucketPage(activeBucketName)
: filesSearchAllPage
const onSearchPage = currentPage?.namespace === activePage.namespace
const validMode = mode === 'global' || (mode === 'bucket' && activeBucketName)
const params = useMemo(() => {
Expand Down Expand Up @@ -88,9 +88,9 @@ export function FilesSearchCmd({
currentPage={currentPage}
key={key}
onSelect={() => {
beforeSelect()
beforeSelect?.()
navigateToModeSpecificFiltering(bucket + key)
afterSelect()
afterSelect?.()
}}
value={key}
>
Expand Down
6 changes: 3 additions & 3 deletions apps/renterd/components/Files/FilesCmd/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function FilesCmd({
router.push(routes.buckets.index)
}
closeDialog()
afterSelect()
afterSelect?.()
}}
>
View files
Expand All @@ -70,7 +70,7 @@ export function FilesCmd({
commandPage={commandPage}
onSelect={() => {
pushPage(filesSearchAllPage)
afterSelect()
afterSelect?.()
}}
>
Search all files
Expand All @@ -81,7 +81,7 @@ export function FilesCmd({
commandPage={commandPage}
onSelect={() => {
pushPage(getFilesSearchBucketPage(activeBucket.name))
afterSelect()
afterSelect?.()
}}
>
Search files in bucket
Expand Down
8 changes: 5 additions & 3 deletions apps/renterd/components/Files/FilesSearchBucketMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export function FilesSearchBucketMenu({ panel }: Props) {
>
<Label className="px-2 flex justify-between items-center">
File search in current bucket
<Button variant="inactive" state="waiting" tabIndex={-1} size="small">
{activeBucket.name}
</Button>
{!!activeBucket && (
<Button variant="inactive" state="waiting" tabIndex={-1} size="small">
{activeBucket.name}
</Button>
)}
</Label>
<Command.Input
aria-label="search files"
Expand Down
Loading

0 comments on commit d68542c

Please sign in to comment.