Skip to content

Commit

Permalink
3208: Added colibo feed type
Browse files Browse the repository at this point in the history
  • Loading branch information
tuj committed Dec 18, 2024
1 parent c01afab commit fa107ff
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 28 deletions.
61 changes: 48 additions & 13 deletions src/components/feed-sources/feed-source-form.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { React } from "react";
import { Button } from "react-bootstrap";
import { Alert, Button } from "react-bootstrap";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import PropTypes from "prop-types";
Expand All @@ -13,6 +13,7 @@ import FormInput from "../util/forms/form-input";
import CalendarApiFeedType from "./templates/calendar-api-feed-type";
import NotifiedFeedType from "./templates/notified-feed-type";
import EventDatabaseApiFeedType from "./templates/event-database-feed-type";
import ColiboFeedType from "./templates/colibo-feed-type.jsx";

/**
* The feed-source form component.
Expand Down Expand Up @@ -47,6 +48,10 @@ function FeedSourceForm({
const { t } = useTranslation("common", { keyPrefix: "feed-source-form" });
const navigate = useNavigate();

const typeInOptions =
!feedSource?.feedType ||
feedSourceTypeOptions.find((el) => el.value === feedSource.feedType);

return (
<>
<Form>
Expand All @@ -72,32 +77,62 @@ function FeedSourceForm({
value={feedSource.description}
onChange={handleInput}
/>
<FormSelect
name="feedType"
formGroupClasses="mb-2"
label={t("feed-source-feed-type-label")}
value={feedSource.feedType}
onChange={onFeedTypeChange}
disabled={mode === "PUT"}
options={feedSourceTypeOptions}
/>
{typeInOptions && (
<FormSelect
name="feedType"
formGroupClasses="mb-2"
label={t("feed-source-feed-type-label")}
value={feedSource.feedType}
onChange={onFeedTypeChange}
disabled={mode === "PUT"}
options={feedSourceTypeOptions}
/>
)}
{!typeInOptions && (
<>
<FormInput
name="title"
formGroupClasses="mb-2"
type="text"
disabled
label={t("feed-source-feed-type-label")}
value={feedSource.feedType}
onChange={() => {}}
/>
<Alert className="mt-4" variant="warning">
{t("feed-type-not-supported")}
</Alert>
</>
)}

{feedSource?.feedType === "App\\Feed\\CalendarApiFeedType" && (
{feedSource?.feedType ===
"App\\Feed\\SourceType\\Calendar\\CalendarApiFeedType" && (
<CalendarApiFeedType
handleInput={handleSecretInput}
formStateObject={feedSource.secrets}
mode={mode}
feedSourceId={feedSource["@id"]}
/>
)}
{feedSource?.feedType === "App\\Feed\\EventDatabaseApiFeedType" && (
{feedSource?.feedType ===
"App\\Feed\\SourceType\\Colibo\\ColiboFeedType" && (
<ColiboFeedType
handleInput={handleSecretInput}
formStateObject={feedSource.secrets}
mode={mode}
feedSourceId={feedSource["@id"]}
/>
)}
{feedSource?.feedType ===
"App\\Feed\\SourceType\\EventDatabase\\EventDatabaseApiFeedType" && (
<EventDatabaseApiFeedType
handleInput={handleSecretInput}
formStateObject={feedSource.secrets}
mode={mode}
/>
)}
{feedSource?.feedType === "App\\Feed\\NotifiedFeedType" && (
{feedSource?.feedType ===
"App\\Feed\\SourceType\\Notified\\NotifiedFeedType" && (
<NotifiedFeedType
handleInput={handleSecretInput}
formStateObject={feedSource.secrets}
Expand Down
33 changes: 22 additions & 11 deletions src/components/feed-sources/feed-source-manager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,42 @@ function FeedSourceManager({

const feedSourceTypeOptions = [
{
value: "App\\Feed\\EventDatabaseApiFeedType",
value: "App\\Feed\\SourceType\\Calendar\\CalendarApiFeedType",
title: t("dynamic-fields.calendar-api-feed-type.title"),
key: "0",
secretsDefault: {
locations: [],
},
},
{
value: "App\\Feed\\SourceType\\Colibo\\ColiboFeedType",
title: t("colibo-feed-type.title"),
key: "5",
secretsDefault: {
api_base_uri: "",
client_id: "",
client_secret: "",
recipients: [],
},
},
{
value: "App\\Feed\\SourceType\\EventDatabase\\EventDatabaseApiFeedType",
title: t("dynamic-fields.event-database-api-feed-type.title"),
key: "1",
secretsDefault: {
host: "",
},
},
{
value: "App\\Feed\\NotifiedFeedType",
value: "App\\Feed\\SourceType\\Notified\\NotifiedFeedType",
title: t("dynamic-fields.notified-feed-type.title"),
key: "2",
secretsDefault: {
token: "",
},
},
{
value: "App\\Feed\\CalendarApiFeedType",
title: t("dynamic-fields.calendar-api-feed-type.title"),
key: "0",
secretsDefault: {
locations: [],
},
},
{
value: "App\\Feed\\RssFeedType",
value: "App\\Feed\\SourceType\\Rss\\RssFeedType",
title: t("dynamic-fields.rss-feed-type.title"),
key: "4",
secretsDefault: {},
Expand Down
107 changes: 107 additions & 0 deletions src/components/feed-sources/templates/colibo-feed-type.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { React, useEffect, useState } from "react";
import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
import { Alert } from "react-bootstrap";
import MultiselectFromEndpoint from "../../slide/content/multiselect-from-endpoint";
import ConfigLoader from "../../../config-loader";
import FormInput from "../../util/forms/form-input.jsx";

const ColiboFeedType = ({
feedSourceId,
handleInput,
formStateObject,
mode,
}) => {
const { t } = useTranslation("common", {
keyPrefix: "colibo-feed-type",
});

const [optionsEndpoint, setOptionsEndpoint] = useState(null);

useEffect(() => {
if (feedSourceId && feedSourceId !== "") {
ConfigLoader.loadConfig().then((config) => {
let endpoint = config.api;
endpoint = endpoint.replace(/\/$/, "");
endpoint += feedSourceId;
endpoint += "/config/FeedEntryRecipients";

setOptionsEndpoint(endpoint);
});
}
}, [feedSourceId]);

return (
<>
{!feedSourceId && (
<Alert className="mt-4" variant="warning">
{t("save-before-recipients-can-be-set")}
</Alert>
)}

<FormInput
name="api_base_uri"
type="text"
label={t("api-base-uri")}
className="mb-2"
onChange={handleInput}
placeholder={
mode === "PUT" ? t("redacted-value-input-placeholder") : ""
}
value={formStateObject?.api_base_uri}
/>

<FormInput
name="client_id"
type="text"
className="mb-2"
label={t("client-id")}
onChange={handleInput}
placeholder={
mode === "PUT" ? t("redacted-value-input-placeholder") : ""
}
value={formStateObject?.client_id}
/>

<FormInput
name="client_secret"
type="text"
label={t("client-secret")}
onChange={handleInput}
placeholder={
mode === "PUT" ? t("redacted-value-input-placeholder") : ""
}
value={formStateObject?.client_secret}
/>

<Alert className="mt-4" variant="info">
{t("values-info")}
</Alert>

{optionsEndpoint && (
<MultiselectFromEndpoint
onChange={handleInput}
name="recipients"
disableSearch={false}
label={t("recipients")}
value={formStateObject.recipients ?? []}
optionsEndpoint={optionsEndpoint}
/>
)}
</>
);
};

ColiboFeedType.propTypes = {
handleInput: PropTypes.func,
formStateObject: PropTypes.shape({
api_base_uri: PropTypes.string,
client_id: PropTypes.string,
client_secret: PropTypes.string,
recipients: PropTypes.arrayOf(PropTypes.string),
}),
feedSourceId: PropTypes.string,
mode: PropTypes.string,
};

export default ColiboFeedType;
2 changes: 1 addition & 1 deletion src/components/slide/content/content-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function ContentForm({
}

returnElement = (
<div key={formData.key}>
<div key={formData.key} className={formData.formGroupClasses}>
{formData?.label && (
<label htmlFor={formData.name} className="form-label">
{formData.label}
Expand Down
3 changes: 2 additions & 1 deletion src/components/slide/content/feed-selector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ function FeedSelector({
value={getValueFromConfiguration(element.name)}
label={element.label}
optionsEndpoint={element.endpoint}
singleSelect={formElement.singleSelect ?? false}
disableSearch={element.disableSearch ?? false}
singleSelect={element.singleSelect ?? false}
/>
);
}
Expand Down
18 changes: 16 additions & 2 deletions src/translations/da/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@
"save-feed-source-error": "Der skete en fejl da feed source skulle gemmes:",
"load-feed-source-error": "Der skete en fejl da feed source med følgende id: {{id}} skulle hentes:"
},
"colibo-feed-type": {
"title": "Colibo"
},
"dynamic-fields": {
"event-database-api-feed-type": {
"title": "Eventdatabase API",
Expand All @@ -273,20 +276,21 @@
"redacted-value-input-placeholder": "Skjult værdi"
},
"calendar-api-feed-type": {
"title": "Kalender feed",
"title": "Kalender",
"locations": "Lokationer",
"redacted-value-input-placeholder": "Skjult værdi",
"save-before-locations-can-be-set": "Bemærk! Datakilden skal gemmes før der kan tilkobles lokationer. Gem og åbn datakilden igen."
},
"rss-feed-type": {
"title": "RSS feed"
"title": "RSS"
}
}
},
"feed-source-form": {
"feed-source-name-label": "Navn",
"feed-source-description-label": "Beskrivelse",
"feed-source-feed-type-label": "Type",
"feed-type-not-supported": "Typen understøttes ikke af administrationen.",
"save-button": "Gem datakilde",
"cancel-button": "Annuller"
},
Expand Down Expand Up @@ -1075,5 +1079,15 @@
"active": "Aktiv",
"future": "Fremtidig",
"expired": "Udløbet"
},
"colibo-feed-type": {
"title": "Colibo feed",
"api-base-uri": "API Base URI",
"client-id": "Client ID",
"client-secret": "Client Secret",
"values-info": "Værdierne Client ID og Client Secret findes ved at oprette en API klient i \"Systemadministration\" -> \"API adgangshåndtering\" i Colibo intranet.",
"recipients": "Modtagergrupper",
"redacted-value-input-placeholder": "Skjult værdi",
"save-before-recipients-can-be-set": "Bemærk! Datakilden skal gemmes før der kan tilkobles modtagergrupper. Gem og åbn datakilden igen."
}
}

0 comments on commit fa107ff

Please sign in to comment.