Skip to content

Commit 6dfbf25

Browse files
committed
2826: Adjustments
1 parent bd3ef7c commit 6dfbf25

File tree

4 files changed

+46
-45
lines changed

4 files changed

+46
-45
lines changed

src/components/feed-sources/feed-source-form.jsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import FormSelect from "../util/forms/select";
1010
import ContentBody from "../util/content-body/content-body";
1111
import ContentFooter from "../util/content-footer/content-footer";
1212
import FormInput from "../util/forms/form-input";
13+
import CalendarFeedType from "./templates/calendar-feed-type.jsx";
14+
import NotifiedFeedType from "./templates/notified-feed-type.jsx";
15+
import EventDatabaseFeedType from "./templates/event-database-feed-type.jsx";
1316

1417
/**
1518
* The feed-source form component.
@@ -25,7 +28,6 @@ import FormInput from "../util/forms/form-input";
2528
* spinner. Default is `""`
2629
* @param {object} props.feedSource The feed source object
2730
* @param {object} props.feedSourceTypeOptions The options for feed source types
28-
* @param {element} props.dynamicFormElement The dynamic form element
2931
* @param {string} props.mode The mode
3032
* @returns {object} The feed-source form.
3133
*/
@@ -37,8 +39,8 @@ function FeedSourceForm({
3739
loadingMessage = "",
3840
feedSource = null,
3941
feedSourceTypeOptions = null,
40-
handleChangeFeedType = () => {},
41-
dynamicFormElement = null,
42+
onFeedTypeChange = () => {},
43+
handleSecretInput = () => {},
4244
mode = null,
4345
}) {
4446
const { t } = useTranslation("common", { keyPrefix: "feed-source-form" });
@@ -71,12 +73,20 @@ function FeedSourceForm({
7173
name="feedType"
7274
label={t("feed-source-feed-type-label")}
7375
value={feedSource.feedType}
74-
onChange={handleChangeFeedType}
76+
onChange={onFeedTypeChange}
7577
disabled={mode === "PUT"}
7678
options={feedSourceTypeOptions}
7779
/>
7880

79-
{dynamicFormElement}
81+
{feedSource?.feedType === "App\\Feed\\CalendarApiFeedType" &&
82+
(<CalendarFeedType handleInput={handleSecretInput} formStateObject={feedSource.secrets} mode={mode} />)
83+
}
84+
{feedSource?.feedType === "App\\Feed\\NotifiedFeedType" &&
85+
(<NotifiedFeedType handleInput={handleSecretInput} formStateObject={feedSource.secrets} mode={mode} />)
86+
}
87+
{feedSource?.feedType === "App\\Feed\\EventDatabaseApiFeedType" &&
88+
(<EventDatabaseFeedType handleInput={handleSecretInput} formStateObject={feedSource.secrets} mode={mode} />)
89+
}
8090
</ContentBody>
8191
<ContentFooter>
8292
<Button

src/components/feed-sources/feed-source-manager.jsx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function FeedSourceManager({
5050

5151
const [dynamicFormElement, setDynamicFormElement] = useState();
5252
const [submitting, setSubmitting] = useState(false);
53-
const [formStateObject, setFormStateObject] = useState();
53+
const [formStateObject, setFormStateObject] = useState({});
5454

5555
const [
5656
postV2FeedSources,
@@ -70,7 +70,6 @@ function FeedSourceManager({
7070
secretsDefault: {
7171
"host": ""
7272
},
73-
template: <EventDatabaseFeedType mode={saveMethod} />,
7473
},
7574
{
7675
value: "App\\Feed\\NotifiedFeedType",
@@ -79,7 +78,6 @@ function FeedSourceManager({
7978
secretsDefault: {
8079
"token": "",
8180
},
82-
template: <NotifiedFeedType mode={saveMethod} />,
8381
},
8482
{
8583
value: "App\\Feed\\CalendarApiFeedType",
@@ -88,14 +86,12 @@ function FeedSourceManager({
8886
secretsDefault: {
8987
"resources": []
9088
},
91-
template: <CalendarFeedType mode={saveMethod} />,
9289
},
9390
{
9491
value: "App\\Feed\\RssFeedType",
9592
title: t("dynamic-fields.rss-feed-type.title"),
9693
key: "4",
9794
secretsDefault: {},
98-
template: null,
9995
},
10096
];
10197

@@ -116,31 +112,28 @@ function FeedSourceManager({
116112
setFormStateObject({ ...initialState });
117113
}, [initialState]);
118114

119-
const onFeedTypeChange = () => {
120-
const option = feedSourceTypeOptions.find((opt) => opt.value === formStateObject.feedType);
115+
const handleSecretInput = ({target}) => {
116+
const localFormStateObject = { ...formStateObject };
117+
if (!localFormStateObject.secrets) {
118+
localFormStateObject.secrets = {};
119+
}
120+
localFormStateObject.secrets[target.id] = target.value;
121+
setFormStateObject(localFormStateObject);
122+
};
123+
124+
const onFeedTypeChange = ({target}) => {
125+
const value = target.value
126+
const option = feedSourceTypeOptions.find((opt) => opt.value === value);
121127
const newFormStateObject = {...formStateObject};
128+
newFormStateObject.feedType = value;
122129
newFormStateObject.secrets = {...option.secretsDefault};
123130
setFormStateObject(newFormStateObject);
124131
}
125132

126-
useEffect(() => {
127-
if (formStateObject?.feedType) {
128-
if (option && option.template) {
129-
setDynamicFormElement(
130-
cloneElement(option.template, {
131-
handleInput,
132-
formStateObject,
133-
})
134-
);
135-
} else {
136-
setDynamicFormElement(null);
137-
}
138-
}
139-
}, [formStateObject?.feedType]);
140-
141133
/** Save feed source. */
142134
function saveFeedSource() {
143135
setLoadingMessage(t("loading-messages.saving-feed-source"));
136+
144137
if (saveMethod === "POST") {
145138
postV2FeedSources({
146139
feedSourceFeedSourceInput: JSON.stringify(formStateObject),
@@ -197,8 +190,9 @@ function FeedSourceManager({
197190
handleSubmit={handleSubmit}
198191
isLoading={isLoading || submitting}
199192
loadingMessage={loadingMessage}
193+
onFeedTypeChange={onFeedTypeChange}
194+
handleSecretInput={handleSecretInput}
200195
feedSourceTypeOptions={feedSourceTypeOptions}
201-
onFeedTypeChange={}
202196
dynamicFormElement={dynamicFormElement}
203197
mode={saveMethod}
204198
/>

src/components/feed-sources/templates/event-database-feed-type.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const EventDatabaseApiTemplate = ({
2121
? t("redacted-value-input-placeholder")
2222
: ""
2323
}
24-
value={formStateObject.host}
24+
value={formStateObject?.host}
2525
/>
2626
</>
2727
);

src/translations/da/common.json

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,24 +227,24 @@
227227
"create-new-theme": "Opret nyt tema"
228228
},
229229
"feed-sources-list": {
230-
"header": "Feed sources",
231-
"create-new-feed-source": "Opret ny feed source",
232-
"number-of-slides": "Slides tilknyttede",
230+
"header": "Datakilder",
231+
"number-of-slides": "Tilkoblede slides",
232+
"create-new-feed-source": "Opret ny datakilde",
233233
"loading-messages": {
234-
"deleting-feed-source": "Sletter feed source(s)",
235-
"loading-feed-sources": "Henter feed sources"
234+
"deleting-feed-source": "Sletter datakilde(r)",
235+
"loading-feed-sources": "Henter datakilder"
236236
},
237237
"error-messages": {
238-
"feed-source-delete-error": "Der skete en fejl da feed sourcen skulle slettes:"
238+
"feed-source-delete-error": "Der skete en fejl da datakilden skulle slettes:"
239239
},
240240
"success-messages": {
241-
"feed-source-delete": "Feed sourcen er blevet slettet"
241+
"feed-source-delete": "Datakilden er blevet slettet"
242242
},
243243
"columns": {
244244
"feed-type": "Type"
245245
},
246246
"info-modal": {
247-
"slides": "Feed sourcen er tilknyttet følgende slides"
247+
"slides": "Datakilde er tilknyttet følgende slides"
248248
}
249249
},
250250
"feed-source-manager": {
@@ -283,13 +283,10 @@
283283
}
284284
},
285285
"feed-source-form": {
286-
"logo-title": "Tilføj logo til feed source",
287-
"feed-source-name-label": "Feed source navn",
288-
"feed-source-description-label": "Feed source beskrivelse",
289-
"feed-source-feed-type-label": "Feed source type",
290-
"feed-source-supported-feed-output-type-label": "Feed output type",
291-
"feed-source-css-label": "Feed source CSS",
292-
"save-button": "Gem feed source",
286+
"feed-source-name-label": "Navn",
287+
"feed-source-description-label": "Beskrivelse",
288+
"feed-source-feed-type-label": "Type",
289+
"save-button": "Gem datakilde",
293290
"cancel-button": "Annuller"
294291
},
295292
"media-list": {
@@ -796,7 +793,7 @@
796793
"configuration-themes": "Temaer",
797794
"configuration-users": "Brugere",
798795
"activation-codes": "Aktiveringskoder",
799-
"configuration-feedsources": "Feed sources"
796+
"configuration-feedsources": "Datakilde"
800797
},
801798
"topbar": {
802799
"brand": "OS2Display",

0 commit comments

Comments
 (0)