diff --git a/frontend/src/components/App/Layout.tsx b/frontend/src/components/App/Layout.tsx index 43dd210327..6a3b3a5145 100644 --- a/frontend/src/components/App/Layout.tsx +++ b/frontend/src/components/App/Layout.tsx @@ -17,6 +17,7 @@ import { useTypedSelector } from '../../redux/reducers/reducers'; import store from '../../redux/stores/store'; import ActionsNotifier from '../common/ActionsNotifier'; import AlertNotification from '../common/AlertNotification'; +import DetailDrawer from '../common/DetailDrawer/DetailDrawer'; import Sidebar, { NavigationTabs } from '../Sidebar'; import RouteSwitcher from './RouteSwitcher'; import TopBar from './TopBar'; @@ -93,6 +94,10 @@ export default function Layout({}: LayoutProps) { const { t } = useTranslation(); const clusterInURL = getCluster(); + // DETAIL DRAWER MODE + const isDetailDrawerEnabled = useTypedSelector(state => state.drawerMode.isDetailDrawerEnabled); + console.log('LAY - isDetailDrawerEnabled', isDetailDrawerEnabled); + useEffect(() => { window.clusterConfigFetchHandler = setInterval( () => { @@ -197,6 +202,7 @@ export default function Layout({}: LayoutProps) { )} + {isDetailDrawerEnabled && } diff --git a/frontend/src/components/App/Settings/DrawerModeButton.tsx b/frontend/src/components/App/Settings/DrawerModeButton.tsx new file mode 100644 index 0000000000..23e000235f --- /dev/null +++ b/frontend/src/components/App/Settings/DrawerModeButton.tsx @@ -0,0 +1,59 @@ +import { FormControlLabel, Switch } from '@material-ui/core'; +import React from 'react'; +import { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { useDispatch } from 'react-redux'; +import { setDetailDrawerEnabled } from '../../../redux/drawerModeSlice'; +import { useTypedSelector } from '../../../redux/reducers/reducers'; + +export default function DrawerModeButton() { + const dispatch = useDispatch(); + const { t } = useTranslation('translation'); + // This will fix the problem of the project refreshing the state away from needed position + + // DETAIL DRAWER MODE + // const isDetailDrawerEnabled = localStorage.getItem('detailDrawerEnabled'); + const isDetailDrawerEnabled = useTypedSelector(state => state.drawerMode.isDetailDrawerEnabled); + const [isDrawerEnabled, changeDetailDrawerEnabled] = useState(isDetailDrawerEnabled); + + if (!isDetailDrawerEnabled) { + console.log(" THE LOCAL STORAGE IS NULL, UNDEFINED, OR 'FALSE' "); + dispatch(setDetailDrawerEnabled(false)); + console.log('READING FROM DISPATCHED STATE', isDetailDrawerEnabled); + } else { + console.log('THE LOCAL STORAGE IS TRUE'); + dispatch(setDetailDrawerEnabled(true)); + console.log('READING FROM DISPATCHED STATE', isDetailDrawerEnabled); + } + + console.log('BUTTON - isDetailDrawerEnabled', isDetailDrawerEnabled); + + // the useEffect will run everytime the isDrawerEnabled state changes, which is everytime the user clicks the switch button because the switch button changes the state of isDrawerEnabled + useEffect(() => { + dispatch(setDetailDrawerEnabled(isDrawerEnabled)); + console.log('ON SETTINGS'); + console.log(localStorage.getItem('detailDrawerEnabled')); + }, [isDrawerEnabled]); + + // this function takes in the current changes and updates it, this kicks off the useEffect that is listening for changes to newDrawerEnabled + function drawerModeToggle() { + console.log('drawerModeToggle'); + changeDetailDrawerEnabled(!isDrawerEnabled); + } + + // NOTICE THAT WE DO NOT USE isDrawerEnabled TO DETERMINE HOW THE SWITCH IS RENDERED UNDER THE CHECKED PROP, THIS IS BECAUSE THE USEEFFECT WILL RERENDER THE COMPONENT WITH THE NEW STATE + return ( + + } + // will need to replace label + label={t('translation|Drawer Mode')} + /> + ); +} diff --git a/frontend/src/components/App/Settings/Settings.tsx b/frontend/src/components/App/Settings/Settings.tsx index 73b1bce3e4..e45b1b1dc0 100644 --- a/frontend/src/components/App/Settings/Settings.tsx +++ b/frontend/src/components/App/Settings/Settings.tsx @@ -9,6 +9,7 @@ import { setAppSettings } from '../../../redux/configSlice'; import { defaultTableRowsPerPageOptions } from '../../../redux/configSlice'; import { ActionButton, NameValueTable, SectionBox } from '../../common'; import TimezoneSelect from '../../common/TimezoneSelect'; +import DrawerModeButton from './DrawerModeButton'; import { useSettings } from './hook'; import NumRowsInput from './NumRowsInput'; import ThemeChangeButton from './ThemeChangeButton'; @@ -69,6 +70,10 @@ export default function Settings() { name: t('translation|Theme'), value: , }, + { + name: t('translation|Drawer Mode'), + value: , + }, { name: t('translation|Number of rows for tables'), value: ( diff --git a/frontend/src/components/App/Settings/__snapshots__/Settings.stories.storyshot b/frontend/src/components/App/Settings/__snapshots__/Settings.stories.storyshot index 09b91fde7a..52b65bbd66 100644 --- a/frontend/src/components/App/Settings/__snapshots__/Settings.stories.storyshot +++ b/frontend/src/components/App/Settings/__snapshots__/Settings.stories.storyshot @@ -158,6 +158,52 @@ exports[`Storyshots Settings General 1`] = ` +
+ Drawer Mode +
+
+ +
diff --git a/frontend/src/components/common/DetailDrawer/DetailDrawer.tsx b/frontend/src/components/common/DetailDrawer/DetailDrawer.tsx new file mode 100644 index 0000000000..8aad0dca26 --- /dev/null +++ b/frontend/src/components/common/DetailDrawer/DetailDrawer.tsx @@ -0,0 +1,103 @@ +import { Button } from '@material-ui/core'; +import Box from '@material-ui/core/Box'; +import Drawer from '@material-ui/core/Drawer'; +import { Fab } from '@mui/material'; +import React from 'react'; +import { useState } from 'react'; +import { useEffect } from 'react'; +import { useDispatch } from 'react-redux'; +// import { useLocation } from 'react-router-dom'; +// import { useParams } from 'react-router-dom'; +import { setDetailDrawerOpen } from '../../../redux/drawerModeSlice'; + +export interface DetailDrawerProps { + // isOpen: boolean; + onClose?: () => void; + children?: React.ReactNode; +} + +export default function DetailDrawer({ children }: DetailDrawerProps) { + const dispatch = useDispatch(); + // const isDetailDrawerEnabled = useTypedSelector(state => state.drawerMode.isDetailDrawerEnabled); + + const isDetailDrawerOpen = localStorage.getItem('detailDrawerOpen'); + + console.log('OFF SETTINGS isDetailDrawerOpen', isDetailDrawerOpen); + + const [openDetailDrawer, changeOpenDetailDrawer] = useState(Boolean(isDetailDrawerOpen)); + console.log('openDetailDrawer', openDetailDrawer); + + useEffect(() => { + console.log('Toggle Open Drawer', openDetailDrawer); + dispatch(setDetailDrawerOpen(openDetailDrawer)); + }, [openDetailDrawer]); + + // * Trying to find a way to get the path and params to determine if it should be rendered within the iframe + const location = window.location.pathname; + + console.log('WINDOW', window.location); + + const pathDetails = ['/pods/']; + + useEffect(() => { + for (let i = 0; i < pathDetails.length; i++) { + if (location.includes(pathDetails[i])) { + console.log('URL PAIR MATCHED', pathDetails[i], location); + } + } + }, [window.location.href]); + + // * DOES NOT WORK, WILL PRINT '{}' WHEN CONSOLE LOG params + // const location = useLocation(); + // const params = useParams(); + + useEffect(() => { + console.log('location changed'); + console.log('LOCATION', location); + + // console.log('PARAMS', params); + }, [location]); + + function toggleOpenDrawer() { + changeOpenDetailDrawer(!openDetailDrawer); + } + + return ( + <> + {!openDetailDrawer && ( + <> + + + Open Drawer + + + + )} + + {openDetailDrawer && ( + <> + + + {/* */} + + {children} + + + + )} + + ); +} + +// * the drawer is not opening in minimized mode? persistent drawer fix maybe - https://mui.com/material-ui/react-drawer/#persistent-drawer diff --git a/frontend/src/components/common/DetailDrawer/DetailDrawerFrame.tsx b/frontend/src/components/common/DetailDrawer/DetailDrawerFrame.tsx new file mode 100644 index 0000000000..0778cfba0e --- /dev/null +++ b/frontend/src/components/common/DetailDrawer/DetailDrawerFrame.tsx @@ -0,0 +1,14 @@ +import React from 'react'; + +export interface DetailDrawerFrameProps { + title?: string; + source: string; +} + +export default function DetailDrawerFrame({ title, source }: DetailDrawerFrameProps) { + return ( + <> + + + ); +} diff --git a/frontend/src/components/common/__snapshots__/ActionsNotifier.stories.storyshot b/frontend/src/components/common/__snapshots__/ActionsNotifier.stories.storyshot index e8cc3287b0..135224ef76 100644 --- a/frontend/src/components/common/__snapshots__/ActionsNotifier.stories.storyshot +++ b/frontend/src/components/common/__snapshots__/ActionsNotifier.stories.storyshot @@ -5,7 +5,7 @@ exports[`Storyshots ActionsNotifier None 1`] = `
`; exports[`Storyshots ActionsNotifier Some 1`] = `