@@ -11,9 +11,9 @@ import {
1111 displayError ,
1212 displaySuccess ,
1313} from "../util/list/toast-component/display-toast" ;
14- import EventDatabaseApiFeedTypeTemplate from "./feed-source-type-templates/EventDatabaseApiFeedType.template " ;
15- import NotifiedFeedTypeTemplate from "./feed-source- type-templates/NotifiedFeedType.template " ;
16- import CalendarFeedTypeTemplate from "./feed-source- type-templates/CalendarFeedType.template " ;
14+ import EventDatabaseFeedType from "./templates/event-database-feed-type.jsx " ;
15+ import NotifiedFeedType from "./templates/notified- feed-type.jsx " ;
16+ import CalendarFeedType from "./templates/calendar- feed-type.jsx " ;
1717
1818/**
1919 * The theme manager component.
@@ -67,27 +67,34 @@ function FeedSourceManager({
6767 value : "App\\Feed\\EventDatabaseApiFeedType" ,
6868 title : t ( "dynamic-fields.event-database-api-feed-type.title" ) ,
6969 key : "1" ,
70- secrets : "host" ,
71- template : < EventDatabaseApiFeedTypeTemplate mode = { saveMethod } /> ,
70+ secretsDefault : {
71+ "host" : ""
72+ } ,
73+ template : < EventDatabaseFeedType mode = { saveMethod } /> ,
7274 } ,
7375 {
7476 value : "App\\Feed\\NotifiedFeedType" ,
7577 title : t ( "dynamic-fields.notified-feed-type.title" ) ,
7678 key : "2" ,
77- secrets : "token" ,
78- template : < NotifiedFeedTypeTemplate mode = { saveMethod } /> ,
79+ secretsDefault : {
80+ "token" : "" ,
81+ } ,
82+ template : < NotifiedFeedType mode = { saveMethod } /> ,
7983 } ,
8084 {
8185 value : "App\\Feed\\CalendarApiFeedType" ,
8286 title : t ( "dynamic-fields.calendar-api-feed-type.title" ) ,
8387 key : "3" ,
84- secrets : "resources" ,
85- template : < CalendarFeedTypeTemplate mode = { saveMethod } /> ,
88+ secretsDefault : {
89+ "resources" : [ ]
90+ } ,
91+ template : < CalendarFeedType mode = { saveMethod } /> ,
8692 } ,
8793 {
8894 value : "App\\Feed\\RssFeedType" ,
8995 title : t ( "dynamic-fields.rss-feed-type.title" ) ,
90- key : "5" ,
96+ key : "4" ,
97+ secretsDefault : { } ,
9198 template : null ,
9299 } ,
93100 ] ;
@@ -109,11 +116,15 @@ function FeedSourceManager({
109116 setFormStateObject ( { ...initialState } ) ;
110117 } , [ initialState ] ) ;
111118
119+ const onFeedTypeChange = ( ) => {
120+ const option = feedSourceTypeOptions . find ( ( opt ) => opt . value === formStateObject . feedType ) ;
121+ const newFormStateObject = { ...formStateObject } ;
122+ newFormStateObject . secrets = { ...option . secretsDefault } ;
123+ setFormStateObject ( newFormStateObject ) ;
124+ }
125+
112126 useEffect ( ( ) => {
113- if ( formStateObject ) {
114- const option = feedSourceTypeOptions . find (
115- ( opt ) => opt . value === formStateObject . feedType
116- ) ;
127+ if ( formStateObject ?. feedType ) {
117128 if ( option && option . template ) {
118129 setDynamicFormElement (
119130 cloneElement ( option . template , {
@@ -125,26 +136,7 @@ function FeedSourceManager({
125136 setDynamicFormElement ( null ) ;
126137 }
127138 }
128- } , [ formStateObject ] ) ;
129-
130- useEffect ( ( ) => {
131- if ( formStateObject ?. feedType ) {
132- const selectedFeedTypeSecret = feedSourceTypeOptions . find (
133- ( option ) => option . value === formStateObject . feedType
134- ) . secrets ;
135-
136- if ( selectedFeedTypeSecret ) {
137- const secretsArray = selectedFeedTypeSecret
138- . split ( "," )
139- . map ( ( prop ) => prop . trim ( ) ) ;
140-
141- formStateObject . secrets = secretsArray ?. reduce ( ( acc , secret ) => {
142- acc [ secret ] = formStateObject [ secret ] ;
143- return acc ;
144- } , { } ) ;
145- }
146- }
147- } , [ formStateObject , formStateObject ?. feedType ] ) ;
139+ } , [ formStateObject ?. feedType ] ) ;
148140
149141 /** Save feed source. */
150142 function saveFeedSource ( ) {
@@ -206,6 +198,7 @@ function FeedSourceManager({
206198 isLoading = { isLoading || submitting }
207199 loadingMessage = { loadingMessage }
208200 feedSourceTypeOptions = { feedSourceTypeOptions }
201+ onFeedTypeChange = { }
209202 dynamicFormElement = { dynamicFormElement }
210203 mode = { saveMethod }
211204 />
0 commit comments