Skip to content

Commit

Permalink
#119 dialog for editing rgroup does not work
Browse files Browse the repository at this point in the history
- add FormContext & useFormContext hook
- update rgroup-logic.jsx
  • Loading branch information
AndreiMazol committed Nov 27, 2020
1 parent 1056e9f commit 6b408e4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/contexts/formContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react'

const formContext = React.createContext(null)

export default formContext
3 changes: 2 additions & 1 deletion src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SettingsContext, { ISettingsContext } from './settingsContext'
import FormContext from './formContext'

export { SettingsContext }
export { SettingsContext, FormContext }
export type { ISettingsContext }
3 changes: 2 additions & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import useSettingsContext from './useSettingsContext'
import useFormContext from './useFormContext'

export { useSettingsContext }
export { useSettingsContext, useFormContext }
6 changes: 6 additions & 0 deletions src/hooks/useFormContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import FormContext from './../contexts/formContext'

export default function useFormContext() {
return React.useContext(FormContext)
}
7 changes: 3 additions & 4 deletions src/script/ui/component/form/form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import classNames from 'classnames'

import Input from './input'
import { updateFormState } from '../../state/modal/form'
import { useContext } from 'react'

const FormContext = React.createContext(null)
import { FormContext } from './../../../../contexts'
import { useFormContext } from './../../../../hooks'

class Form extends Component {
constructor(props) {
Expand Down Expand Up @@ -100,7 +99,7 @@ function Label({ labelPos, title, children, ...props }) {

function Field(props) {
const { name, onChange, component, labelPos, ...prop } = props
const { schema, stateStore } = useContext(FormContext)
const { schema, stateStore } = useFormContext()
const desc = prop.schema || schema.properties[name]
const { dataError, ...fieldOpts } = stateStore.field(name, onChange)
const Component = component
Expand Down
5 changes: 3 additions & 2 deletions src/script/ui/dialog/toolbox/rgroup-logic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import { connect } from 'react-redux'
import { rgroupLogic as rgroupSchema } from '../../data/schema/struct-schema'
import Form, { Field } from '../../component/form/form'
import Dialog from '../../component/dialog'
import { useFormContext } from './../../../../hooks'

function IfThenSelect(props, { schema }) {
function IfThenSelect(props) {
const { name, rgids } = props

const { schema } = useFormContext()
const desc = {
title: schema.properties[name].title,
enum: [0],
Expand Down

0 comments on commit 6b408e4

Please sign in to comment.