Skip to content

Commit

Permalink
feat: unplug ode
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-Guillemin committed Sep 12, 2024
1 parent fc1c29d commit 113e348
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 21 deletions.
5 changes: 4 additions & 1 deletion frontend/src/app/root/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { LoadingScreen, Layout, useOdeClient } from "@edifice-ui/react";
import { LoadingScreen } from "@edifice-ui/react";
import { Outlet } from "react-router-dom";

import { Layout, useOdeClient } from "~/utils/context.utils";

function Root() {
console.log("i am in root with outlet");

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/common/ShareModal/ShareModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Button,
Tooltip,
Combobox,
useOdeClient,
} from "@edifice-ui/react";
import { UseMutationResult } from "@tanstack/react-query";
import {
Expand All @@ -32,6 +31,7 @@ import { FOLDER_TYPE } from "~/core/enums/folder-type.enum";
import { Folder } from "~/models/folder.model";
import { useBoardsNavigation } from "~/providers/BoardsNavigationProvider";
import { useFoldersNavigation } from "~/providers/FoldersNavigationProvider";
import { useOdeClient } from "~/utils/context.utils";
import "./ShareModal.scss";

export type ShareOptions = {
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/common/ShareModal/hooks/useSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { ChangeEvent, Dispatch, useEffect, useReducer } from "react";

import { Bookmark } from "@edifice-ui/icons";
import {
OptionListItemType,
useDebounce,
useIsAdml,
useOdeClient,
} from "@edifice-ui/react";
import { OptionListItemType, useDebounce, useIsAdml } from "@edifice-ui/react";
import {
ShareRight,
ShareRightAction,
Expand All @@ -18,6 +13,7 @@ import { useTranslation } from "react-i18next";

import { ShareAction } from "./useShare";
import { ShareOptions } from "../ShareModal";
import { useOdeClient } from "~/utils/context.utils";

type State = {
searchInputValue: string;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/common/ShareModal/hooks/useShare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useReducer } from "react";

import { useOdeClient, useUser, useToast } from "@edifice-ui/react";
import { useUser, useToast } from "@edifice-ui/react";
import {
odeServices,
PutShareResponse,
Expand All @@ -15,6 +15,7 @@ import { useDispatch } from "react-redux";
import { ShareOptions, ShareResourceMutation } from "../ShareModal";
import { boardsApi } from "~/services/api/boards.service.ts";
import { foldersApi } from "~/services/api/folders.service.ts";
import { useOdeClient } from "~/utils/context.utils";

interface UseShareResourceModalProps {
/**
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/board-item/BoardItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";

import { Card, useOdeClient, Tooltip } from "@edifice-ui/react";
import { Card, Tooltip } from "@edifice-ui/react";
import {
mdiAccountCircle,
mdiCalendarBlank,
Expand All @@ -18,6 +18,7 @@ import "./BoardItem.scss";
import { LAYOUT_TYPE } from "~/core/enums/layout-type.enum";
import { Board } from "~/models/board.model";
import { useBoardsNavigation } from "~/providers/BoardsNavigationProvider";
import { useOdeClient } from "~/utils/context.utils";

interface BoardItemProps {
board: {
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/empty-screen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useOdeClient, useOdeTheme, EmptyScreen } from "@edifice-ui/react";
import { useOdeTheme, EmptyScreen } from "@edifice-ui/react";
import { useTranslation } from "react-i18next";

import { useOdeClient } from "~/utils/context.utils";

export default function EmptyScreenApp(): JSX.Element {
const { appCode } = useOdeClient();
const { theme } = useOdeTheme();
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/folder-item/FolderItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useState } from "react";

import { Card, useOdeClient } from "@edifice-ui/react";
import { Card } from "@edifice-ui/react";
import "./FolderItem.scss";
import { mdiFolder, mdiFolderAccount } from "@mdi/js";
import Icon from "@mdi/react";
Expand All @@ -12,6 +12,7 @@ import { Board } from "~/models/board.model";
import { Folder } from "~/models/folder.model";
import { useFoldersNavigation } from "~/providers/FoldersNavigationProvider";
import { useMoveBoardsMutation } from "~/services/api/boards.service";
import { useOdeClient } from "~/utils/context.utils";
import { UserRights } from "~/utils/share.utils";

type FolderListProps = {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";

import { AppHeader, Button, useOdeClient } from "@edifice-ui/react";
import { AppHeader, Button } from "@edifice-ui/react";
import "./Header.scss";
import MenuIcon from "@mui/icons-material/Menu";
import IconButton from "@mui/material/IconButton";
Expand All @@ -9,6 +9,7 @@ import { useTranslation } from "react-i18next";
import myimg from "./uni-magneto.png";
import { FOLDER_TYPE } from "~/core/enums/folder-type.enum";
import { useFoldersNavigation } from "~/providers/FoldersNavigationProvider";
import { useOdeClient } from "~/utils/context.utils";
import { UserRights } from "~/utils/share.utils";

interface HeaderProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FunctionComponent, useState } from "react";

import { Modal, SearchBar, useOdeClient, useToggle } from "@edifice-ui/react";
import { Modal, SearchBar, useToggle } from "@edifice-ui/react";
import { Switch } from "@mui/material";
import { useSpring } from "@react-spring/web";
import { useTranslation } from "react-i18next";
Expand All @@ -13,6 +13,7 @@ import { Board, IBoardItemResponse } from "~/models/board.model";
import { Card as CardModel, ICardItemResponse } from "~/models/card.model";
import "./MagnetsCollectionModal.scss";
import { useGetAllBoardsQuery } from "~/services/api/boards.service";
import { useOdeClient } from "~/utils/context.utils";

type props = {
isOpen: boolean;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/move-board/MoveBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FunctionComponent, useState } from "react";

// eslint-disable-next-line
import { Button, Modal, TreeView, useOdeClient } from "@edifice-ui/react";
import { Button, Modal, TreeView } from "@edifice-ui/react";

import { useTranslation } from "react-i18next";

Expand All @@ -12,6 +12,7 @@ import { Folder, IFolderResponse } from "~/models/folder.model";
import { useBoardsNavigation } from "~/providers/BoardsNavigationProvider";
import { useFoldersNavigation } from "~/providers/FoldersNavigationProvider";
import { useMoveBoardsMutation } from "~/services/api/boards.service";
import { useOdeClient } from "~/utils/context.utils";
import { UserRights } from "~/utils/share.utils";

type props = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/share-modal/ShareModalMagneto.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FunctionComponent } from "react";

import { OdeClientProvider } from "@edifice-ui/react";
import { useOdeClient } from "@edifice-ui/react";
import { RightStringified } from "edifice-ts-client";

import { ShareModal } from "~/common/ShareModal";
import { RESOURCE_BIG_TYPE } from "~/core/enums/resource-big-type.enum";
import { useOdeClient } from "~/utils/context.utils";

type props = {
isOpen: boolean;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/side-bar/SideBarButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";

import { Button, useOdeClient, useToggle } from "@edifice-ui/react";
import { Button, useToggle } from "@edifice-ui/react";
import { mdiFolderPlus, mdiStar } from "@mdi/js";
import { Icon } from "@mdi/react";
import { useTranslation } from "react-i18next";
Expand All @@ -10,6 +10,7 @@ import { MagnetsCollectionModal } from "../magnets-collection/MagnetsCollectionM
import "./SideBar.scss";
import { FOLDER_TYPE } from "~/core/enums/folder-type.enum";
import { useFoldersNavigation } from "~/providers/FoldersNavigationProvider";
import { useOdeClient } from "~/utils/context.utils";
import { UserRights } from "~/utils/share.utils";

type SideBarButtonsProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ActionBar,
isActionAvailable,
useToggle,
useOdeClient,
checkUserRight,
} from "@edifice-ui/react";
import { useTransition, animated } from "@react-spring/web";
Expand All @@ -29,6 +28,7 @@ import { useFoldersNavigation } from "~/providers/FoldersNavigationProvider";
import { useDuplicateBoardMutation } from "~/services/api/boards.service";
import { useActions } from "~/services/queries";
import { useUserRightsStore } from "~/stores";
import { useOdeClient } from "~/utils/context.utils";

export interface ToasterContainerProps {
reset: () => void;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/tree-view/TreeViewContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useEffect, useState } from "react";
import "./TreeViewContent.scss";

import { TreeView, useOdeClient } from "@edifice-ui/react";
import { TreeView } from "@edifice-ui/react";
import { useTranslation } from "react-i18next";

import { useGetFolderTypeData } from "./utils";
Expand All @@ -11,6 +11,7 @@ import { Board } from "~/models/board.model";
import { Folder, IFolderResponse } from "~/models/folder.model";
import { useFoldersNavigation } from "~/providers/FoldersNavigationProvider";
import { useMoveBoardsMutation } from "~/services/api/boards.service";
import { useOdeClient } from "~/utils/context.utils";
import { UserRights } from "~/utils/share.utils";

type TreeViewContainerProps = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";

import { OdeClientProvider, ThemeProvider } from "@edifice-ui/react";
import {
QueryCache,
QueryClient,
Expand All @@ -16,6 +15,7 @@ import { FoldersNavigationProvider } from "./providers/FoldersNavigationProvider
import { router } from "./routes";
import { setupStore } from "./store";
import "~/i18n";
import { OdeClientProvider, ThemeProvider } from "./utils/context.utils";

const rootElement = document.getElementById("root");
const root = createRoot(rootElement!);
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/open/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ComponentPropsWithoutRef, type ReactNode } from "react";

interface LayoutProps extends ComponentPropsWithoutRef<any> {
/** Main content of an application */
children: ReactNode;
}

const Layout = ({ children }: LayoutProps) => {
return (
<div className="d-flex flex-column bg-white container-fluid">
{children}
</div>
);
};

export default Layout;
72 changes: 72 additions & 0 deletions frontend/src/open/utils/OdeClientProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { createContext, useContext, useEffect, useMemo } from "react";

import { OdeClientProps, OdeContextProps } from "@edifice-ui/react";
import { useTranslation } from "react-i18next";

import { confQuery, sessionQuery } from "./fakeData";

export const OdeClientContext = createContext<OdeContextProps | null>(null!);

export function OdeClientProvider({ children, params }: OdeClientProps) {
const appCode = params.app;

const { t } = useTranslation();
const translatedAppCode = t(appCode);

const init = confQuery?.isSuccess && sessionQuery?.isSuccess;

useEffect(() => {
const attributes = [
{
data: "html",
value: sessionQuery?.data?.currentLanguage || "fr",
},
// #WB-3137 Disable the translation of the content of the page which provoced issues
{
data: "translate",
value: "no",
},
];

attributes.forEach((attribute) => {
return document
.querySelector("html")
?.setAttribute(attribute.data, attribute.value as string);
});
}, [sessionQuery?.data]);

useEffect(() => {
document.title = `${translatedAppCode}`;
}, [appCode, sessionQuery.data, translatedAppCode]);

const values = useMemo(
() => ({
appCode,
applications: confQuery?.data?.applications,
confQuery,
currentApp: confQuery?.data?.currentApp,
currentLanguage: sessionQuery?.data?.currentLanguage,
init,
sessionQuery,
user: sessionQuery?.data?.user,
userDescription: sessionQuery?.data?.userDescription,
userProfile: sessionQuery?.data?.userProfile,
}),
[appCode, confQuery, init, sessionQuery],
);

return (
<OdeClientContext.Provider value={values}>
{children}
</OdeClientContext.Provider>
);
}

export function useOdeClient() {
const context = useContext(OdeClientContext);

if (!context) {
throw new Error(`Cannot be used outside of OdeClientProvider`);
}
return context;
}
Loading

0 comments on commit 113e348

Please sign in to comment.