@@ -32,52 +32,65 @@ import './editor.scss';
3232 *
3333 * @return {Element } Element to render.
3434 */
35- export default function Edit ( { attributes, setAttributes } )
36- {
37- const { samsConfigId, matchSeriesId } = attributes ;
35+ export default function Edit ( { attributes, setAttributes } ) {
36+ // rankingConfig: { samsConfigId, matchSeriesId }
37+ const { rankingConfig = { } } = attributes ;
38+ const { samsConfigId, matchSeriesId } = rankingConfig ;
3839
3940 const configs = useSelect (
4041 ( select ) => select ( 'core' ) . getEntityRecords ( 'postType' , 'sams_host_config' , { per_page : 100 } ) ,
4142 [ ]
4243 ) ;
4344
44- const selectedConfig = configs && samsConfigId ? configs . find ( config => config . id == samsConfigId ) : null ;
45+ const selectedConfig
46+ = configs
47+ && samsConfigId
48+ ? configs . find ( config => config . id == samsConfigId )
49+ : null ;
4550
4651 return (
47- < >
48- < InspectorControls >
49- < PanelBody title = { __ ( 'Settings' , 'sams-integration' ) } >
50- { ! configs ? (
51- < p > { __ ( 'Loading ...' , 'sams-integration' ) } </ p >
52- ) : (
53- < select
54- value = { samsConfigId || '' }
55- onChange = { e => {
56- setAttributes ( {
57- samsConfigId : e . target . value ,
58- } ) ;
59- } }
60- >
61- < option value = "" > { __ ( 'Select SAMS Server' , 'sams-integration' ) } </ option >
62- { configs . map ( config => (
63- < option key = { config . id } value = { config . id } >
64- { config . title ?. rendered || config . id }
65- </ option >
66- ) ) }
67- </ select >
68- ) }
69- < TextControl
70- label = { __ ( 'MatchSeriesId' , 'sams-integration' ) }
71- value = { matchSeriesId || '' }
72- onChange = { ( value ) => setAttributes ( { matchSeriesId : value } ) }
73- />
74- </ PanelBody >
75- </ InspectorControls >
76- < p { ...useBlockProps ( ) } >
77- SAMS Ranking Vorschau:< br />
78- { __ ( 'Config:' , 'sams-integration' ) } { selectedConfig ? ( selectedConfig . title ?. rendered || selectedConfig . id ) : __ ( 'None selected' , 'sams-integration' ) } < br />
79- { __ ( 'MatchSeriesId:' , 'sams-integration' ) } { matchSeriesId || __ ( 'None' , 'sams-integration' ) }
80- </ p >
81- </ >
82- ) ;
52+ < >
53+ < InspectorControls >
54+ < PanelBody title = { __ ( 'Settings' , 'sams-integration' ) } >
55+ { ! configs ? (
56+ < p > { __ ( 'Loading ...' , 'sams-integration' ) } </ p >
57+ ) : (
58+ < select
59+ value = { samsConfigId || '' }
60+ onChange = { e => {
61+ setAttributes ( {
62+ rankingConfig : {
63+ ...rankingConfig ,
64+ samsConfigId : e . target . value ,
65+ }
66+ } ) ;
67+ } }
68+ >
69+ < option value = "" > { __ ( 'Select SAMS Server' , 'sams-integration' ) } </ option >
70+ { configs . map ( config => (
71+ < option key = { config . id } value = { config . id } >
72+ { config . title ?. rendered || config . id }
73+ </ option >
74+ ) ) }
75+ </ select >
76+ ) }
77+ < TextControl
78+ label = { __ ( 'MatchSeriesId' , 'sams-integration' ) }
79+ value = { matchSeriesId || '' }
80+ onChange = { ( value ) => setAttributes ( {
81+ rankingConfig : {
82+ ...rankingConfig ,
83+ matchSeriesId : value ,
84+ }
85+ } ) }
86+ />
87+ </ PanelBody >
88+ </ InspectorControls >
89+ < p { ...useBlockProps ( ) } >
90+ SAMS Ranking Vorschau:< br />
91+ { __ ( 'Config:' , 'sams-integration' ) } { selectedConfig ? ( selectedConfig . title ?. rendered || selectedConfig . id ) : __ ( 'None selected' , 'sams-integration' ) } < br />
92+ { __ ( 'MatchSeriesId:' , 'sams-integration' ) } { matchSeriesId || __ ( 'None' , 'sams-integration' ) }
93+ </ p >
94+ </ >
95+ ) ;
8396}
0 commit comments