-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7635e79
commit cc7b150
Showing
15 changed files
with
218 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'renterd': minor | ||
--- | ||
|
||
Contracts can now be filtered by contract set. |
68 changes: 68 additions & 0 deletions
68
...ponents/Contracts/ContractsCmd/ContractsFilterCmd/ContractFilterCmdGroups/ContractSet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
CommandGroup, | ||
CommandItemNav, | ||
CommandItemSearch, | ||
} from '../../../../CmdRoot/Item' | ||
import { Page } from '../../../../CmdRoot/types' | ||
import { useDialog } from '../../../../../contexts/dialog' | ||
import { contractSetsIncludeFilter } from '../../../ContractsFilterContractSetDialog' | ||
|
||
export const contractsFilterContractSetPage = { | ||
namespace: 'contracts/filterContractSet', | ||
label: 'Contracts filter by contract set', | ||
} | ||
|
||
export function ContractSetCmdGroup({ | ||
select, | ||
currentPage, | ||
}: { | ||
currentPage: Page | ||
select: () => void | ||
}) { | ||
const filter = contractSetsIncludeFilter('') | ||
const { openDialog } = useDialog() | ||
return ( | ||
<CommandGroup | ||
currentPage={currentPage} | ||
commandPage={contractsFilterContractSetPage} | ||
> | ||
<CommandItemSearch | ||
currentPage={currentPage} | ||
commandPage={contractsFilterContractSetPage} | ||
onSelect={() => { | ||
select() | ||
openDialog('contractsFilterContractSet') | ||
}} | ||
> | ||
{filter.label} | ||
</CommandItemSearch> | ||
</CommandGroup> | ||
) | ||
} | ||
|
||
export function ContractSetCmdNav({ | ||
select, | ||
currentPage, | ||
parentPage, | ||
commandPage, | ||
}: { | ||
currentPage: Page | ||
parentPage: Page | ||
commandPage: Page | ||
select: () => void | ||
}) { | ||
const { openDialog } = useDialog() | ||
return ( | ||
<CommandItemNav | ||
currentPage={currentPage} | ||
parentPage={parentPage} | ||
commandPage={commandPage} | ||
onSelect={() => { | ||
select() | ||
openDialog('contractsFilterContractSet') | ||
}} | ||
> | ||
{contractsFilterContractSetPage.label} | ||
</CommandItemNav> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
apps/renterd/components/Contracts/ContractsFilterContractSetDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { | ||
ConfigFields, | ||
Dialog, | ||
FieldSelect, | ||
FormSubmitButton, | ||
useDialogFormHelpers, | ||
useOnInvalid, | ||
} from '@siafoundation/design-system' | ||
import { useContracts } from '../../contexts/contracts' | ||
import { ContractData } from '../../contexts/contracts/types' | ||
import { useForm } from 'react-hook-form' | ||
import { useCallback } from 'react' | ||
|
||
export function contractSetsIncludeFilter(contractSet: string) { | ||
return { | ||
id: 'contractSetsInclude', | ||
value: contractSet, | ||
label: `contract in set ${contractSet}`, | ||
fn: (d: ContractData) => { | ||
return d.contractSets?.includes(contractSet) | ||
}, | ||
} | ||
} | ||
|
||
function getDefaultValues(defaultContractSet?: string) { | ||
return { | ||
contractSet: defaultContractSet, | ||
} | ||
} | ||
|
||
type Values = ReturnType<typeof getDefaultValues> | ||
|
||
function getFields({ | ||
contractSets, | ||
}: { | ||
contractSets: string[] | ||
}): ConfigFields<Values, never> { | ||
return { | ||
contractSet: { | ||
type: 'select', | ||
title: 'Contract set', | ||
options: contractSets.map((contractSet) => ({ | ||
label: contractSet, | ||
value: contractSet, | ||
})), | ||
placeholder: 'autopilot', | ||
validation: { | ||
required: 'required', | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type Props = { | ||
trigger?: React.ReactNode | ||
open: boolean | ||
onOpenChange: (val: boolean) => void | ||
} | ||
|
||
export function ContractsFilterContractSetDialog({ | ||
trigger, | ||
open, | ||
onOpenChange, | ||
}: Props) { | ||
const { setFilter, contractSets } = useContracts() | ||
|
||
const defaultValues = getDefaultValues(contractSets.data?.[0]) | ||
const form = useForm({ | ||
mode: 'all', | ||
defaultValues, | ||
}) | ||
|
||
const { handleOpenChange, closeAndReset } = useDialogFormHelpers({ | ||
form, | ||
onOpenChange, | ||
defaultValues, | ||
}) | ||
|
||
const fields = getFields({ contractSets: contractSets.data || [] }) | ||
|
||
const onValid = useCallback( | ||
(values: Values) => { | ||
setFilter(contractSetsIncludeFilter(values.contractSet)) | ||
closeAndReset() | ||
}, | ||
[setFilter, closeAndReset] | ||
) | ||
|
||
const onInvalid = useOnInvalid(fields) | ||
|
||
return ( | ||
<Dialog | ||
trigger={trigger} | ||
title="Filter by contract set" | ||
open={open} | ||
onOpenChange={handleOpenChange} | ||
contentVariants={{ | ||
className: 'w-[400px]', | ||
}} | ||
onSubmit={form.handleSubmit(onValid, onInvalid)} | ||
> | ||
<div className="flex flex-col gap-4"> | ||
<div className="flex flex-col gap-4"> | ||
<FieldSelect form={form} fields={fields} name="contractSet" /> | ||
<FormSubmitButton form={form} size="medium"> | ||
Filter | ||
</FormSubmitButton> | ||
</div> | ||
</div> | ||
</Dialog> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
apps/walletd/hooks/useDialogFormHelpers.ts → ...n-system/src/form/useDialogFormHelpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters