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

WIP - new-log-viewer: Add <SearchTabPanel/> for submitting queries and viewing search results. #82

Closed
wants to merge 73 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
73 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
3faaf0d
Add <SearchTabPanel/>.
junhaoliao Sep 30, 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
Prev Previous commit
Next Next commit
Refactor CentralContainer and extract Sidebar component.
junhaoliao committed Sep 27, 2024

Verified

This commit was signed with the committer’s verified signature.
ArcticLampyrid ArcticLampyrid
commit d1c40ded8635cf26060c7817b0a670da40622004
3 changes: 3 additions & 0 deletions new-log-viewer/src/components/CentralContainer/Sidebar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.sidebar-tabs-container {
display: flex;
}
111 changes: 111 additions & 0 deletions new-log-viewer/src/components/CentralContainer/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {
useCallback,
useRef,
useState,
} from "react";

import {TAB_NAME} from "../../typings/tab";
import PanelTabs from "./PanelTabs";
import ResizeHandle from "./ResizeHandle";

import "./Sidebar.css";


const PANEL_DEFAULT_WIDTH_IN_PIXEL = 360;
const PANEL_CLIP_THRESHOLD_IN_PIXEL = 250;
const PANEL_MAX_WIDTH_TO_WINDOW_WIDTH_RATIO = 0.8;

/**
* Gets width of the panel from body style properties.
*
* @return the width in pixels as a number.
*/
const getPanelWidth = () => parseInt(
document.body.style.getPropertyValue("--ylv-panel-width"),
10
);

/**
* Sets width of the panel in body style properties.
*
* @param newValue in pixels.
*/
const setPanelWidth = (newValue: number) => {
document.body.style.setProperty("--ylv-panel-width", `${newValue}px`);
};


/**

Check warning on line 38 in new-log-viewer/src/components/CentralContainer/Sidebar.tsx

GitHub Actions / lint-check

Missing JSDoc block description

Check warning on line 38 in new-log-viewer/src/components/CentralContainer/Sidebar.tsx

GitHub Actions / lint-check

Missing JSDoc @return declaration
*

Check warning on line 39 in new-log-viewer/src/components/CentralContainer/Sidebar.tsx

GitHub Actions / lint-check

No empty blocks
*/
const Sidebar = () => {
const [activeTabName, setActiveTabName] = useState<TAB_NAME>(TAB_NAME.FILE_INFO);

const tabListRef = useRef<HTMLDivElement>(null);

const deactivateTabAndHideResizeHandle = useCallback(() => {
setActiveTabName(TAB_NAME.NONE);
document.body.style.setProperty("--ylv-panel-resize-handle-width", "0px");
}, []);

const handleActiveTabNameChange = useCallback((tabName: TAB_NAME) => {
if (null === tabListRef.current) {
console.error("Unexpected null tabListRef.current");

return;
}

if (activeTabName === tabName) {
deactivateTabAndHideResizeHandle();
setPanelWidth(tabListRef.current.clientWidth);

return;
}
setActiveTabName(tabName);
setPanelWidth(PANEL_DEFAULT_WIDTH_IN_PIXEL);
document.body.style.setProperty("--ylv-panel-resize-handle-width", "3px");
}, [
activeTabName,
deactivateTabAndHideResizeHandle,
]);

const handleResizeHandleRelease = useCallback(() => {
if (getPanelWidth() === tabListRef.current?.clientWidth) {
deactivateTabAndHideResizeHandle();
}
}, [deactivateTabAndHideResizeHandle]);

const handleResize = useCallback((resizeHandlePosition: number) => {
if (null === tabListRef.current) {
console.error("Unexpected null tabListRef.current");

return;
}
if (tabListRef.current.clientWidth + PANEL_CLIP_THRESHOLD_IN_PIXEL > resizeHandlePosition) {
// If the resize handle is positioned to the right of the <TabList/>'s right edge
// with a clipping threshold accounted, close the panel.
setPanelWidth(tabListRef.current.clientWidth);
} else if (
resizeHandlePosition < window.innerWidth * PANEL_MAX_WIDTH_TO_WINDOW_WIDTH_RATIO
) {
// If the resize handle is positioned to the left of 80% of the window's width,
// update the panel width with the distance between the mouse pointer and the
// window's left edge.
setPanelWidth(resizeHandlePosition);
}
}, []);

return (
<div className={"sidebar-tabs-container"}>
<PanelTabs
activeTabName={activeTabName}
ref={tabListRef}
onActiveTabNameChange={handleActiveTabNameChange}/>
<ResizeHandle
onHandleRelease={handleResizeHandleRelease}
onResize={handleResize}/>
</div>
);
};

