Skip to content

Commit 899540e

Browse files
committed
2321: Fixed feed integrations to align with api
1 parent d6916c5 commit 899540e

File tree

6 files changed

+73
-64
lines changed

6 files changed

+73
-64
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +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";
13+
import CalendarApiFeedType from "./templates/calendar-api-feed-type.jsx";
1414
import NotifiedFeedType from "./templates/notified-feed-type.jsx";
15-
import EventDatabaseFeedType from "./templates/event-database-feed-type.jsx";
15+
import EventDatabaseApiFeedType from "./templates/event-database-feed-type.jsx";
1616

1717
/**
1818
* The feed-source form component.
@@ -82,14 +82,14 @@ function FeedSourceForm({
8282
/>
8383

8484
{feedSource?.feedType === "App\\Feed\\CalendarApiFeedType" &&
85-
(<CalendarFeedType handleInput={handleSecretInput} formStateObject={feedSource.secrets} mode={mode} />)
85+
(<CalendarApiFeedType handleInput={handleSecretInput} formStateObject={feedSource.secrets} mode={mode} feedSourceId={feedSource['@id']} />)
86+
}
87+
{feedSource?.feedType === "App\\Feed\\EventDatabaseApiFeedType" &&
88+
(<EventDatabaseApiFeedType handleInput={handleSecretInput} formStateObject={feedSource.secrets} mode={mode} />)
8689
}
8790
{feedSource?.feedType === "App\\Feed\\NotifiedFeedType" &&
8891
(<NotifiedFeedType handleInput={handleSecretInput} formStateObject={feedSource.secrets} mode={mode} />)
8992
}
90-
{feedSource?.feedType === "App\\Feed\\EventDatabaseApiFeedType" &&
91-
(<EventDatabaseFeedType handleInput={handleSecretInput} formStateObject={feedSource.secrets} mode={mode} />)
92-
}
9393
</ContentBody>
9494
<ContentFooter>
9595
<Button

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "../util/list/toast-component/display-toast";
1414
import EventDatabaseFeedType from "./templates/event-database-feed-type.jsx";
1515
import NotifiedFeedType from "./templates/notified-feed-type.jsx";
16-
import CalendarFeedType from "./templates/calendar-feed-type.jsx";
16+
import CalendarApiFeedType from "./templates/calendar-api-feed-type.jsx";
1717

1818
/**
1919
* The theme manager component.
@@ -82,9 +82,9 @@ function FeedSourceManager({
8282
{
8383
value: "App\\Feed\\CalendarApiFeedType",
8484
title: t("dynamic-fields.calendar-api-feed-type.title"),
85-
key: "3",
85+
key: "0",
8686
secretsDefault: {
87-
"resources": []
87+
"locations": []
8888
},
8989
},
9090
{
@@ -109,16 +109,19 @@ function FeedSourceManager({
109109

110110
/** Set loaded data into form state. */
111111
useEffect(() => {
112-
setFormStateObject({ ...initialState });
112+
const newState = { ...initialState };
113+
114+
if (newState.secrets instanceof Array) {
115+
newState.secrets = {};
116+
}
117+
118+
setFormStateObject(newState);
113119
}, [initialState]);
114120

115121
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+
const secrets = { ...formStateObject.secrets };
123+
secrets[target.id] = target.value;
124+
setFormStateObject({ ...formStateObject, secrets: secrets });
122125
};
123126

124127
const onFeedTypeChange = ({target}) => {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { React } from "react";
2+
import PropTypes from "prop-types";
3+
import { useTranslation } from "react-i18next";
4+
import MultiselectFromEndpoint from "../../slide/content/multiselect-from-endpoint.jsx";
5+
import { Alert } from "react-bootstrap";
6+
7+
const CalendarApiFeedType = ({ feedSourceId, handleInput, formStateObject }) => {
8+
const { t } = useTranslation("common", {
9+
keyPrefix: "feed-source-manager.dynamic-fields.calendar-api-feed-type"
10+
});
11+
12+
return (
13+
<>
14+
{!feedSourceId && (<Alert className="mt-4" variant="warning">
15+
{t("save-before-locations-can-be-set")}
16+
</Alert>)}
17+
{feedSourceId &&
18+
<MultiselectFromEndpoint
19+
onChange={handleInput}
20+
name={"locations"}
21+
label={t("locations")}
22+
value={formStateObject.locations ?? []}
23+
optionsEndpoint={"https://displayapiservice.local.itkdev.dk" + feedSourceId + "/config/locations"}
24+
/>
25+
}
26+
</>
27+
);
28+
};
29+
30+
CalendarApiFeedType.propTypes = {
31+
handleInput: PropTypes.func,
32+
formStateObject: PropTypes.shape({
33+
locations: PropTypes.arrayOf(PropTypes.string)
34+
}),
35+
mode: PropTypes.string
36+
};
37+
38+
export default CalendarApiFeedType;

src/components/feed-sources/templates/calendar-feed-type.jsx

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/components/slide/content/feed-selector.jsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,25 @@ function FeedSelector({
4646
supportedFeedOutputType: formElement.supportedFeedOutputType,
4747
});
4848

49+
useEffect(() => {
50+
if (feedSourceOptions?.length === 1) {
51+
// If there's only one feed source option select it.
52+
const feedSource = feedSourceOptions[0]['@id'];
53+
const configuration = value?.configuration ?? {};
54+
const newValue = { ...value, feedSource, configuration };
55+
onChange(newValue);
56+
}
57+
}, [feedSourceOptions]);
58+
4959
useEffect(() => {
5060
if (feedSourcesData) {
51-
if (feedSourcesData["hydra:member"].length === 1) {
52-
// If there's only one feed source option select it.
53-
const feedSource = feedSourcesData["hydra:member"][0]["@id"];
54-
const configuration = value?.configuration ?? {};
55-
const newValue = { ...value, feedSource, configuration };
56-
onChange(newValue);
57-
}
5861
setFeedSourceOptions(
5962
feedSourcesData["hydra:member"].map((source) => {
6063
return {
6164
title: source.title,
6265
value: source["@id"],
6366
key: source["@id"],
67+
id: source["@id"],
6468
};
6569
})
6670
);
@@ -153,13 +157,13 @@ function FeedSelector({
153157
{feedSourcesLoadingError && <div>Error</div>}
154158
{feedSourcesLoading && <Spinner animation="border" />}
155159

156-
{feedSourcesData && feedSourceOptions && (
160+
{feedSourcesData && feedSourceOptions?.length > 0 && (
157161
<MultiSelectComponent
158162
options={feedSourceOptions}
159163
selected={getSelected(value?.feedSource)}
160164
name="feedSource"
161165
labelledBy="Select"
162-
singleSelect={formElement.singleSelect ?? false}
166+
singleSelect={true}
163167
overrideStrings={{
164168
allItemsAreSelected: t("feed-selector.all-selected"),
165169
clearSelected: t("feed-selector.clear-selection"),

src/translations/da/common.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@
274274
},
275275
"calendar-api-feed-type": {
276276
"title": "Kalender feed",
277-
"resources": "Ressourcer",
278-
"redacted-value-input-placeholder": "Skjult værdi"
277+
"locations": "Lokationer",
278+
"redacted-value-input-placeholder": "Skjult værdi",
279+
"save-before-locations-can-be-set": "Bemærk! Datakilden skal gemmes før der kan tilkobles lokationer. Gem og åbn datakilden igen."
279280
},
280281
"rss-feed-type": {
281282
"title": "RSS feed"

0 commit comments

Comments
 (0)