@@ -5,8 +5,18 @@ import {
55 TreeViewCheckbox ,
66 TreeViewSection ,
77} from "@prismicio/editor-ui" ;
8+ import { useSelector } from "react-redux" ;
9+
10+ import {
11+ hasLocal ,
12+ LocalOrRemoteCustomType ,
13+ } from "@/legacy/lib/models/common/ModelData" ;
14+ import { selectAllCustomTypes } from "@/modules/availableCustomTypes" ;
815
916export function ContentRelationshipFieldPicker ( ) {
17+ const customTypes = useSelector ( selectAllCustomTypes ) . filter ( hasLocal ) ;
18+ const simplifiedCustomTypes = simplifyCustomTypes ( customTypes ) ;
19+
1020 return (
1121 < Box overflow = "hidden" flexDirection = "column" border borderRadius = { 6 } >
1222 < Box
@@ -24,32 +34,18 @@ export function ContentRelationshipFieldPicker() {
2434 </ Text >
2535 </ Box >
2636 < TreeView title = "Exposed fields" subtitle = "(3)" >
27- < TreeViewSection
28- title = "Custom Type A"
29- subtitle = "(3 fields exposed)"
30- badge = "Custom Type"
31- >
32- < TreeViewCheckbox title = "Name" />
33- < TreeViewCheckbox title = "Biography" />
37+ { simplifiedCustomTypes . map ( ( ct ) => (
3438 < TreeViewSection
35- title = "Slice A"
36- subtitle = "(2 fields exposed)"
37- badge = "Slice"
39+ key = { ct . id }
40+ title = { ct . label }
41+ subtitle = { `(${ ct . fields . length } fields exposed)` }
42+ badge = "Custom Type"
3843 >
39- < TreeViewCheckbox title = "Title" />
40- < TreeViewCheckbox title = "Subtitle" />
41- < TreeViewCheckbox title = "Image" />
44+ { ct . fields . map ( ( field ) => {
45+ return < TreeViewCheckbox key = { field . id } title = { field . label } /> ;
46+ } ) }
4247 </ TreeViewSection >
43- </ TreeViewSection >
44- < TreeViewSection title = "Custom Type B" badge = "Custom Type" >
45- Something else
46- </ TreeViewSection >
47- < TreeViewSection title = "Custom Type C" badge = "Custom Type" >
48- Something else
49- </ TreeViewSection >
50- < TreeViewSection title = "Custom Type D" badge = "Custom Type" >
51- Something else
52- </ TreeViewSection >
48+ ) ) }
5349 </ TreeView >
5450 </ Box >
5551 < Box backgroundColor = "white" flexDirection = "column" padding = { 12 } >
@@ -68,3 +64,25 @@ export function ContentRelationshipFieldPicker() {
6864 </ Box >
6965 ) ;
7066}
67+
68+ type SimplifiedCustomType = {
69+ id : string ;
70+ label : string ;
71+ fields : { id : string ; label : string } [ ] ;
72+ } ;
73+
74+ function simplifyCustomTypes ( customTypes : LocalOrRemoteCustomType [ ] ) {
75+ return customTypes . flatMap < SimplifiedCustomType > ( ( ct ) => {
76+ if ( ! ( "local" in ct ) ) return [ ] ;
77+
78+ const { id, label, tabs } = ct . local ;
79+ const fields = tabs . flatMap ( ( tab ) => {
80+ return tab . value . map ( ( field ) => ( {
81+ id : field . key ,
82+ label : field . value . config ?. label ?? field . key ,
83+ } ) ) ;
84+ } ) ;
85+
86+ return { id, label : label ?? id , fields } ;
87+ } ) ;
88+ }
0 commit comments