Skip to content

Commit

Permalink
feat(panel): Resizable side panel
Browse files Browse the repository at this point in the history
Resolves: flyteorg/flyte#5102
Signed-off-by: Chi-Sheng Liu <[email protected]>
  • Loading branch information
MortalHappiness committed Mar 25, 2024
1 parent eb7fe2b commit bf1bfc1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 31 additions & 3 deletions packages/oss-console/src/components/common/DetailsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ import Paper from '@mui/material/Paper';
import { useTheme } from '@mui/material/styles';
import styled from '@mui/system/styled';
import { detailsPanelId } from '@clients/common/constants';
import { detailsPanelWidth } from './constants';
import classnames from 'classnames';
import { defaultDetailsPanelWidth } from './constants';

const StyledPaper = styled(Paper)(({ theme }) => ({
display: 'flex',
flex: '1 1 100%',
maxHeight: '100%',
paddingBottom: theme.spacing(2),
pointerEvents: 'initial',
width: detailsPanelWidth,
'& .dragger': {
width: '3px',
cursor: 'ew-resize',
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
zIndex: 100,
},
}));

interface DetailsPanelProps {
Expand All @@ -29,6 +38,24 @@ export const DetailsPanel: React.FC<PropsWithChildren<DetailsPanelProps>> = ({
open = false,
}) => {
const theme = useTheme();

const [panelWidth, setPanelWidth] = React.useState(defaultDetailsPanelWidth);

const handleMouseDown = (e: React.MouseEvent) => {
document.addEventListener('mouseup', handleMouseUp, true);
document.addEventListener('mousemove', handleMouseMove, true);

Check warning on line 46 in packages/oss-console/src/components/common/DetailsPanel.tsx

View check run for this annotation

Codecov / codecov/patch

packages/oss-console/src/components/common/DetailsPanel.tsx#L45-L46

Added lines #L45 - L46 were not covered by tests
};

const handleMouseUp = (e: React.MouseEvent) => {
document.removeEventListener('mouseup', handleMouseUp, true);
document.removeEventListener('mousemove', handleMouseMove, true);

Check warning on line 51 in packages/oss-console/src/components/common/DetailsPanel.tsx

View check run for this annotation

Codecov / codecov/patch

packages/oss-console/src/components/common/DetailsPanel.tsx#L50-L51

Added lines #L50 - L51 were not covered by tests
};

const handleMouseMove = React.useCallback((e: React.MouseEvent) => {
const newWidth = document.body.offsetWidth - e.clientX;
setPanelWidth(newWidth);

Check warning on line 56 in packages/oss-console/src/components/common/DetailsPanel.tsx

View check run for this annotation

Codecov / codecov/patch

packages/oss-console/src/components/common/DetailsPanel.tsx#L55-L56

Added lines #L55 - L56 were not covered by tests
}, []);

return (
<Drawer
anchor="right"
Expand All @@ -50,7 +77,8 @@ export const DetailsPanel: React.FC<PropsWithChildren<DetailsPanelProps>> = ({
open={open}
key="detailsPanel"
>
<StyledPaper id={detailsPanelId} square>
<StyledPaper id={detailsPanelId} square sx={{ width: panelWidth }}>
<div onMouseDown={(e) => handleMouseDown(e)} className={classnames('dragger')} />

Check warning on line 81 in packages/oss-console/src/components/common/DetailsPanel.tsx

View check run for this annotation

Codecov / codecov/patch

packages/oss-console/src/components/common/DetailsPanel.tsx#L81

Added line #L81 was not covered by tests
{children}
</StyledPaper>
</Drawer>
Expand Down
2 changes: 1 addition & 1 deletion packages/oss-console/src/components/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { env } from '@clients/common/environment';
import { InterpreterOptions } from 'xstate';

export const detailsPanelWidth = 432;
export const defaultDetailsPanelWidth = 432;

export const labels = {
moreOptionsButton: 'Display more options',
Expand Down

0 comments on commit bf1bfc1

Please sign in to comment.