Skip to content

Commit c536ba6

Browse files
authored
fix(fields): add optional pageId to fields
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.
1 parent 8beb602 commit c536ba6

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

packages/jaen-pages/src/containers/fields/ChoiceField/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const ChoiceField: React.FC<ChoiceFieldProps> = ({
4848
onRenderPopover,
4949
onRender,
5050
initValue,
51-
fieldName
51+
fieldName,
52+
...props
5253
}) => {
5354
const dispatch = useAppDispatch()
5455

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

6061
const {jaenPageContext} = useTemplate()
61-
const pageId = jaenPageContext.id
62+
const pageId = props.pageId || jaenPageContext.id
6263

6364
const register = () => dispatch(registerPageField({pageId, field}))
6465
const unregister = () => dispatch(unregisterPageField({pageId, field}))

packages/jaen-pages/src/containers/fields/ImageField/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const ImageField: React.FC<ImageFieldProps> = ({
3636
const dispatch = useAppDispatch()
3737
const isEditing = useAppSelector(state => state.options.isEditing)
3838
const {jaenPageContext} = useTemplate()
39-
const pageId = jaenPageContext.id
39+
const pageId = props.pageId || jaenPageContext.id
4040

4141
const page = usePage(pageId)
4242

packages/jaen-pages/src/containers/fields/TextField/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ const TextField: React.FC<TextFieldProps> = ({
2828
rtf = true,
2929
toolbar = 'balloon',
3030
fieldName,
31-
initValue
31+
initValue,
32+
...props
3233
}) => {
3334
const dispatch = useAppDispatch()
3435
const isEditing = useAppSelector(state => state.options.isEditing)
3536
const {jaenPageContext} = useTemplate()
36-
const pageId = jaenPageContext.id
37+
const pageId = props.pageId || jaenPageContext.id
3738

3839
const {block, updatedFieldName} = useBlock(fieldName)
3940
fieldName = updatedFieldName

packages/jaen-pages/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export type StreamBlockIdentifier = {
1616
export type FieldIdentifier = {
1717
initValue: any
1818
fieldName: string
19+
/**
20+
* Override the default pageId for the field.
21+
*/
22+
pageId?: string
1923
}
2024

2125
export type BlockIdentifier = {

0 commit comments

Comments
 (0)