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 Dec 11, 2023
1 parent fe7f2ed commit 5e443f0
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 5 deletions.
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 = localStorage.getItem('detailDrawerEnabled');
const isDetailDrawerEnabled = useTypedSelector(state => state.drawerMode.isDetailDrawerEnabled);
const [isDrawerEnabled, changeDetailDrawerEnabled] = useState<any>(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 (
<FormControlLabel
control={
<Switch
checked={Boolean(isDrawerEnabled)}
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|Drawer Mode'),
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
78 changes: 78 additions & 0 deletions frontend/src/components/common/DetailDrawer/DetailDrawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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 { 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>(Boolean(isDetailDrawerOpen));
console.log('openDetailDrawer', openDetailDrawer);

useEffect(() => {
console.log('Toggle Open Drawer', openDetailDrawer);
dispatch(setDetailDrawerOpen(openDetailDrawer));
}, [openDetailDrawer]);

function toggleOpenDrawer() {
changeOpenDetailDrawer(!openDetailDrawer);
}

return (
<>
{!openDetailDrawer && (
<>
<Box p={2}>
<Fab
style={{
position: 'fixed',
bottom: '20px',
right: '20px',
}}
color="primary"
variant="extended"
onClick={() => toggleOpenDrawer()}
>
Open
</Fab>
</Box>
</>
)}

{openDetailDrawer && (
<>
<Drawer
hideBackdrop
variant="temporary"
anchor="right"
open
onClose={() => toggleOpenDrawer()}
>
<Box width={600} p={2}>
<Button onClick={() => toggleOpenDrawer()}>Close</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
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
1 change: 1 addition & 0 deletions frontend/src/i18n/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Visible": "Sichtbar",
"Plugins": "Plugins",
"Save & Apply": "Speichern & Anwenden",
"Drawer Mode": "",
"Enter a value between {{ minRows }} and {{ maxRows }}.": "Geben Sie einen Wert zwischen {{ minRows }} und {{ maxRows }} ein.",
"Custom row value": "Benutzerdefinierter Zeilenwert",
"Apply": "Anwenden",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Visible": "Visible",
"Plugins": "Plugins",
"Save & Apply": "Save & Apply",
"Drawer Mode": "Drawer Mode",
"Enter a value between {{ minRows }} and {{ maxRows }}.": "Enter a value between {{ minRows }} and {{ maxRows }}.",
"Custom row value": "Custom row value",
"Apply": "Apply",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Visible": "Visible",
"Plugins": "Plugins",
"Save & Apply": "Guardar & Aplicar",
"Drawer Mode": "",
"Enter a value between {{ minRows }} and {{ maxRows }}.": "Introduzca un valor entre {{ minRows }} y {{ maxRows }}.",
"Custom row value": "Núm. de líneas personalizado",
"Apply": "Aplicar",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Visible": "Visible",
"Plugins": "Plugins",
"Save & Apply": "Sauvegarder et appliquer",
"Drawer Mode": "",
"Enter a value between {{ minRows }} and {{ maxRows }}.": "Entrez une valeur entre {{ minRows }} et {{ maxRows }}.",
"Custom row value": "Valeur de ligne personnalisée",
"Apply": "Appliquer",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Visible": "Visível",
"Plugins": "Plugins",
"Save & Apply": "Guardar & Aplicar",
"Drawer Mode": "",
"Enter a value between {{ minRows }} and {{ maxRows }}.": "Introduza um valor entre {{ minRows }} e {{ maxRows }}.",
"Custom row value": "Núm. de linhas personalizado",
"Apply": "Aplicar",
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/redux/drawerModeSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface DrawerModeState {
isDetailDrawerEnabled: boolean;
isDetailDrawerOpen: boolean;
}

const initialState: DrawerModeState = {
isDetailDrawerEnabled: false,
isDetailDrawerOpen: false,
};

const drawerModeSlice = createSlice({
name: 'drawerMode',
initialState,
reducers: {
setDetailDrawerEnabled: (state, action: PayloadAction<boolean>) => {
state.isDetailDrawerEnabled = action.payload;
localStorage.setItem('detailDrawerEnabled', `${action.payload}`);
},
setDetailDrawerOpen: (state, action: PayloadAction<boolean>) => {
state.isDetailDrawerOpen = action.payload;
localStorage.setItem('detailDrawerOpen', `${action.payload}`);
},
},
});

export const { setDetailDrawerEnabled, setDetailDrawerOpen } = drawerModeSlice.actions;
export default drawerModeSlice.reducer;
2 changes: 2 additions & 0 deletions frontend/src/redux/reducers/reducers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import pluginsReducer from '../../plugin/pluginsSlice';
import actionButtons from '../actionButtonsSlice';
import clusterAction from '../clusterActionSlice';
import configReducer from '../configSlice';
import drawerModeSlice from '../drawerModeSlice';
import filterReducer from '../filterSlice';
import routesReducer from '../routesSlice';
import resourceTableReducer from './../../components/common/Resource/resourceTableSlice';
Expand All @@ -26,6 +27,7 @@ const reducers = combineReducers({
detailsViewSection: detailsViewSectionReducer,
routes: routesReducer,
sidebar: sidebarReducer,
drawerMode: drawerModeSlice,
});

export type RootState = ReturnType<typeof reducers>;
Expand Down

0 comments on commit 5e443f0

Please sign in to comment.