Skip to content

Commit

Permalink
frontend Detail Drawer: Add detail drawer mode
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent T <[email protected]>
  • Loading branch information
vyncent-t committed Jan 2, 2024
1 parent fe7f2ed commit e3ddd00
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 14 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"storybook": "start-storybook -p 6006 -s public",
"build-typedoc": "npx typedoc",
"build-storybook": "build-storybook -s public -o ../docs/development/storybook",
"i18n": "npx --no-install i18next ./src/**/ts* ./src/**/**/*.ts* ./src/**/**/**/*.ts* -c ./src/i18n/i18next-parser.config.js",
"i18n": "npx --no-install i18next ./src/**/*.ts* ./src/**/**/*.ts* ./src/**/**/**/*.ts* -c ./src/i18n/i18next-parser.config.js",
"tsc": "tsc",
"make-version": "node ./make-env.js",
"postinstall": "patch-package"
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/App/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
() => {
Expand Down Expand Up @@ -197,6 +202,7 @@ export default function Layout({}: LayoutProps) {
)}
</Container>
</Box>
{isDetailDrawerEnabled && <DetailDrawer />}
</main>
<ActionsNotifier />
</Box>
Expand Down
59 changes: 59 additions & 0 deletions frontend/src/components/App/Settings/DrawerModeButton.tsx
Original file line number Diff line number Diff line change
@@ -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 = useTypedSelector(state => state.drawerMode.isDetailDrawerEnabled);
// const localDetailDrawerEnabled = localStorage.getItem('detailDrawerEnabled');
const [isDrawerEnabled, changeDetailDrawerEnabled] = useState<any>(isDetailDrawerEnabled);

