Merge pull request #437 from bluewave-labs/feat/select-component

Select component
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-07-24 11:35:15 -07:00
commit be10a16a73
10 files changed
+232 -203

No files matched your search

@@ -0,0 +1,23 @@
.select-wrapper .select-component > .MuiSelect-select {
padding: 0 10px;
height: 34px !important;
display: flex !important;
align-items: center;
text-transform: capitalize;
line-height: 1;
}
.select-wrapper .MuiInputBase-root:has(> .MuiSelect-select) {
min-width: 150px;
}
.select-wrapper .MuiInputBase-root:has(> .MuiSelect-select),
.MuiMenu-List .MuiMenuItem-root,
.select-wrapper h3.MuiTypography-root {
font-size: var(--env-var-font-size-medium);
color: var(--env-var-color-5);
}
.MuiInputBase-root:has(> .MuiSelect-select) fieldset {
border-color: var(--env-var-color-29);
}
.MuiInputBase-root:not(.Mui-focused):has(> .MuiSelect-select):hover fieldset {
border-color: var(--env-var-color-29);
}
@@ -0,0 +1,132 @@
import PropTypes from "prop-types";
import { useTheme } from "@emotion/react";
import {
MenuItem,
Select as MuiSelect,
Stack,
Typography,
} from "@mui/material";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import "./index.css";
/**
* @component
* @param {object} props
* @param {string} props.id - The ID attribute for the select element.
* @param {string} props.placeholder - The label of the select element.
* @param {string} props.placeholder - The placeholder text when no option is selected.
* @param {boolean} props.isHidden - Whether the placeholder should be hidden.
* @param {string} props.value - The currently selected value.
* @param {object[]} props.items - The array of items to populate in the select dropdown.
* @param {(string | number)} props.items._id - The unique identifier of each item.
* @param {string} props.items.name - The display name of each item.
* @param {function} props.onChange - The function to handle onChange event.
* @param {object} props.sx - The custom styles object for MUI Select component.
* @returns {JSX.Element}
*
* @example
* const frequencies = [
* { _id: 1, name: "1 minute" },
* { _id: 2, name: "2 minutes" },
* { _id: 3, name: "3 minutes" },
* ];
*
* <Select
* id="frequency-id"
* label="Check frequency"
* placeholder="Select frequency"
* value={value}
* onChange={handleChange}
* items={frequencies}
* />
*/
const Select = ({
id,
label,
placeholder,
isHidden,
value,
items,
onChange,
sx,
}) => {
const theme = useTheme();
const itemStyles = {
fontSize: "var(--env-var-font-size-medium)",
color: theme.palette.otherColors.bluishGray,
textTransform: "capitalize",
borderRadius: `${theme.shape.borderRadius}px`,
margin: theme.gap.xs,
};
return (
<Stack gap={theme.gap.xs} className="select-wrapper">
{label && <Typography component="h3">{label}</Typography>}
<MuiSelect
className="select-component"
value={value}
onChange={onChange}
displayEmpty
inputProps={{ id: id }}
MenuProps={{
PaperProps: {
className: "select-dropdown",
style: {
marginTop: theme.gap.xs,
},
},
MenuListProps: {
style: { padding: 0 },
},
}}
IconComponent={KeyboardArrowDownIcon}
sx={{ ...sx }}
>
{placeholder && (
<MenuItem
className="select-placeholder"
value="0"
sx={{
display: isHidden ? "none" : "flex",
visibility: isHidden ? "none" : "visible",
...itemStyles,
}}
>
{placeholder}
</MenuItem>
)}
{items.map((item) => (
<MenuItem
value={item._id}
key={`${id}-${item._id}`}
sx={{
...itemStyles,
}}
>
{item.name}
</MenuItem>
))}
</MuiSelect>
</Stack>
);
};
Select.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.string,
placeholder: PropTypes.string,
isHidden: PropTypes.bool,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
items: PropTypes.arrayOf(
PropTypes.shape({
_id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
name: PropTypes.string.isRequired,
})
).isRequired,
onChange: PropTypes.func.isRequired,
sx: PropTypes.object,
};
export default Select;
@@ -5,9 +5,7 @@ import {
ButtonGroup, ButtonGroup,
Divider, Divider,
IconButton, IconButton,
MenuItem,
Modal, Modal,
Select,
Stack, Stack,
TextField, TextField,
Typography, Typography,
@@ -18,12 +16,12 @@ import { useEffect, useState } from "react";
import EditSvg from "../../../assets/icons/edit.svg?react"; import EditSvg from "../../../assets/icons/edit.svg?react";
import Field from "../../Inputs/Field"; import Field from "../../Inputs/Field";
import { credentials } from "../../../Validation/validation"; import { credentials } from "../../../Validation/validation";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import axiosInstance from "../../../Utils/axiosConfig"; import axiosInstance from "../../../Utils/axiosConfig";
import { createToast } from "../../../Utils/toastUtils"; import { createToast } from "../../../Utils/toastUtils";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import BasicTable from "../../BasicTable"; import BasicTable from "../../BasicTable";
import Remove from "../../../assets/icons/trash-bin.svg?react"; import Remove from "../../../assets/icons/trash-bin.svg?react";
import Select from "../../Inputs/Select";
/** /**
* TeamPanel component manages the organization and team members, * TeamPanel component manages the organization and team members,
@@ -44,7 +42,7 @@ const TeamPanel = () => {
}); });
const [toInvite, setToInvite] = useState({ const [toInvite, setToInvite] = useState({
email: "", email: "",
role: [""], role: ["0"],
}); });
const [tableData, setTableData] = useState({}); const [tableData, setTableData] = useState({});
const [members, setMembers] = useState([]); const [members, setMembers] = useState([]);
@@ -202,7 +200,7 @@ const TeamPanel = () => {
}; };
const closeInviteModal = () => { const closeInviteModal = () => {
setIsOpen(false); setIsOpen(false);
setToInvite({ email: "", role: [""] }); setToInvite({ email: "", role: ["0"] });
setErrors({}); setErrors({});
}; };
@@ -377,6 +375,8 @@ const TeamPanel = () => {
/> />
<Select <Select
id="team-member-role" id="team-member-role"
placeholder="Select role"
isHidden={true}
value={toInvite.role[0]} value={toInvite.role[0]}
onChange={(event) => onChange={(event) =>
setToInvite((prev) => ({ setToInvite((prev) => ({
@@ -384,46 +384,11 @@ const TeamPanel = () => {
role: [event.target.value], role: [event.target.value],
})) }))
} }
displayEmpty items={[
MenuProps={{ { _id: "admin", name: "admin" },
PaperProps: { { _id: "user", name: "user" },
style: { ]}
marginTop: theme.gap.xs, />
},
},
MenuListProps: {
style: { padding: 0 },
},
}}
IconComponent={KeyboardArrowDownIcon}
sx={{ mt: theme.gap.xs }}
>
<MenuItem disableRipple id="role-default" value="">
Select role
</MenuItem>
<MenuItem
disableRipple
value="admin"
sx={{
fontSize: "13px",
borderRadius: `${theme.shape.borderRadius}px`,
margin: theme.gap.xs,
}}
>
Admin
</MenuItem>
<MenuItem
disableRipple
value="user"
sx={{
fontSize: "13px",
borderRadius: `${theme.shape.borderRadius}px`,
margin: theme.gap.xs,
}}
>
User
</MenuItem>
</Select>
<Stack <Stack
direction="row" direction="row"
gap={theme.gap.small} gap={theme.gap.small}
-34
View File
@@ -67,23 +67,6 @@
align-items: center; align-items: center;
} }
#select-actions,
#select-role {
padding: 5px 0;
padding-left: 15px;
padding-right: 50px;
line-height: 1.75;
}
.MuiInputBase-root:has(#select-actions) fieldset,
.MuiInputBase-root:has(#select-role) fieldset {
border-color: #a1a7b1;
margin: -1px;
border-width: 1px;
}
.MuiInputBase-root:has(#select-actions):hover fieldset,
.MuiInputBase-root:has(#select-role):hover fieldset {
border-color: var(--env-var-color-2);
}
/* for testing, will remove later */ /* for testing, will remove later */
@media only screen and (max-width: 1600px) { @media only screen and (max-width: 1600px) {
@@ -111,23 +94,6 @@
margin: 0; margin: 0;
} }
#role-default {
display: none;
visibility: none;
}
.MuiInputBase-root:has(#team-member-role) {
height: 34px;
}
#team-member-role {
padding: 0 10px;
height: 100%;
display: flex;
align-items: center;
}
.MuiInputBase-root:not(.Mui-focused):has(#team-member-role):hover fieldset {
border-color: var(--env-var-color-29);
}
.edit-organization-form { .edit-organization-form {
display: flex; display: flex;
align-items: center; align-items: center;
+10 -18
View File
@@ -1,12 +1,6 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { import { Typography, ButtonGroup, Stack } from "@mui/material";
Select,
MenuItem,
Typography,
ButtonGroup,
Stack,
} from "@mui/material";
import Button from "../../Components/Button"; import Button from "../../Components/Button";
import axiosInstance from "../../Utils/axiosConfig"; import axiosInstance from "../../Utils/axiosConfig";
@@ -15,6 +9,7 @@ import { StatusLabel } from "../../Components/Label";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import "./index.css"; import "./index.css";
import Select from "../../Components/Inputs/Select";
const Incidents = () => { const Incidents = () => {
const theme = useTheme(); const theme = useTheme();
@@ -118,16 +113,13 @@ const Incidents = () => {
> >
<Stack direction="row" alignItems="center" gap={theme.gap.medium}> <Stack direction="row" alignItems="center" gap={theme.gap.medium}>
<Typography component="h1">Incident history for: </Typography> <Typography component="h1">Incident history for: </Typography>
<Select value={selectedMonitor} onChange={handleSelect}> <Select
<MenuItem value={"0"}>All servers</MenuItem> id="incidents-select-monitor"
{Object.values(monitors).map((monitor) => { placeholder="All servers"
return ( value={selectedMonitor}
<MenuItem key={monitor._id} value={monitor._id}> onChange={handleSelect}
{monitor.name} items={Object.values(monitors)}
</MenuItem> />
);
})}
</Select>
<ButtonGroup sx={{ ml: "auto" }}> <ButtonGroup sx={{ ml: "auto" }}>
<Button <Button
level="secondary" level="secondary"
@@ -158,7 +150,7 @@ const Incidents = () => {
/> />
</ButtonGroup> </ButtonGroup>
</Stack> </Stack>
<BasicTable data={data} paginated={true} rowsPerPage={12}/> <BasicTable data={data} paginated={true} rowsPerPage={12} />
</Stack> </Stack>
); );
}; };
@@ -69,4 +69,9 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: var(--env-var-spacing-4); gap: var(--env-var-spacing-4);
}
body:has(.configure-monitor) .select-dropdown .MuiMenuItem-root,
.configure-monitor .select-wrapper .select-component > .MuiSelect-select {
text-transform: lowercase;
} }
+16 -37
View File
@@ -5,15 +5,15 @@ import { useEffect, useState } from "react";
import Button from "../../../Components/Button"; import Button from "../../../Components/Button";
import Field from "../../../Components/Inputs/Field"; import Field from "../../../Components/Inputs/Field";
import RadioButton from "../../../Components/RadioButton"; import RadioButton from "../../../Components/RadioButton";
import { Box, MenuItem, Select, Stack, Typography } from "@mui/material"; import { Box, MenuItem, Stack, Typography } from "@mui/material";
import WestRoundedIcon from "@mui/icons-material/WestRounded"; import WestRoundedIcon from "@mui/icons-material/WestRounded";
import GreenCheck from "../../../assets/icons/checkbox-green.svg?react"; import GreenCheck from "../../../assets/icons/checkbox-green.svg?react";
import RedCheck from "../../../assets/icons/checkbox-red.svg?react"; import RedCheck from "../../../assets/icons/checkbox-red.svg?react";
import PauseCircleOutlineIcon from "@mui/icons-material/PauseCircleOutline"; import PauseCircleOutlineIcon from "@mui/icons-material/PauseCircleOutline";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import "./index.css"; import "./index.css";
import { monitorValidation } from "../../../Validation/validation"; import { monitorValidation } from "../../../Validation/validation";
import Select from "../../../Components/Inputs/Select";
const formatDurationRounded = (ms) => { const formatDurationRounded = (ms) => {
const seconds = Math.floor(ms / 1000); const seconds = Math.floor(ms / 1000);
@@ -119,7 +119,13 @@ const Configure = () => {
// TODO // TODO
}; };
const frequencies = [1, 2, 3, 4, 5]; const frequencies = [
{ _id: 1, name: "1 minute" },
{ _id: 2, name: "2 minutes" },
{ _id: 3, name: "3 minutes" },
{ _id: 4, name: "4 minutes" },
{ _id: 5, name: "5 minutes" },
];
return ( return (
<div <div
@@ -285,40 +291,13 @@ const Configure = () => {
<Typography component="h2">Advanced settings</Typography> <Typography component="h2">Advanced settings</Typography>
</Box> </Box>
<Stack gap={theme.gap.xl}> <Stack gap={theme.gap.xl}>
<Box> <Select
<Typography component="p" mb={theme.gap.small}> id="monitor-interval-configure"
Check frequency label="Check frequency"
</Typography> value={monitor?.interval || 1}
<Select onChange={(event) => handleChange(event, "interval")}
id="monitor-interval" items={frequencies}
value={monitor?.interval || 1} />
inputProps={{ id: "monitor-interval-select" }}
MenuProps={{
PaperProps: {
style: {
marginTop: "10px",
},
},
}}
IconComponent={KeyboardArrowDownIcon}
onChange={(event) => handleChange(event, "interval")}
>
{frequencies.map((freq) => (
<MenuItem
key={`port-${freq}`}
value={freq}
disableRipple
sx={{
fontSize: "13px",
borderRadius: `${theme.shape.borderRadius}px`,
margin: theme.gap.xs,
}}
>
{freq} {freq === 1 ? "minute" : "minutes"}
</MenuItem>
))}
</Select>
</Box>
</Stack> </Stack>
</Stack> </Stack>
<Stack direction="row" justifyContent="flex-end"> <Stack direction="row" justifyContent="flex-end">
@@ -10,14 +10,12 @@
font-size: var(--env-var-font-size-large); font-size: var(--env-var-font-size-large);
} }
.create-monitor p.MuiTypography-root, .create-monitor p.MuiTypography-root,
.create-monitor button.MuiButtonBase-root, .create-monitor button.MuiButtonBase-root {
#monitor-frequencies {
font-size: var(--env-var-font-size-medium); font-size: var(--env-var-font-size-medium);
} }
.create-monitor h2.MuiTypography-root, .create-monitor h2.MuiTypography-root,
.create-monitor h6.MuiTypography-root, .create-monitor h6.MuiTypography-root,
.create-monitor p.MuiTypography-root, .create-monitor p.MuiTypography-root {
#monitor-frequencies {
color: var(--env-var-color-2); color: var(--env-var-color-2);
} }
.create-monitor h6.MuiTypography-root { .create-monitor h6.MuiTypography-root {
@@ -36,21 +34,6 @@
position: absolute; position: absolute;
top: 0; top: 0;
} }
.create-monitor .MuiSelect-select.MuiSelect-outlined.MuiInputBase-input {
padding: var(--env-var-spacing-1);
}
.create-monitor .MuiInputBase-root:has(#monitor-frequencies) {
min-width: 300px;
width: 100%;
height: 34px;
border: 1px solid var(--env-var-color-4);
border-radius: var(--env-var-radius-1);
overflow: hidden;
}
.create-monitor .MuiInputBase-root:has(#monitor-frequencies) fieldset {
outline: none;
border: none;
}
.create-monitor .MuiStack-root:has(span.MuiTypography-root.input-error) { .create-monitor .MuiStack-root:has(span.MuiTypography-root.input-error) {
position: relative; position: relative;
} }
@@ -75,4 +58,9 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: var(--env-var-spacing-4); gap: var(--env-var-spacing-4);
}
body:has(.create-monitor) .select-dropdown .MuiMenuItem-root,
.create-monitor .select-wrapper .select-component > .MuiSelect-select {
text-transform: lowercase;
} }
@@ -2,7 +2,7 @@ import "./index.css";
import React, { useState } from "react"; import React, { useState } from "react";
import RadioButton from "../../../Components/RadioButton"; import RadioButton from "../../../Components/RadioButton";
import Button from "../../../Components/Button"; import Button from "../../../Components/Button";
import { Box, MenuItem, Select, Stack, Typography } from "@mui/material"; import { Box, MenuItem, Stack, Typography } from "@mui/material";
import { useSelector, useDispatch } from "react-redux"; import { useSelector, useDispatch } from "react-redux";
import { monitorValidation } from "../../../Validation/validation"; import { monitorValidation } from "../../../Validation/validation";
import { createMonitor } from "../../../Features/Monitors/monitorsSlice"; import { createMonitor } from "../../../Features/Monitors/monitorsSlice";
@@ -10,6 +10,7 @@ import { useNavigate } from "react-router-dom";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import WestRoundedIcon from "@mui/icons-material/WestRounded"; import WestRoundedIcon from "@mui/icons-material/WestRounded";
import Field from "../../../Components/Inputs/Field"; import Field from "../../../Components/Inputs/Field";
import Select from "../../../Components/Inputs/Select";
const CreateMonitor = () => { const CreateMonitor = () => {
const MS_PER_MINUTE = 60000; const MS_PER_MINUTE = 60000;
@@ -125,7 +126,13 @@ const CreateMonitor = () => {
//select values //select values
// const ports = ["Port 1", "Port 2", "Port 3"]; // const ports = ["Port 1", "Port 2", "Port 3"];
const frequencies = [1, 2, 3, 4, 5]; const frequencies = [
{ _id: 1, name: "1 minute" },
{ _id: 2, name: "2 minutes" },
{ _id: 3, name: "3 minutes" },
{ _id: 4, name: "4 minutes" },
{ _id: 5, name: "5 minutes" },
];
return ( return (
<div <div
@@ -309,41 +316,15 @@ const CreateMonitor = () => {
<Typography component="h2">Advanced settings</Typography> <Typography component="h2">Advanced settings</Typography>
</Box> </Box>
<Stack gap={theme.gap.large}> <Stack gap={theme.gap.large}>
{/* TODO - refactor select component */} <Select
<Box> id="monitor-interval"
<Typography component="p" mb={theme.gap.small}> label="Check frequency"
Check frequency value={advancedSettings.interval || 1}
</Typography> onChange={(event) =>
<Select handleChange(event, "interval", setAdvancedSettings)
id="monitor-frequencies" }
value={advancedSettings.interval || 1} items={frequencies}
inputProps={{ id: "monitor-frequencies-select" }} />
onChange={(event) =>
handleChange(event, "interval", setAdvancedSettings)
}
MenuProps={{
PaperProps: {
style: {
marginTop: "10px",
},
},
}}
>
{frequencies.map((freq) => (
<MenuItem
key={`port-${freq}`}
value={freq}
sx={{
fontSize: "13px",
borderRadius: `${theme.shape.borderRadius}px`,
margin: "5px",
}}
>
{freq} {freq === 1 ? "minute" : "minutes"}
</MenuItem>
))}
</Select>
</Box>
{/* TODO */} {/* TODO */}
{/* <FlexibileTextField {/* <FlexibileTextField
id="monitor-settings-retries" id="monitor-settings-retries"
+11 -13
View File
@@ -1,10 +1,11 @@
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { Box, Stack, Typography } from "@mui/material"; import { Box, Stack, Typography } from "@mui/material";
import Button from "../../Components/Button"; import Button from "../../Components/Button";
import "./index.css";
import Field from "../../Components/Inputs/Field"; import Field from "../../Components/Inputs/Field";
import Link from "../../Components/Link"; import Link from "../../Components/Link";
import Select from "../../Components/Inputs/Select";
import "./index.css";
const Settings = () => { const Settings = () => {
const theme = useTheme(); const theme = useTheme();
@@ -38,22 +39,19 @@ const Settings = () => {
</Typography> </Typography>
</Box> </Box>
<Stack gap={theme.gap.xl}> <Stack gap={theme.gap.xl}>
{/* TODO - build select component */} <Select
<Field
type="text"
id="display-timezone" id="display-timezone"
label="Display timezone" label="Display timezone"
placeholder="America / Toronto" value="est"
value="" onChange={() => console.log("disabled")}
onChange={() => console.log("Disabled")} items={[{ _id: "est", name: "America / Toronto" }]}
/> />
<Field <Select
type="text"
id="server-timezone" id="server-timezone"
label="Server timezone" label="Server timezone"
placeholder="America / Toronto" value="est"
value="" onChange={() => console.log("disabled")}
onChange={() => console.log("Disabled")} items={[{ _id: "est", name: "America / Toronto" }]}
/> />
</Stack> </Stack>
</Stack> </Stack>