Skip to content

Commit

Permalink
fix(fields): add optional pageId to fields
Browse files Browse the repository at this point in the history
This feature should already be included into v2.0.0 but went missing.
This change adds a optional pageId property to all fields thatare based
on the template id of the jaen context.

This change is required to make the fields more flexible by allowing
to use the same field in different contexts.
  • Loading branch information
schettn authored Oct 2, 2021
1 parent 8beb602 commit c536ba6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const ChoiceField: React.FC<ChoiceFieldProps> = ({
onRenderPopover,
onRender,
initValue,
fieldName
fieldName,
...props
}) => {
const dispatch = useAppDispatch()

Expand All @@ -58,7 +59,7 @@ const ChoiceField: React.FC<ChoiceFieldProps> = ({
const field = {initValue, fieldName, block}

const {jaenPageContext} = useTemplate()
const pageId = jaenPageContext.id
const pageId = props.pageId || jaenPageContext.id

const register = () => dispatch(registerPageField({pageId, field}))
const unregister = () => dispatch(unregisterPageField({pageId, field}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ImageField: React.FC<ImageFieldProps> = ({
const dispatch = useAppDispatch()
const isEditing = useAppSelector(state => state.options.isEditing)
const {jaenPageContext} = useTemplate()
const pageId = jaenPageContext.id
const pageId = props.pageId || jaenPageContext.id

const page = usePage(pageId)

Expand Down
5 changes: 3 additions & 2 deletions packages/jaen-pages/src/containers/fields/TextField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ const TextField: React.FC<TextFieldProps> = ({
rtf = true,
toolbar = 'balloon',
fieldName,
initValue
initValue,
...props
}) => {
const dispatch = useAppDispatch()
const isEditing = useAppSelector(state => state.options.isEditing)
const {jaenPageContext} = useTemplate()
const pageId = jaenPageContext.id
const pageId = props.pageId || jaenPageContext.id

const {block, updatedFieldName} = useBlock(fieldName)
fieldName = updatedFieldName
Expand Down
4 changes: 4 additions & 0 deletions packages/jaen-pages/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export type StreamBlockIdentifier = {
export type FieldIdentifier = {
initValue: any
fieldName: string
/**
* Override the default pageId for the field.
*/
pageId?: string
}

export type BlockIdentifier = {
Expand Down

0 comments on commit c536ba6

Please sign in to comment.