if (isDetailDrawerEnabled) {
console.log('THE LOCAL STORAGE IS TRUE');
dispatch(setDetailDrawerEnabled(true));
console.log('READING FROM DISPATCHED STATE', isDetailDrawerEnabled);
} else {
console.log(" THE LOCAL STORAGE IS NULL, UNDEFINED, OR 'FALSE' ");
dispatch(setDetailDrawerEnabled(false));
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 (
<FormControlLabel
control={
<Switch
checked={isDetailDrawerEnabled}
onClick={drawerModeToggle}
name="drawerMode"
color="primary"
/>
}
// will need to replace label
label={t('translation|Drawer Mode')}
/>
);
}
5 changes: 5 additions & 0 deletions frontend/src/components/App/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -69,6 +70,10 @@ export default function Settings() {
name: t('translation|Theme'),
value: <ThemeChangeButton showBothIcons />,
},
{
name: t('translation|Details on list view'),
value: <DrawerModeButton />,
},
{
name: t('translation|Number of rows for tables'),
value: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,52 @@ exports[`Storyshots Settings General 1`] = `
</button>
</div>
</dd>
<dt
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-4 makeStyles-metadataNameCell css-1r6indk-MuiGrid-root"
>
Drawer Mode
</dt>
<dd
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-8 makeStyles-metadataCell makeStyles-valueCol css-r0umuq-MuiGrid-root"
>
<label
class="MuiFormControlLabel-root"
>
<span
class="MuiSwitch-root"
>
<span
aria-disabled="false"
class="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-1 MuiSwitch-switchBase MuiSwitch-colorPrimary"
>
<span
class="MuiIconButton-label"
>
<input
class="PrivateSwitchBase-input-4 MuiSwitch-input"
name="drawerMode"
type="checkbox"
value=""
/>
<span
class="MuiSwitch-thumb"
/>
</span>
<span
class="MuiTouchRipple-root"
/>
</span>
<span
class="MuiSwitch-track"
/>
</span>
<span
class="MuiTypography-root MuiFormControlLabel-label MuiTypography-body1"
>
Drawer Mode
</span>
</label>
</dd>
<dt
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-4 makeStyles-metadataNameCell css-1r6indk-MuiGrid-root"
>
Expand Down
124 changes: 124 additions & 0 deletions frontend/src/components/common/DetailDrawer/DetailDrawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// PUT BACK LATER ♦
// import { Button } from '@material-ui/core'; ♦
// import Box from '@material-ui/core/Box'; ♦
// import Drawer from '@material-ui/core/Drawer'; ♦
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';
import { useTypedSelector } from '../../../redux/reducers/reducers';

// PUT BACK LATER ♦
// import DetailDrawerFrame from './DetailDrawerFrame'; ♦

export interface DetailDrawerProps {
// isOpen: boolean;
onClose?: () => void;
children?: React.ReactNode;
}

// DELETE OR FIND A WAY TO USE CHILDREN LIKE IN CONSOLE LOG ♦
// export default function DetailDrawer({ children }: DetailDrawerProps) { ♦
export default function DetailDrawer({ children }: DetailDrawerProps) {
const dispatch = useDispatch();

// DELETE LATER - CONSOLE LOG ♦
console.log(children);

const isDetailDrawerOpen = useTypedSelector(state => state.drawerMode.isDetailDrawerOpen);
console.log('OFF SETTINGS isDetailDrawerOpen', isDetailDrawerOpen);

// USE CHANGEOPENDETAILDRAWER OR JUST OPEN DETAIL DRAWER ♦
// const [openDetailDrawer, changeOpenDetailDrawer] = useState<boolean>(isDetailDrawerOpen);
const [openDetailDrawer] = 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;
// const url = window.location.href;

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 && (
<>
<Box p={2}>
<Fab
style={{
position: 'fixed',
bottom: '20px',
right: '20px',
padding: '0 20px',
borderRadius: '1em',
}}
color="primary"
variant="extended"
onClick={toggleOpenDrawer}
>
Open Drawer
</Fab>
</Box>
</>
)} */}

{/* {openDetailDrawer && (
<>
<Drawer variant="temporary" anchor="right" open onClose={toggleOpenDrawer}>
<Box width={600} p={2}>
<DetailDrawerFrame title={'Example'} source={url} />
<Button onClick={toggleOpenDrawer}>Close Drawer</Button>
{children}
</Box>
</Drawer>
</>
)} */}

{/* {!openDetailDrawer && (
<>
<Drawer anchor="right" open onClose={toggleOpenDrawer}>
<Box width={200} p={2}>
<Button onClick={toggleOpenDrawer}>Open Drawer</Button>
{children}
</Box>
</Drawer>
</>
)} */}
</>
);
}

// * the drawer is not opening in minimized mode? persistent drawer fix maybe - https://mui.com/material-ui/react-drawer/#persistent-drawer
17 changes: 17 additions & 0 deletions frontend/src/components/common/DetailDrawer/DetailDrawerFrame.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import PodDetails from '../../pod/Details';

export interface DetailDrawerFrameProps {
title?: string;
source?: string;
}

export default function DetailDrawerFrame({ title }: DetailDrawerFrameProps) {
return (
<>
<p>{title}</p>
{/* <iframe title={title} src={source} width={'100%'} height={'100%'}></iframe> */}
<PodDetails />
</>
);
}
21 changes: 17 additions & 4 deletions frontend/src/components/common/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface LinkProps extends LinkBaseProps {
state?: {
[prop: string]: any;
};
drawerEnabled?: boolean;
}

export interface LinkObjectProps extends LinkBaseProps {
Expand All @@ -30,11 +31,23 @@ export interface LinkObjectProps extends LinkBaseProps {

function PureLink(props: React.PropsWithChildren<LinkProps | LinkObjectProps>) {
if ((props as LinkObjectProps).kubeObject) {
const { kubeObject, ...otherProps } = props as LinkObjectProps;
const { kubeObject, drawerEnabled, ...otherProps } = props as LinkObjectProps;
return (
<MuiLink component={RouterLink} to={kubeObject.getDetailsLink()} {...otherProps}>
{props.children || kubeObject.getName()}
</MuiLink>
<>
{drawerEnabled === true ? (
<MuiLink
component={RouterLink}
to={kubeObject.getDetailsLink() + '/drawer'}
{...otherProps}
>
{props.children || kubeObject.getName()}
</MuiLink>
) : (
<MuiLink component={RouterLink} to={kubeObject.getDetailsLink()} {...otherProps}>
{props.children || kubeObject.getName()}
</MuiLink>
)}
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`Storyshots ActionsNotifier None 1`] = `<div />`;
exports[`Storyshots ActionsNotifier Some 1`] = `
<div>
<div
class="makeStyles-bottom-4 makeStyles-left-5 makeStyles-root-1"
class="makeStyles-bottom-8 makeStyles-left-9 makeStyles-root-5"
>
<div
class="MuiCollapse-root MuiCollapse-entered"
Expand All @@ -18,22 +18,22 @@ exports[`Storyshots ActionsNotifier Some 1`] = `
class="MuiCollapse-wrapperInner"
>
<div
class="SnackbarItem-root-8 SnackbarItem-wrappedRoot-23 SnackbarItem-anchorOriginBottomLeft-14"
class="SnackbarItem-root-12 SnackbarItem-wrappedRoot-27 SnackbarItem-anchorOriginBottomLeft-18"
>
<div
aria-describedby="notistack-snackbar"
class="ForwardRef-root-24 SnackbarItem-contentRoot-15"
class="ForwardRef-root-28 SnackbarItem-contentRoot-19"
role="alert"
style="webkit-transform: none; transform: none; webkit-transition: -webkit-transform 225ms cubic-bezier(0.0, 0, 0.2, 1) 0ms; transition: transform 225ms cubic-bezier(0.0, 0, 0.2, 1) 0ms;"
>
<div
class="SnackbarItem-message-21"
class="SnackbarItem-message-25"
id="notistack-snackbar"
>
Some message
</div>
<div
class="SnackbarItem-action-22"
class="SnackbarItem-action-26"
>
<button
class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textSecondary MuiButton-sizeSmall MuiButton-textSizeSmall MuiButton-root MuiButton-text MuiButton-textSecondary MuiButton-sizeSmall MuiButton-textSizeSmall css-u3zvl7-MuiButtonBase-root-MuiButton-root"
Expand Down
Loading

0 comments on commit e3ddd00

Please sign in to comment.