forked from y-scope/yscope-log-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileInfoTabPanel.tsx
61 lines (53 loc) · 1.67 KB
/
FileInfoTabPanel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;