export default Sidebar;
8 changes: 2 additions & 6 deletions new-log-viewer/src/components/CentralContainer/index.css
Original file line number Diff line number Diff line change
@@ -2,16 +2,12 @@
--ylv-panel-width: 360px;
}

.sidebar-container {
.central-container {
display: grid;
grid-template-columns: var(--ylv-panel-width) 1fr;
width: 100vw;
}

.sidebar-tabs-container {
display: flex;
}

.sidebar-children-container {
.central-container-children-container {
width: calc(100vw - var(--ylv-panel-width));
}
111 changes: 9 additions & 102 deletions new-log-viewer/src/components/CentralContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,123 +1,30 @@
import React, {
useCallback,
useRef,
useState,
} from "react";
import React from "react";

import {TAB_NAME} from "../../typings/tab";
import PanelTabs from "./PanelTabs";
import ResizeHandle from "./ResizeHandle";
import Sidebar from "./Sidebar";

import "./index.css";


const PANEL_DEFAULT_WIDTH_IN_PIXEL = 360;
const PANEL_CLIP_THRESHOLD_IN_PIXEL = 250;
const PANEL_MAX_WIDTH_TO_WINDOW_WIDTH_RATIO = 0.8;

interface SidebarContainerProps {
interface CentralContainerProps {
children: React.ReactNode,
}

/**
* Gets width of the panel from body style properties.
*
* @return the width in pixels as a number.
*/
const getPanelWidth = () => parseInt(
document.body.style.getPropertyValue("--ylv-panel-width"),
10
);

/**
* Sets width of the panel in body style properties.
*
* @param newValue in pixels.
*/
const setPanelWidth = (newValue: number) => {
document.body.style.setProperty("--ylv-panel-width", `${newValue}px`);
};

/**
* Wraps a children with a sidebar component on the left.
* Locates in the center of the <Layout/> and wraps a children with a sidebar component on its left.
*
* @param props
* @param props.children
* @return
*/
const SidebarContainer = ({children}: SidebarContainerProps) => {
const [activeTabName, setActiveTabName] = useState<TAB_NAME>(TAB_NAME.FILE_INFO);

const tabListRef = useRef<HTMLDivElement>(null);

const deactivateTabAndHideResizeHandle = useCallback(() => {
setActiveTabName(TAB_NAME.NONE);
document.body.style.setProperty("--ylv-panel-resize-handle-width", "0px");
}, []);

const handleActiveTabNameChange = useCallback((tabName: TAB_NAME) => {
if (null === tabListRef.current) {
console.error("Unexpected null tabListRef.current");

return;
}

if (activeTabName === tabName) {
deactivateTabAndHideResizeHandle();
setPanelWidth(tabListRef.current.clientWidth);

return;
}
setActiveTabName(tabName);
setPanelWidth(PANEL_DEFAULT_WIDTH_IN_PIXEL);
document.body.style.setProperty("--ylv-panel-resize-handle-width", "3px");
}, [
activeTabName,
deactivateTabAndHideResizeHandle,
]);

const handleResizeHandleRelease = useCallback(() => {
if (getPanelWidth() === tabListRef.current?.clientWidth) {
deactivateTabAndHideResizeHandle();
}
}, [deactivateTabAndHideResizeHandle]);

const handleResize = useCallback((resizeHandlePosition: number) => {
if (null === tabListRef.current) {
console.error("Unexpected null tabListRef.current");

return;
}
if (tabListRef.current.clientWidth + PANEL_CLIP_THRESHOLD_IN_PIXEL > resizeHandlePosition) {
// If the resize handle is positioned to the right of the <TabList/>'s right edge
// with a clipping threshold accounted, close the panel.
setPanelWidth(tabListRef.current.clientWidth);
} else if (
resizeHandlePosition < window.innerWidth * PANEL_MAX_WIDTH_TO_WINDOW_WIDTH_RATIO
) {
// If the resize handle is positioned to the left of 80% of the window's width,
// update the panel width with the distance between the mouse pointer and the
// window's left edge.
setPanelWidth(resizeHandlePosition);
}
}, []);

const CentralContainer = ({children}: CentralContainerProps) => {
return (
<div className={"sidebar-container"}>
<div className={"sidebar-tabs-container"}>
<PanelTabs
activeTabName={activeTabName}
ref={tabListRef}
onActiveTabNameChange={handleActiveTabNameChange}/>
<ResizeHandle
onHandleRelease={handleResizeHandleRelease}
onResize={handleResize}/>
</div>
<div className={"sidebar-children-container"}>
<div className={"central-container"}>
<Sidebar/>
<div className={"central-container-children-container"}>
{children}
</div>
</div>
);
};

export default SidebarContainer;
export default CentralContainer;