Skip to content

Commit

Permalink
init: Capabilities form
Browse files Browse the repository at this point in the history
  • Loading branch information
BjrInt committed Sep 15, 2023
1 parent 4414d4f commit 28a80e3
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 5 deletions.
37 changes: 37 additions & 0 deletions src/components/form/AddFunctionCapabilities/cmp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import NoisyContainer from '@/components/common/NoisyContainer/styles'
import { AddFunctionCapabilitiesProps } from './types'
import { useAddFunctionCapabilities } from '@/hooks/form/useAddFunctionCapabilities'
import { Checkbox, CheckboxGroup } from '@aleph-front/aleph-core'

const AddFunctionCapabilities = (props: AddFunctionCapabilitiesProps) => {
const { internetAccessCtrl, blockchainRPCCtrl, enableAutoSnapshotsCtrl } =
useAddFunctionCapabilities(props)

return (
<NoisyContainer>
<Checkbox
label="Outgoing internet access"
tw="my-3"
{...internetAccessCtrl.field}
{...internetAccessCtrl.fieldState}
/>

<Checkbox
label="Accessing blockchain RPC nodes"
tw="my-3"
{...blockchainRPCCtrl.field}
{...blockchainRPCCtrl.fieldState}
/>

<Checkbox
label="Enable automatic snapshots (not available yet)"
tw="my-3"
{...enableAutoSnapshotsCtrl.field}
{...enableAutoSnapshotsCtrl.fieldState}
disabled
/>
</NoisyContainer>
)
}

export default AddFunctionCapabilities
2 changes: 2 additions & 0 deletions src/components/form/AddFunctionCapabilities/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './cmp'
export type { AddFunctionCapabilitiesProps } from './types'
6 changes: 6 additions & 0 deletions src/components/form/AddFunctionCapabilities/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Control } from 'react-hook-form'

export type AddFunctionCapabilitiesProps = {
name?: string
control: Control
}
21 changes: 18 additions & 3 deletions src/components/pages/dashboard/NewFunctionPage/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SelectFunctionPersistence from '@/components/form/SelectFunctionPersisten
import BorderBox from '@/components/common/BorderBox'
import { convertByteUnits } from '@/helpers/utils'
import Form from '@/components/form/Form'
import AddFunctionCapabilities from '@/components/form/AddFunctionCapabilities'

export default function NewFunctionPage() {
const {
Expand Down Expand Up @@ -117,6 +118,20 @@ export default function NewFunctionPage() {
<section tw="px-0 py-6 md:py-10">
<Container>
<CompositeTitle as="h2" number="5">
Function capabilities
</CompositeTitle>
<p tw="mb-6">
Enable advanced capabilities for your decentralized functions with
additional capabilities. Choose from outgoing internet access,
blockchain RPC nodes, or future options like automated snapshots.
Note: some features are still in development.
</p>
<AddFunctionCapabilities name="capabilities" control={control} />
</Container>
</section>
<section tw="px-0 py-6 md:py-10">
<Container>
<CompositeTitle as="h2" number="6">
Name and tags
</CompositeTitle>
<p tw="mb-6">
Expand All @@ -130,7 +145,7 @@ export default function NewFunctionPage() {
</section>
<section tw="px-0 py-6 md:py-10">
<Container>
<CompositeTitle as="h2" number="6">
<CompositeTitle as="h2" number="7">
Add volumes
</CompositeTitle>
{values.specs && (
Expand All @@ -153,7 +168,7 @@ export default function NewFunctionPage() {
</section>
<section tw="px-0 py-6 md:py-10">
<Container>
<CompositeTitle as="h2" number="7">
<CompositeTitle as="h2" number="8">
Add environment variables
</CompositeTitle>
<p tw="mb-6">
Expand All @@ -167,7 +182,7 @@ export default function NewFunctionPage() {
</section>
<section tw="px-0 py-6 md:py-10">
<Container>
<CompositeTitle as="h2" number="8">
<CompositeTitle as="h2" number="9">
Custom domain
</CompositeTitle>
<p tw="mb-6">
Expand Down
2 changes: 0 additions & 2 deletions src/domain/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ export class ProgramManager
try {
const programMessage = await this.parseProgram(newProgram)

console.log('programMessage', programMessage)

const response = await program.publish(programMessage)

const [entity] = await this.parseMessages([response])
Expand Down
49 changes: 49 additions & 0 deletions src/hooks/form/useAddFunctionCapabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Control, UseControllerReturn, useController } from 'react-hook-form'

export const defaultCapabilities = {
internetAccess: true,
blockchainRPC: true,
enableAutoSnapshots: false,
}

export type UseAddFunctionCapabilitiesProps = {
name?: string
control: Control
defaultValue?: typeof defaultCapabilities
}

export type UseAddFunctionCapabilitiesReturn = {
internetAccessCtrl: UseControllerReturn<any, any>
blockchainRPCCtrl: UseControllerReturn<any, any>
enableAutoSnapshotsCtrl: UseControllerReturn<any, any>
}

export function useAddFunctionCapabilities({
name = 'capabilities',
control,
defaultValue = defaultCapabilities,
}: UseAddFunctionCapabilitiesProps): UseAddFunctionCapabilitiesReturn {
const internetAccessCtrl = useController({
control,
name: `${name}.internetAccess`,
defaultValue: defaultValue?.internetAccess,
})

const blockchainRPCCtrl = useController({
control,
name: `${name}.internetAccess`,
defaultValue: defaultValue?.blockchainRPC,
})

const enableAutoSnapshotsCtrl = useController({
control,
name: `${name}.internetAccess`,
defaultValue: defaultValue?.enableAutoSnapshots,
})

return {
internetAccessCtrl,
blockchainRPCCtrl,
enableAutoSnapshotsCtrl,
}
}

0 comments on commit 28a80e3

Please sign in to comment.