Skip to content

Commit 82e34a5

Browse files
authored
Replaced MenuDropdown components with mds variables (#3113)
- Replaced menu dropdown in Files Button - Input Unit Menu dropdown replacement - Migrated Download Widget dropdown Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 7b83f4b commit 82e34a5

File tree

8 files changed

+97
-145
lines changed

8 files changed

+97
-145
lines changed

portal-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"local-storage-fallback": "^4.1.1",
1818
"lodash": "^4.17.21",
1919
"luxon": "^3.4.3",
20-
"mds": "https://github.com/minio/mds.git#v0.10.1",
20+
"mds": "https://github.com/minio/mds.git#v0.11.0",
2121
"react": "^18.1.0",
2222
"react-component-export-image": "^1.0.6",
2323
"react-copy-to-clipboard": "^5.0.2",

portal-ui/src/screens/Console/Buckets/ListBuckets/UploadFilesButton.tsx

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { Fragment, useState } from "react";
18-
import { Theme } from "@mui/material/styles";
1918
import { CSSObject } from "styled-components";
20-
import { Menu, MenuItem } from "@mui/material";
21-
import createStyles from "@mui/styles/createStyles";
22-
import withStyles from "@mui/styles/withStyles";
23-
import ListItemText from "@mui/material/ListItemText";
24-
import ListItemIcon from "@mui/material/ListItemIcon";
25-
import { Button, UploadFolderIcon, UploadIcon } from "mds";
19+
import { Button, DropdownSelector, UploadFolderIcon, UploadIcon } from "mds";
2620
import {
2721
IAM_SCOPES,
2822
permissionTooltipHelper,
@@ -39,30 +33,20 @@ interface IUploadFilesButton {
3933
forceDisable?: boolean;
4034
uploadFileFunction: (closeFunction: () => void) => void;
4135
uploadFolderFunction: (closeFunction: () => void) => void;
42-
classes: any;
4336
overrideStyles?: CSSObject;
4437
}
4538

46-
const styles = (theme: Theme) =>
47-
createStyles({
48-
listUploadIcons: {
49-
height: 20,
50-
"& .min-icon": {
51-
width: 18,
52-
fill: "rgba(0,0,0,0.87)",
53-
},
54-
},
55-
});
56-
5739
const UploadFilesButton = ({
5840
uploadPath,
5941
bucketName,
6042
forceDisable = false,
6143
uploadFileFunction,
6244
uploadFolderFunction,
63-
classes,
6445
overrideStyles = {},
6546
}: IUploadFilesButton) => {
47+
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
48+
const [uploadOptionsOpen, uploadOptionsSetOpen] = useState<boolean>(false);
49+
6650
const anonymousMode = useSelector(
6751
(state: AppState) => state.system.anonymousMode,
6852
);
@@ -82,9 +66,9 @@ const UploadFilesButton = ({
8266
putObjectPermScopes,
8367
);
8468

85-
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
8669
const openUploadMenu = Boolean(anchorEl);
8770
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
71+
uploadOptionsSetOpen(!uploadOptionsOpen);
8872
setAnchorEl(event.currentTarget);
8973
};
9074
const handleCloseUpload = () => {
@@ -104,6 +88,15 @@ const UploadFilesButton = ({
10488
true,
10589
);
10690

91+
const uploadFolderAction = (action: string) => {
92+
if (action === "folder") {
93+
uploadFolderFunction(handleCloseUpload);
94+
return;
95+
}
96+
97+
uploadFileFunction(handleCloseUpload);
98+
};
99+
107100
const uploadEnabled: boolean = uploadObjectAllowed || uploadFolderAllowed;
108101

109102
return (
@@ -131,48 +124,34 @@ const UploadFilesButton = ({
131124
sx={overrideStyles}
132125
/>
133126
</TooltipWrapper>
134-
<Menu
135-
id={`upload-main-menu`}
136-
aria-labelledby={`upload-main`}
137-
anchorEl={anchorEl}
138-
open={openUploadMenu}
139-
onClose={() => {
140-
handleCloseUpload();
141-
}}
142-
anchorOrigin={{
143-
vertical: "bottom",
144-
horizontal: "center",
127+
<DropdownSelector
128+
id={"upload-main-menu"}
129+
options={[
130+
{
131+
label: "Upload File",
132+
icon: <UploadIcon />,
133+
value: "file",
134+
disabled: !uploadObjectAllowed || forceDisable,
135+
},
136+
{
137+
label: "Upload Folder",
138+
icon: <UploadFolderIcon />,
139+
value: "folder",
140+
disabled: !uploadFolderAllowed || forceDisable,
141+
},
142+
]}
143+
selectedOption={""}
144+
onSelect={(nValue) => uploadFolderAction(nValue)}
145+
hideTriggerAction={() => {
146+
uploadOptionsSetOpen(false);
145147
}}
146-
transformOrigin={{
147-
vertical: "top",
148-
horizontal: "center",
149-
}}
150-
>
151-
<MenuItem
152-
onClick={() => {
153-
uploadFileFunction(handleCloseUpload);
154-
}}
155-
disabled={!uploadObjectAllowed || forceDisable}
156-
>
157-
<ListItemIcon className={classes.listUploadIcons}>
158-
<UploadIcon />
159-
</ListItemIcon>
160-
<ListItemText>Upload File</ListItemText>
161-
</MenuItem>
162-
<MenuItem
163-
onClick={() => {
164-
uploadFolderFunction(handleCloseUpload);
165-
}}
166-
disabled={!uploadFolderAllowed || forceDisable}
167-
>
168-
<ListItemIcon className={classes.listUploadIcons}>
169-
<UploadFolderIcon />
170-
</ListItemIcon>
171-
<ListItemText>Upload Folder</ListItemText>
172-
</MenuItem>
173-
</Menu>
148+
open={uploadOptionsOpen}
149+
anchorEl={anchorEl}
150+
anchorOrigin={"end"}
151+
useAnchorWidth={false}
152+
/>
174153
</Fragment>
175154
);
176155
};
177156

178-
export default withStyles(styles)(UploadFilesButton);
157+
export default UploadFilesButton;

portal-ui/src/screens/Console/Common/FormComponents/InputUnitMenu/InputUnitMenu.tsx

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,27 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { Fragment } from "react";
18-
import { Theme } from "@mui/material/styles";
19-
import createStyles from "@mui/styles/createStyles";
20-
import withStyles from "@mui/styles/withStyles";
21-
import { SelectorType } from "mds";
22-
import { Menu, MenuItem } from "@mui/material";
18+
import { DropdownSelector, SelectorType } from "mds";
19+
import styled from "styled-components";
20+
import get from "lodash/get";
2321

2422
interface IInputUnitBox {
25-
classes: any;
2623
id: string;
2724
unitSelected: string;
2825
unitsList: SelectorType[];
2926
disabled?: boolean;
3027
onUnitChange?: (newValue: string) => void;
3128
}
3229

33-
const styles = (theme: Theme) =>
34-
createStyles({
35-
buttonTrigger: {
36-
border: "#F0F2F2 1px solid",
37-
borderRadius: 3,
38-
color: "#838383",
39-
backgroundColor: "#fff",
40-
fontSize: 12,
41-
},
42-
});
30+
const UnitMenuButton = styled.button(({ theme }) => ({
31+
border: `1px solid ${get(theme, "borderColor", "#E2E2E2")}`,
32+
borderRadius: 3,
33+
color: get(theme, "secondaryText", "#5B5C5C"),
34+
backgroundColor: get(theme, "boxBackground", "#FBFAFA"),
35+
fontSize: 12,
36+
}));
4337

4438
const InputUnitMenu = ({
45-
classes,
4639
id,
4740
unitSelected,
4841
unitsList,
@@ -63,46 +56,31 @@ const InputUnitMenu = ({
6356

6457
return (
6558
<Fragment>
66-
<button
59+
<UnitMenuButton
6760
id={`${id}-button`}
6861
aria-controls={`${id}-menu`}
6962
aria-haspopup="true"
7063
aria-expanded={open ? "true" : undefined}
7164
onClick={handleClick}
72-
className={classes.buttonTrigger}
7365
disabled={disabled}
7466
type={"button"}
7567
>
7668
{unitSelected}
77-
</button>
78-
<Menu
79-
id={`${id}-menu`}
80-
aria-labelledby={`${id}-button`}
81-
anchorEl={anchorEl}
82-
open={open}
83-
onClose={() => {
69+
</UnitMenuButton>
70+
<DropdownSelector
71+
id={"upload-main-menu"}
72+
options={unitsList}
73+
selectedOption={""}
74+
onSelect={(value) => handleClose(value)}
75+
hideTriggerAction={() => {
8476
handleClose("");
8577
}}
86-
anchorOrigin={{
87-
vertical: "bottom",
88-
horizontal: "center",
89-
}}
90-
transformOrigin={{
91-
vertical: "top",
92-
horizontal: "center",
93-
}}
94-
>
95-
{unitsList.map((unit) => (
96-
<MenuItem
97-
onClick={() => handleClose(unit.value)}
98-
key={`itemUnit-${unit.value}-${unit.label}`}
99-
>
100-
{unit.label}
101-
</MenuItem>
102-
))}
103-
</Menu>
78+
open={open}
79+
anchorEl={anchorEl}
80+
anchorOrigin={"end"}
81+
/>
10482
</Fragment>
10583
);
10684
};
10785

108-
export default withStyles(styles)(InputUnitMenu);
86+
export default InputUnitMenu;

portal-ui/src/screens/Console/Dashboard/DownloadWidgetDataButton.tsx

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { Fragment } from "react";
18-
import { Box, Menu, MenuItem } from "@mui/material";
19-
import ListItemText from "@mui/material/ListItemText";
20-
import { DownloadIcon } from "mds";
18+
import { Box, DownloadIcon, DropdownSelector } from "mds";
2119
import { exportComponentAsPNG } from "react-component-export-image";
2220
import { ErrorResponseHandler } from "../../../common/types";
2321
import { useAppDispatch } from "../../../../src/store";
@@ -104,11 +102,19 @@ const DownloadWidgetDataButton = ({
104102
}
105103
};
106104

105+
const handleSelectedOption = (selectOption: string) => {
106+
if (selectOption === "csv") {
107+
downloadAsCSV();
108+
} else if (selectOption === "png") {
109+
downloadAsPNG();
110+
}
111+
};
112+
107113
return (
108114
<Fragment>
109115
<Box
110-
justifyItems={"center"}
111116
sx={{
117+
justifyItems: "center",
112118
"& .download-icon": {
113119
backgroundColor: "transparent",
114120
border: 0,
@@ -126,33 +132,24 @@ const DownloadWidgetDataButton = ({
126132
},
127133
}}
128134
>
129-
<button onClick={handleClick} className={"download-icon"}>
135+
<button className={"download-icon"} onClick={handleClick}>
130136
<DownloadIcon />
131137
</button>
132-
<Menu
133-
id={`download-widget-main-menu`}
134-
aria-labelledby={`download-widget-main`}
135-
anchorEl={anchorEl}
136-
open={openDownloadMenu}
137-
onClose={() => {
138+
<DropdownSelector
139+
id={"download-widget-main-menu"}
140+
options={[
141+
{ label: "Download as CSV", value: "csv" },
142+
{ label: "Download as PNG", value: "png" },
143+
]}
144+
selectedOption={""}
145+
onSelect={(value) => handleSelectedOption(value)}
146+
hideTriggerAction={() => {
138147
handleCloseDownload();
139148
}}
140-
>
141-
<MenuItem
142-
onClick={() => {
143-
downloadAsCSV();
144-
}}
145-
>
146-
<ListItemText>Download as CSV</ListItemText>
147-
</MenuItem>
148-
<MenuItem
149-
onClick={() => {
150-
downloadAsPNG();
151-
}}
152-
>
153-
<ListItemText>Download as PNG</ListItemText>
154-
</MenuItem>
155-
</Menu>
149+
open={openDownloadMenu}
150+
anchorEl={anchorEl}
151+
anchorOrigin={"end"}
152+
/>
156153
</Box>
157154
</Fragment>
158155
);

portal-ui/src/screens/LoginPage/StrategyForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ const StrategyForm = ({ redirectRules }: { redirectRules: RedirectRule[] }) => {
152152
}}
153153
open={ssoOptionsOpen}
154154
anchorEl={anchorEl}
155+
useAnchorWidth={true}
155156
/>
156157
)}
157158
</Box>

portal-ui/src/utils/stylesUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const generateOverrideTheme = (overrideVars: IEmbeddedCustomStyles) => {
4242
loaderColor: overrideVars.loaderColor,
4343
boxBackground: overrideVars.boxBackground,
4444
mutedText: "#9c9c9c",
45+
secondaryText: "#9c9c9c",
4546
buttons: {
4647
regular: {
4748
enabled: {

portal-ui/tests/permissions-B/bucketWritePrefixOnly.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ test
3131
.useRole(roles.bucketWritePrefixOnly)
3232
.navigateTo("http://localhost:9090/browser/testcafe")
3333
.click(uploadButton)
34-
.expect(Selector("li").withText("Upload File").hasClass("Mui-disabled"))
34+
.expect(Selector("li").withText("Upload File").hasClass("disabled"))
3535
.ok()
36-
.expect(
37-
Selector("li").withText("Upload Folder").hasClass("Mui-disabled"),
38-
)
36+
.expect(Selector("li").withText("Upload Folder").hasClass("disabled"))
3937
.notOk();
4038
},
4139
)
@@ -50,11 +48,9 @@ test
5048
.useRole(roles.bucketWritePrefixOnly)
5149
.navigateTo("http://localhost:9090/browser/testcafe/d3JpdGU=")
5250
.click(uploadButton)
53-
.expect(Selector("li").withText("Upload File").hasClass("Mui-disabled"))
51+
.expect(Selector("li").withText("Upload File").hasClass("disabled"))
5452
.notOk()
55-
.expect(
56-
Selector("li").withText("Upload Folder").hasClass("Mui-disabled"),
57-
)
53+
.expect(Selector("li").withText("Upload Folder").hasClass("disabled"))
5854
.notOk();
5955
},
6056
)

0 commit comments

Comments
 (0)