Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new-log-viewer: Add tabbed Sidebar with resizable panel; Rearrange open and settings buttons. #74

Merged
merged 89 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
96de362
Remove redundant div wrapper in Layout component to simplify the DOM …
junhaoliao Sep 16, 2024
c6ab307
Add SidebarContainer with resizable tabs.
junhaoliao Sep 17, 2024
a0a618a
Add newline to EOF.
junhaoliao Sep 17, 2024
3c35843
Add newline to EOF.
junhaoliao Sep 17, 2024
b0948b6
Add borders to StatusBar and MenuBar
junhaoliao Sep 17, 2024
2666f95
Set resize handle z-index with global CSS variable.
junhaoliao Sep 17, 2024
3605209
Introduce 8px padding to .menu-bar for better spacing. Add .menu-bar-…
junhaoliao Sep 17, 2024
db82737
Add newline to EOF.
junhaoliao Sep 17, 2024
b9ebe1d
Extract <CustomTabPanel/>.
junhaoliao Sep 17, 2024
3ac708c
Remove redundant line.
junhaoliao Sep 17, 2024
1474245
Rename 'File Info' field to 'Name' in FileInfoTab.
junhaoliao Sep 18, 2024
ef55b61
Replace FileOpenIcon with FolderOpenIcon in PanelTabs.
junhaoliao Sep 18, 2024
0418f1f
Move open file functionality to MenuBar.
junhaoliao Sep 18, 2024
f87fc9f
Set default messages for no file open.
junhaoliao Sep 18, 2024
1707ccf
Refactor tab panel close behaviour.
junhaoliao Sep 18, 2024
1ed3de9
Add TAB_DISPLAY_NAMES and use it for tab titles.
junhaoliao Sep 18, 2024
25af90b
Refactor panel resize behaviour.
junhaoliao Sep 18, 2024
6efc0e4
Merge remote-tracking branch 'yscope/main' into sidebar
junhaoliao Sep 18, 2024
85d112d
Increase the min-width before the sidebar snaps closed.
junhaoliao Sep 18, 2024
c032ce4
Decrease the padding in the sidebar by 25%.
junhaoliao Sep 18, 2024
7b00600
Make the buttons square rather than rectangles.
junhaoliao Sep 18, 2024
5f43d9a
Add YScope logo component and ABeeZee font.
junhaoliao Sep 18, 2024
9bbfc0b
Add YScopeLogo and replace IconButton with Button.
junhaoliao Sep 18, 2024
54bb3c8
Update sidebar tab button dimensions.
junhaoliao Sep 18, 2024
ea6b38e
Adjust default Sidebar panel width to 360px.
junhaoliao Sep 18, 2024
98b55f5
Reformat CSS file.
junhaoliao Sep 18, 2024
128ab5f
Remove redundant line in StateContextProvider.tsx
junhaoliao Sep 18, 2024
8a3e9b6
Disable custom-property-pattern check for joyui custom properties in …
junhaoliao Sep 18, 2024
f535eeb
Rename 'File Info' tab display name to 'File info'.
junhaoliao Sep 18, 2024
bd3c94c
Remove YScopeLogo component and update icon styles.
junhaoliao Sep 18, 2024
fd1431f
Move active tab button indicator placement to the left.
junhaoliao Sep 18, 2024
8e1e54e
Change default fileName back to an empty string.
junhaoliao Sep 18, 2024
d5c9fa4
Show no-file-open message in FileInfoTab.
junhaoliao Sep 18, 2024
f4baacd
Refactor tab buttons to use TooltipTab component which moves indicato…
junhaoliao Sep 18, 2024
4e046fe
Add arrow to "Open file" tooltip.
junhaoliao Sep 18, 2024
74328ca
Support clicking on an active tab button to close the tab.
junhaoliao Sep 18, 2024
0b1b33f
Remove unnecessary type assertion on tabName value.
junhaoliao Sep 18, 2024
832763d
Add set status bar z-index so that the border of it can be shown over…
junhaoliao Sep 18, 2024
203f4f2
Change fileName empty string check.
junhaoliao Sep 18, 2024
748a159
Add padding between sidebar tab panel title and content.
junhaoliao Sep 18, 2024
6784f3b
Add Divider component to TooltipTab.
junhaoliao Sep 18, 2024
f5d6a6f
Add outlined variant to TooltipTab component.
junhaoliao Sep 18, 2024
e0f1c93
Revert "Add Divider component to TooltipTab."
junhaoliao Sep 18, 2024
27cc339
Refactor CSS imports.
junhaoliao Sep 19, 2024
69d0aa3
Prevent text selection in panel titles.
junhaoliao Sep 19, 2024
c19ae6b
Clear original file size before loading.
junhaoliao Sep 19, 2024
dbe858c
Add word-break style to FileInfoTab content.
junhaoliao Sep 19, 2024
38a31b7
Merge branch 'main' into sidebar
junhaoliao Sep 24, 2024
3aa0e0a
Move CustomListItem.tsx to PanelTabs directory.
junhaoliao Sep 24, 2024
ed64bcf
Remove unused ABeeZee font link from index.html.
junhaoliao Sep 24, 2024
8c1d6dc
Fix typo in docs - apply sugguestions.
junhaoliao Sep 24, 2024
f1e1d58
Moved custom tab panel title styles from inline CSS to the stylesheet.
junhaoliao Sep 24, 2024
db8a443
Remove useEffect for updating panel width state and externalized widt…
junhaoliao Sep 24, 2024
80b203a
Remove unnecessary fragment in ResizeHandle component.
junhaoliao Sep 24, 2024
6e27725
Update variable names and docs for the resize handle behaviours.
junhaoliao Sep 24, 2024
68adc0c
Update the `deactivateTabAndHideResizeHandle` function to use the `us…
junhaoliao Sep 24, 2024
e9ff7a9
Update dependencies for useCallback hooks in SidebarContainer.
junhaoliao Sep 24, 2024
9dfdef3
Suppress 'max-statements' ESLint rule for StateContextProvider.
junhaoliao Sep 24, 2024
f53a2e2
Rename SidebarContainer to CentralContainer.
junhaoliao Sep 27, 2024
d1c40de
Refactor CentralContainer and extract Sidebar component.
junhaoliao Sep 27, 2024
81bc4ae
Reorganize Sidebar component files.
junhaoliao Sep 27, 2024
591a55b
Rename FileInfoTab to FileInfoTabPanel.
junhaoliao Sep 27, 2024
1fbe903
Rename PanelTabs to SidebarTabs.
junhaoliao Sep 27, 2024
c3165a1
Add docs for Sidebar.
junhaoliao Sep 27, 2024
561d7ed
Refactor SidebarTabs to use a constant for tab info.
junhaoliao Sep 27, 2024
20efbb5
Add docs to explain why "sidebar-tab-list-spacing" is needed.
junhaoliao Sep 27, 2024
2204868
Split the useEffect hook in ResizeHandle into two.
junhaoliao Sep 28, 2024
7abfdf9
Avoid unnecessary dynamic change of the --ylv-panel-resize-handle-wid…
junhaoliao Sep 28, 2024
030036e
Change the resize handle width when not hovered.
junhaoliao Sep 29, 2024
03e3de1
Add visual feedback on Sidebar resize handle mouse down.
junhaoliao Sep 29, 2024
6f4613e
Increase panel resize handle width.
junhaoliao Sep 29, 2024
7146619
Rename `TooltipTab` to `TabButton`.
junhaoliao Sep 29, 2024
9e078b4
Merge branch 'main' into sidebar
junhaoliao Oct 2, 2024
f7c38d7
Introduce a constant for file unloaded check in FileInfoTabPanel.
junhaoliao Oct 3, 2024
caf32a3
Move DropFileContainer and Editor into CentralContainer directly.
junhaoliao Oct 3, 2024
b3d3e03
Simplify CentralContainer component documentation - apply code review…
junhaoliao Oct 3, 2024
7e1000d
Cache formattedOriginalSize with `useMemo`.
junhaoliao Oct 3, 2024
d36a73b
Reorder params in docs - Apply suggestions from code review
junhaoliao Oct 5, 2024
cae668b
Remove redundant container "central-container-children" and CSS for C…
junhaoliao Oct 10, 2024
374ac14
Merge remote-tracking branch 'junhao/sidebar' into sidebar
junhaoliao Oct 10, 2024
1fa0953
Merge branch 'main' into sidebar
junhaoliao Oct 10, 2024
530b352
Increase eslint rule "max-lines" limit to 500.
junhaoliao Oct 10, 2024
02a9eb0
Avoid leaving mouseup event listener active even when the resize hand…
junhaoliao Oct 10, 2024
703cea2
Merge branch 'main' into HEAD
davemarco Oct 11, 2024
6ad338e
Apply suggestions from code review
davemarco Oct 11, 2024
22f97aa
rename onDiskFileSize
davemarco Oct 11, 2024
0b66e00
fix pixels
davemarco Oct 11, 2024
efe3a3d
fix lint
davemarco Oct 11, 2024
9d9901e
fix original in more places
davemarco Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions new-log-viewer/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.resize-handle {
cursor: ew-resize;

z-index: var(--ylv-resize-handle-z-index);

box-sizing: border-box;
width: var(--ylv-panel-resize-handle-width);
height: 100%;

/* stylelint-disable-next-line custom-property-pattern */
background-color: var(--joy-palette-background-surface, #fbfcfe);
/* stylelint-disable-next-line custom-property-pattern */
border-right: 1px solid var(--joy-palette-neutral-outlinedBorder, #cdd7e1);
}

.resize-handle-holding,
.resize-handle:hover {
box-sizing: initial;

/* stylelint-disable-next-line custom-property-pattern */
background-color: var(--joy-palette-primary-solidHoverBg, #0258a8);
border-right: initial;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, {
useCallback,
useEffect,
useState,
} from "react";

import "./ResizeHandle.css";


interface ResizeHandleProps {
onHandleRelease: () => void,

/**
* Gets triggered when a resize event occurs.
*
* @param resizeHandlePosition The horizontal distance, in pixels, between the mouse pointer
* and the left edge of the viewport.
*/
onResize: (resizeHandlePosition: number) => void,
}

/**
* A vertical handle for resizing an object.
*
* @param props
* @param props.onResize The method to call when a resize occurs.
* @param props.onHandleRelease
* @return
*/
const ResizeHandle = ({
onResize,
onHandleRelease,
}: ResizeHandleProps) => {
const [isMouseDown, setIsMouseDown] = useState<boolean>(false);

const handleMouseDown = (ev: React.MouseEvent) => {
ev.preventDefault();
setIsMouseDown(true);
};

const handleMouseMove = useCallback((ev: MouseEvent) => {
ev.preventDefault();
onResize(ev.clientX);
}, [onResize]);

const handleMouseUp = useCallback((ev: MouseEvent) => {
ev.preventDefault();
setIsMouseDown(false);
onHandleRelease();
}, [onHandleRelease]);

// On `isMouseDown` change, add / remove event listeners.
useEffect(() => {
if (isMouseDown) {
window.addEventListener("mousemove", handleMouseMove);
window.addEventListener("mouseup", handleMouseUp);
}

return () => {
// Always clean up the event listeners before the hook is re-run due to `isMouseDown`
// changes / when the component is unmounted.
window.removeEventListener("mousemove", handleMouseMove);
window.removeEventListener("mouseup", handleMouseUp);
};
}, [
handleMouseMove,
handleMouseUp,
isMouseDown,
]);

return (
<div
className={`resize-handle ${isMouseDown ?
"resize-handle-holding" :
""}`}
onMouseDown={handleMouseDown}/>
);
};


export default ResizeHandle;
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";

import {
ListItem,
ListItemContent,
ListItemDecorator,
Typography,
TypographyProps,
} from "@mui/joy";


interface CustomListItemProps {
content: string,
icon: React.ReactNode,
slotProps?: {
content?: TypographyProps
},
title: string
}

/**
* Renders a custom list item with an icon, a title and a context text.
*
* @param props
* @param props.content
* @param props.icon
* @param props.slotProps
* @param props.title
* @return
*/
const CustomListItem = ({content, icon, slotProps, title}: CustomListItemProps) => (
davemarco marked this conversation as resolved.
Show resolved Hide resolved
<ListItem>
<ListItemDecorator>
{icon}
</ListItemDecorator>
<ListItemContent>
<Typography level={"title-sm"}>
{title}
</Typography>
<Typography
{...slotProps?.content}
level={"body-sm"}
>
{content}
</Typography>
</ListItemContent>
</ListItem>
);

export default CustomListItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.sidebar-tab-panel {
padding: 0.75rem;
}

.sidebar-tab-panel-title-container {
user-select: none;
margin-bottom: 0.5rem !important;
}

.sidebar-tab-panel-title {
font-size: 0.875rem !important;
font-weight: 400 !important;
text-transform: uppercase;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";

import {
DialogContent,
DialogTitle,
TabPanel,
Typography,
} from "@mui/joy";

import "./CustomTabPanel.css";


interface CustomTabPanelProps {
children: React.ReactNode,
tabName: string,
title: string,
}

/**
* Renders a customized tab panel to be extended for displaying extra information in the sidebar.
*
* @param props
* @param props.children
* @param props.tabName
* @param props.title
* @return
*/
const CustomTabPanel = ({children, tabName, title}: CustomTabPanelProps) => {
return (
<TabPanel
className={"sidebar-tab-panel"}
value={tabName}
>
<DialogTitle className={"sidebar-tab-panel-title-container"}>
<Typography
className={"sidebar-tab-panel-title"}
level={"body-md"}
>
{title}
</Typography>
</DialogTitle>
<DialogContent>
{children}
</DialogContent>
</TabPanel>
);
};


export default CustomTabPanel;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
useContext,
useMemo,
} from "react";

import {
Divider,
List,
} from "@mui/joy";

import AbcIcon from "@mui/icons-material/Abc";
import StorageIcon from "@mui/icons-material/Storage";

import {StateContext} from "../../../../contexts/StateContextProvider";
import {
TAB_DISPLAY_NAMES,
TAB_NAME,
} from "../../../../typings/tab";
import {formatSizeInBytes} from "../../../../utils/units";
import CustomListItem from "./CustomListItem";
import CustomTabPanel from "./CustomTabPanel";


/**
* Displays a panel containing the file name and on-disk size of the selected file.
*
* @return
*/
const FileInfoTabPanel = () => {
const {fileName, onDiskFileSizeInBytes} = useContext(StateContext);

const isFileUnloaded = 0 === fileName.length;
const formattedOnDiskSize = useMemo(
() => formatSizeInBytes(onDiskFileSizeInBytes, false),
[onDiskFileSizeInBytes]
);

return (
<CustomTabPanel
tabName={TAB_NAME.FILE_INFO}
title={TAB_DISPLAY_NAMES[TAB_NAME.FILE_INFO]}
>
{isFileUnloaded ?
"No file is open." :
<List>
<CustomListItem
content={fileName}
icon={<AbcIcon/>}
slotProps={{content: {sx: {wordBreak: "break-word"}}}}
title={"Name"}/>
<Divider/>
<CustomListItem
content={formattedOnDiskSize}
icon={<StorageIcon/>}
title={"On-disk Size"}/>
</List>}
</CustomTabPanel>
);
};

export default FileInfoTabPanel;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.sidebar-tab-button {
justify-content: center !important;
width: 48px;
height: 48px;
padding: 0 !important;
}

.sidebar-tab-button-icon {
font-size: 32px !important;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
Tab,
Tooltip,
} from "@mui/joy";

import {SvgIconComponent} from "@mui/icons-material";

import {
TAB_DISPLAY_NAMES,
TAB_NAME,
} from "../../../../typings/tab";

import "./TabButton.css";


interface TabButtonProps {
tabName: TAB_NAME,
Icon: SvgIconComponent,
onTabButtonClick: (tabName: TAB_NAME) => void
}

/**
* Renders a tooltip-wrapped tab button.
*
* @param props
* @param props.tabName
* @param props.Icon
* @param props.onTabButtonClick
* @return
*/
const TabButton = ({tabName, Icon, onTabButtonClick}: TabButtonProps) => {
const handleClick = () => {
onTabButtonClick(tabName);
};
davemarco marked this conversation as resolved.
Show resolved Hide resolved

return (
<Tooltip
arrow={true}
key={tabName}
placement={"right"}
title={TAB_DISPLAY_NAMES[tabName]}
variant={"outlined"}
>
<Tab
className={"sidebar-tab-button"}
color={"neutral"}
indicatorPlacement={"left"}
slotProps={{root: {onClick: handleClick}}}
value={tabName}
>
<Icon className={"sidebar-tab-button-icon"}/>
</Tab>
</Tooltip>
);
};

export default TabButton;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.sidebar-tabs {
flex-grow: 1;
width: calc(100% - var(--ylv-panel-resize-handle-width));
height: 100%;
}

.sidebar-tab-list-spacing {
flex-grow: 1;
}
Loading
Loading