diff --git a/linked-dependencies/matrix-react-sdk/src/components/views/spaces/SpacePanel.tsx b/linked-dependencies/matrix-react-sdk/src/components/views/spaces/SpacePanel.tsx index 555f548977..a2fab55664 100644 --- a/linked-dependencies/matrix-react-sdk/src/components/views/spaces/SpacePanel.tsx +++ b/linked-dependencies/matrix-react-sdk/src/components/views/spaces/SpacePanel.tsx @@ -74,6 +74,7 @@ import { UIComponent } from "../../../settings/UIFeature"; import { ThreadsActivityCentre } from "./threads-activity-centre/"; import AccessibleButton from "../elements/AccessibleButton"; import TchapUIFeature from "../../../../../../src/tchap/util/TchapUIFeature"; // :TCHAP: extend-remove-thread-buttons +import TchapGaufre from "../../../../../../src/tchap/components/views/common/Gaufre"; const useSpaces = (): [Room[], MetaSpace[], Room[], SpaceKey] => { const invites = useEventEmitterState(SpaceStore.instance, UPDATE_INVITED_SPACES, () => { @@ -423,6 +424,10 @@ const SpacePanel: React.FC = () => { {TchapUIFeature.isFeatureActiveForHomeserver("feature_thread") ? : null} {/** end :TCHAP: */} + + {/* :TCHAP: lasuite-gaufre-integration */} + + {/* end :TCHAP: */} )} diff --git a/modules/tchap-translations/tchap_translations.json b/modules/tchap-translations/tchap_translations.json index 10ea655569..b05895e6e8 100644 --- a/modules/tchap-translations/tchap_translations.json +++ b/modules/tchap-translations/tchap_translations.json @@ -753,5 +753,9 @@ "location_sharing|live_enable_description": { "en": "Please note: the history of your shared location will still be accessible to other members of the room even after the functionality is stopped", "fr": "Attention: l'historique des positions partagées sera accessible aux autres membres du salon meme après avoir arreté le partage" + }, + "lasuite_numerique": { + "en": "La suite numérique", + "fr": "La suite numérique" } } diff --git a/package.json b/package.json index c75b2ab11b..16f69b20b6 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "@types/react": "17.0.80" }, "dependencies": { + "@gouvfr-lasuite/integration": "^1.0.1", "@matrix-org/olm": "3.2.15", "@matrix-org/react-sdk-module-api": "^2.3.0", "gfm.css": "^1.1.2", diff --git a/patches/subtree-modifications.json b/patches/subtree-modifications.json index 5b9f4921f8..002931b5da 100644 --- a/patches/subtree-modifications.json +++ b/patches/subtree-modifications.json @@ -25,5 +25,11 @@ "src/components/views/rooms/RoomHeader.tsx", "src/components/views/settings/Notifications.tsx" ] + }, + "lasuite-gaufre-integration": { + "issue": "https://github.com/tchapgouv/tchap-web-v4/issues/1012", + "files": [ + "src/components/views/spaces/SpacePanel.tsx" + ] } } \ No newline at end of file diff --git a/res/css/common/_TchapGaufre.pcss b/res/css/common/_TchapGaufre.pcss new file mode 100644 index 0000000000..e9d5c75322 --- /dev/null +++ b/res/css/common/_TchapGaufre.pcss @@ -0,0 +1,8 @@ +.lasuite-gaufre-tchap { + border: solid 1px #9999fc; + color: #9999fc; + + &::before { + background: #9999fc; + } +} \ No newline at end of file diff --git a/src/tchap/components/views/common/Gaufre.tsx b/src/tchap/components/views/common/Gaufre.tsx new file mode 100644 index 0000000000..1874ac8512 --- /dev/null +++ b/src/tchap/components/views/common/Gaufre.tsx @@ -0,0 +1,90 @@ + +import React, { useEffect, useRef, useState } from 'react' +import '@gouvfr-lasuite/integration/dist/css/gaufre.css'; + +import ContextMenu, { ChevronFace, alwaysAboveRightOf, useContextMenu } from 'matrix-react-sdk/src/components/structures/ContextMenu'; +import AccessibleButton from 'matrix-react-sdk/src/components/views/elements/AccessibleButton'; +import classNames from 'classnames'; +import { _t } from '../../../../languageHandler'; +import "../../../../../res/css/common/_TchapGaufre.pcss"; + +const TchapGaufre: React.FC<{ + isPanelCollapsed: boolean; +}> = ({ isPanelCollapsed = false }) => { + + const [menuDisplayed, handle, openMenu, closeMenu] = useContextMenu(); + const gaufreListElmRef = useRef(null); + const gaufreContentRef = useRef(null); + const [loading, setLoading] = useState(true); + + const lasuiteOrigin = "https://integration.lasuite.numerique.gouv.fr" + + // Getting the content of the gaufre from la-suite + async function getLasuiteList() { + try { + const res = await fetch(`${lasuiteOrigin}/api/v1/gaufre`); + const html = await res.text(); + // replacing the origin urls explicitly by lasuiteOrigin to fetch the images + const updatedHtml = html.replace(/(src=|href=|url\()"\//g, `$1"${lasuiteOrigin}/`); + const parser = new DOMParser(); + const popupDocument = parser.parseFromString(updatedHtml, "text/html"); + + // creating an element to put the content retrieved from lasuite + const gaufreElm = document.createElement("div"); + gaufreElm.innerHTML = popupDocument.body.innerHTML; + gaufreListElmRef.current = gaufreElm; + setLoading(false); + } catch (error) { + console.error("Error fetching gaufre list:", error); + setLoading(false); + } + } + + useEffect(() => { + getLasuiteList() + }, []) + + useEffect(() => { + // only display the content if the content was fetched and the menu opened + if (menuDisplayed && gaufreContentRef.current && gaufreListElmRef.current && !gaufreContentRef.current.innerHTML) { + gaufreContentRef.current.appendChild(gaufreListElmRef.current); + } + }, [menuDisplayed]); + + + let contextMenu: JSX.Element | undefined; + + if (menuDisplayed && handle.current) { + contextMenu = ( + +
+
+
+ ); + } + + return ( + <> + + {!isPanelCollapsed ? _t("lasuite_numerique") : null} + + + {contextMenu} + + ); +}; + +export default TchapGaufre; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 9c2b49f2fc..c3ecbbddf1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1903,6 +1903,11 @@ resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.2.tgz#d8bae93ac8b815b2bd7a98078cf91e2724ef11e5" integrity sha512-J4yDIIthosAsRZ5CPYP/jQvUAQtlZTTD/4suA08/FEnlxqW3sKS9iAhgsa9VYLZ6vDHn/ixJgIqRQPotoBjxIw== +"@gouvfr-lasuite/integration@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@gouvfr-lasuite/integration/-/integration-1.0.1.tgz#26340c3c281fdcd13ea95bda08aee551d6b441e7" + integrity sha512-w1roGR5rG7RFoxmnvs0T1vg3lxB9AHws1Mmio6c3QsIR7GdltHC1HyHI/vZVq5V5TSoyLanlU4qG2lSi5uUnGw== + "@humanwhocodes/config-array@^0.11.14": version "0.11.14" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b"