- Replace Doc icon with Reorder icon
- Replace Text input with Search component - Extend Search component to accept start and end adorment
This commit is contained in:
1 parent
d844078ed7
commit
23d97f8e56
8 files changed
+122
-53
No files matched your search
@@ -54,6 +54,8 @@ const Search = ({
|
|||||||
isAdorned = true,
|
isAdorned = true,
|
||||||
error,
|
error,
|
||||||
disabled,
|
disabled,
|
||||||
|
startAdornment,
|
||||||
|
endAdornment
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
@@ -66,15 +68,15 @@ const Search = ({
|
|||||||
onInputChange={(_, newValue) => {
|
onInputChange={(_, newValue) => {
|
||||||
handleInputChange(newValue);
|
handleInputChange(newValue);
|
||||||
}}
|
}}
|
||||||
onChange={(_, newValue) => {
|
onChange={(e, newValue) => {
|
||||||
handleChange && handleChange(newValue);
|
handleChange && handleChange(e, newValue);
|
||||||
}}
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
freeSolo
|
freeSolo
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
disableClearable
|
disableClearable
|
||||||
options={options}
|
options={options}
|
||||||
getOptionLabel={(option) => option[filteredBy]}
|
getOptionLabel={(option) => option[filteredBy]??""}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
<Stack>
|
<Stack>
|
||||||
<Typography
|
<Typography
|
||||||
@@ -89,9 +91,13 @@ const Search = ({
|
|||||||
{...params}
|
{...params}
|
||||||
error={Boolean(error)}
|
error={Boolean(error)}
|
||||||
placeholder="Type to search"
|
placeholder="Type to search"
|
||||||
InputProps={{
|
slotProps={{
|
||||||
...params.InputProps,
|
input: {
|
||||||
...(isAdorned && { startAdornment: <SearchAdornment /> }),
|
...params.InputProps,
|
||||||
|
...(isAdorned && { startAdornment: <SearchAdornment /> }),
|
||||||
|
...(startAdornment && { startAdornment: startAdornment }),
|
||||||
|
...(endAdornment && { endAdornment: endAdornment }),
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
"& fieldset": {
|
"& fieldset": {
|
||||||
@@ -187,7 +193,7 @@ Search.propTypes = {
|
|||||||
options: PropTypes.array.isRequired,
|
options: PropTypes.array.isRequired,
|
||||||
filteredBy: PropTypes.string.isRequired,
|
filteredBy: PropTypes.string.isRequired,
|
||||||
secondaryLabel: PropTypes.string,
|
secondaryLabel: PropTypes.string,
|
||||||
value: PropTypes.array,
|
value: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||||
inputValue: PropTypes.string.isRequired,
|
inputValue: PropTypes.string.isRequired,
|
||||||
handleInputChange: PropTypes.func.isRequired,
|
handleInputChange: PropTypes.func.isRequired,
|
||||||
handleChange: PropTypes.func,
|
handleChange: PropTypes.func,
|
||||||
@@ -195,6 +201,8 @@ Search.propTypes = {
|
|||||||
sx: PropTypes.object,
|
sx: PropTypes.object,
|
||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
|
startAdornment: PropTypes.object,
|
||||||
|
endAdornment: PropTypes.object
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Search;
|
export default Search;
|
||||||
@@ -3,8 +3,8 @@ import { useTheme } from "@mui/material/styles";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import VisibilityOff from "@mui/icons-material/VisibilityOff";
|
import VisibilityOff from "@mui/icons-material/VisibilityOff";
|
||||||
import Visibility from "@mui/icons-material/Visibility";
|
import Visibility from "@mui/icons-material/Visibility";
|
||||||
import Docs from "../../../../assets/icons/docs.svg?react";
|
import ReorderRoundedIcon from '@mui/icons-material/ReorderRounded';
|
||||||
import DeleteIcon from "../../../../assets/icons/trash-bin.svg?react";
|
import DeleteIcon from "../../../../assets/icons/trash-bin.svg?react";
|
||||||
|
|
||||||
export const HttpAdornment = ({ https, prefix }) => {
|
export const HttpAdornment = ({ https, prefix }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -70,7 +70,7 @@ PasswordEndAdornment.propTypes = {
|
|||||||
export const ServerStartAdornment = () => {
|
export const ServerStartAdornment = () => {
|
||||||
return (
|
return (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
<Docs />
|
<ReorderRoundedIcon />
|
||||||
</InputAdornment>
|
</InputAdornment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
import TextInput from "../../../../Inputs/TextInput";
|
|
||||||
import { ServerStartAdornment, ServerEndAdornment } from "../../../../Inputs/TextInput/Adornments";
|
import { ServerStartAdornment, ServerEndAdornment } from "../../../../Inputs/TextInput/Adornments";
|
||||||
|
import Search from "../../../../Inputs/Search";
|
||||||
|
import {useState} from "react"
|
||||||
|
|
||||||
|
const Server = ({ id, removeItem, onChange, monitors, value, label }) => {
|
||||||
const Server = ({ id, removeItem, value, onChange }) => {
|
const [search, setSearch] = useState("");
|
||||||
|
const handleSearch = (val) => {
|
||||||
|
setSearch(val);
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<TextInput
|
<Search
|
||||||
type="text"
|
id={id}
|
||||||
|
multiple={false}
|
||||||
|
isAdorned={false}
|
||||||
|
options={monitors ? monitors : []}
|
||||||
|
filteredBy="name"
|
||||||
|
inputValue={search}
|
||||||
|
value={value}
|
||||||
startAdornment={<ServerStartAdornment />}
|
startAdornment={<ServerStartAdornment />}
|
||||||
endAdornment={
|
endAdornment={
|
||||||
<ServerEndAdornment
|
<ServerEndAdornment
|
||||||
@@ -13,10 +23,9 @@ const Server = ({ id, removeItem, value, onChange }) => {
|
|||||||
removeItem={removeItem}
|
removeItem={removeItem}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id={id}
|
handleInputChange={handleSearch}
|
||||||
value= {value}
|
handleChange={onChange}
|
||||||
onChange ={ onChange }
|
/>
|
||||||
></TextInput>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ const CustomCard = React.forwardRef((props, ref) => (
|
|||||||
removeItem={props.removeCard}
|
removeItem={props.removeCard}
|
||||||
value={props.value}
|
value={props.value}
|
||||||
onChange={props.onChange}
|
onChange={props.onChange}
|
||||||
|
monitors={props.monitors}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
));
|
));
|
||||||
|
|
||||||
const MyCard = ({ id, index, moveCard, removeCard, value, onChange }) => {
|
const MyCard = ({ id, index, moveCard, removeCard, value, onChange, monitors }) => {
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
const [, drop] = useDrop({
|
const [, drop] = useDrop({
|
||||||
accept: ItemTypes.CARD,
|
accept: ItemTypes.CARD,
|
||||||
@@ -80,6 +81,7 @@ const MyCard = ({ id, index, moveCard, removeCard, value, onChange }) => {
|
|||||||
removeCard={removeCard}
|
removeCard={removeCard}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
monitors={monitors}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useCallback, useContext } from "react";
|
import { useState, useCallback, useContext, useEffect } from "react";
|
||||||
import { Button, Box, Stack, Typography } from "@mui/material";
|
import { Button, Box, Stack, Typography } from "@mui/material";
|
||||||
import ConfigBox from "../../../Components/ConfigBox";
|
import ConfigBox from "../../../Components/ConfigBox";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
@@ -6,11 +6,38 @@ import TabPanel from "@mui/lab/TabPanel";
|
|||||||
import Card from "./Card";
|
import Card from "./Card";
|
||||||
import update from "immutability-helper";
|
import update from "immutability-helper";
|
||||||
import { StatusFormContext } from "../../../Pages/Status/CreateStatusContext";
|
import { StatusFormContext } from "../../../Pages/Status/CreateStatusContext";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import { logger } from "../../../Utils/Logger"
|
||||||
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
|
import { networkService } from "../../../main";
|
||||||
|
|
||||||
const ContentPanel = () => {
|
const ContentPanel = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { form, setForm, errors, setErrors } = useContext(StatusFormContext);
|
const { form, setForm, errors, setErrors } = useContext(StatusFormContext);
|
||||||
const [cards, setCards] = useState(form.monitors);
|
const [cards, setCards] = useState(form.monitors.length>0? form.monitors.map((m, idx)=>({id: idx, val: m})): []);
|
||||||
|
const {user, authToken } = useSelector((state) => state.auth);
|
||||||
|
const [monitors, setMonitors] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchMonitors = async () => {
|
||||||
|
try {
|
||||||
|
const response = await networkService.getMonitorsByTeamId({
|
||||||
|
authToken: authToken,
|
||||||
|
teamId: user.teamId,
|
||||||
|
limit: -1,
|
||||||
|
types: ["http", "ping", "pagespeed", "hardware"],
|
||||||
|
});
|
||||||
|
if(response.data.data.monitors.length==0){
|
||||||
|
setErrors({monitors: "Please config monitors to setup status page"})
|
||||||
|
}
|
||||||
|
setMonitors(response.data.data.monitors);
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: "Failed to fetch monitors data" });
|
||||||
|
logger.error("Failed to fetch monitors", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchMonitors();
|
||||||
|
}, [user, authToken]);
|
||||||
|
|
||||||
const moveCard = useCallback(
|
const moveCard = useCallback(
|
||||||
(dragIndex, hoverIndex) => {
|
(dragIndex, hoverIndex) => {
|
||||||
@@ -27,31 +54,40 @@ const ContentPanel = () => {
|
|||||||
[cards]
|
[cards]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCardChange = (event) => {
|
const handleCardChange = (event, val) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const { value, id } = event.target;
|
const { id } = event.target;
|
||||||
let idx = cards.findIndex((a) => a.id == id);
|
let idx = cards.findIndex((a) => {
|
||||||
|
let found = false;
|
||||||
|
let optionIdx = id.indexOf("-option");
|
||||||
|
if (optionIdx !== -1) found = a.id == id.substr(0, optionIdx);
|
||||||
|
else found = a.id == id;
|
||||||
|
return found;
|
||||||
|
});
|
||||||
let newCards;
|
let newCards;
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
let x = JSON.parse(JSON.stringify(cards[idx]));
|
let x = JSON.parse(JSON.stringify(cards[idx]));
|
||||||
x.url = value;
|
x.val = val;
|
||||||
newCards = update(cards, { $splice: [[idx, 1, x]] });
|
newCards = update(cards, { $splice: [[idx, 1, x]] });
|
||||||
setCards(newCards);
|
setCards(newCards);
|
||||||
} else {
|
} else {
|
||||||
newCards = update(cards, { $push: [{ id: id, url: value }] });
|
newCards = update(cards, { $push: [{ id: id, val: val }] });
|
||||||
setCards(newCards);
|
setCards(newCards);
|
||||||
}
|
}
|
||||||
setForm({ ...form, monitors: newCards });
|
setForm({ ...form, monitors: newCards.map(c=>c.val) });
|
||||||
};
|
};
|
||||||
const handleAddNew = () => {
|
const handleAddNew = () => {
|
||||||
|
if (cards.length === monitors.length) return;
|
||||||
const newCards = [...cards, { id: "" + Math.random() }];
|
const newCards = [...cards, { id: "" + Math.random() }];
|
||||||
setCards(newCards);
|
setCards(newCards);
|
||||||
setForm({ ...form, monitors: newCards });
|
|
||||||
};
|
};
|
||||||
const removeCard = (id) => {
|
const removeCard = (id) => {
|
||||||
const newCards = cards.filter((c) => c?.id != id);
|
const newCards = cards.filter((c) => c?.id != id);
|
||||||
setCards(newCards);
|
setCards(newCards);
|
||||||
setForm({ ...form, monitors: newCards });
|
setForm({
|
||||||
|
...form,
|
||||||
|
monitors: newCards.filter((c) => c.val !== undefined).map((c) => c.val),
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -107,7 +143,12 @@ const ContentPanel = () => {
|
|||||||
{" "}
|
{" "}
|
||||||
Servers list{" "}
|
Servers list{" "}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button onClick={handleAddNew}>Add New</Button>
|
<Button
|
||||||
|
onClick={handleAddNew}
|
||||||
|
disabled={monitors.length === 0 || monitors.length <= cards.length}
|
||||||
|
>
|
||||||
|
Add New
|
||||||
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
{cards.length > 0 && (
|
{cards.length > 0 && (
|
||||||
<Stack
|
<Stack
|
||||||
@@ -115,18 +156,21 @@ const ContentPanel = () => {
|
|||||||
direction="column"
|
direction="column"
|
||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
>
|
>
|
||||||
{cards.map((card, idx) => (
|
{cards.map((card, idx) => {
|
||||||
<Card
|
return (
|
||||||
key={idx}
|
<Card
|
||||||
index={idx}
|
key={idx}
|
||||||
id={card?.id ?? "" + Math.random()}
|
index={idx}
|
||||||
text={"" + idx}
|
id={card?.id ?? "" + Math.random()}
|
||||||
moveCard={moveCard}
|
text={"" + idx}
|
||||||
removeCard={removeCard}
|
moveCard={moveCard}
|
||||||
value={card?.url ?? ""}
|
removeCard={removeCard}
|
||||||
onChange={handleCardChange}
|
value={card.val ?? {}}
|
||||||
/>
|
onChange={handleCardChange}
|
||||||
))}
|
monitors={monitors}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
{errors["monitors"] && (
|
{errors["monitors"] && (
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ const CreateMaintenance = () => {
|
|||||||
setSearch(value);
|
setSearch(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectMonitors = (monitors) => {
|
const handleSelectMonitors = (_, monitors) => {
|
||||||
setForm({ ...form, monitors });
|
setForm({ ...form, monitors });
|
||||||
const { error } = maintenanceWindowValidation.validate(
|
const { error } = maintenanceWindowValidation.validate(
|
||||||
{ monitors },
|
{ monitors },
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import { networkService } from "../../../main";
|
|||||||
const CreateStatus = ({ initForm }) => {
|
const CreateStatus = ({ initForm }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const mode = useSelector((state) => state.ui.mode);
|
const mode = useSelector((state) => state.ui.mode);
|
||||||
const {authToken} = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
const {apiBaseUrl} = useSelector((state) => state.settings);
|
const {apiBaseUrl} = useSelector((state) => state.settings);
|
||||||
const [tabIdx, setTabIdx] = useState(0);
|
const [tabIdx, setTabIdx] = useState(0);
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
@@ -46,7 +46,6 @@ import { networkService } from "../../../main";
|
|||||||
// showBarcode: false,
|
// showBarcode: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const setActiveTabOnErrors = () => {
|
const setActiveTabOnErrors = () => {
|
||||||
let newIdx = -1;
|
let newIdx = -1;
|
||||||
Object.keys(errors).map((id) => {
|
Object.keys(errors).map((id) => {
|
||||||
@@ -72,7 +71,6 @@ import { networkService } from "../../../main";
|
|||||||
delete form.logo;
|
delete form.logo;
|
||||||
//let localData = {...form, monitors: form.monitors.map(m=>m.url)}
|
//let localData = {...form, monitors: form.monitors.map(m=>m.url)}
|
||||||
let localData = {...form, monitors: form.monitors, theme: mode}
|
let localData = {...form, monitors: form.monitors, theme: mode}
|
||||||
|
|
||||||
if (hasValidationErrors(localData, publicPageGeneralSettingsValidation, setErrors)) {
|
if (hasValidationErrors(localData, publicPageGeneralSettingsValidation, setErrors)) {
|
||||||
setActiveTabOnErrors();
|
setActiveTabOnErrors();
|
||||||
return;
|
return;
|
||||||
@@ -85,7 +83,8 @@ import { networkService } from "../../../main";
|
|||||||
// if (error) return;
|
// if (error) return;
|
||||||
|
|
||||||
//form.logo = { ...logo, size: formatBytes(logo?.size) };
|
//form.logo = { ...logo, size: formatBytes(logo?.size) };
|
||||||
let config = { authToken: authToken, url: apiBaseUrl, data: localData };
|
localData = {...form, monitors: form.monitors.map(m=>m.url),theme: mode}
|
||||||
|
let config = { authToken: authToken, url: "status-page", data: localData };
|
||||||
try{
|
try{
|
||||||
const res = await networkService.createStatusPage(config)
|
const res = await networkService.createStatusPage(config)
|
||||||
if (!res.status === 200) {
|
if (!res.status === 200) {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import CreateStatus from "./CreateStatus";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { networkService } from "../../main";
|
import { networkService } from "../../main";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
import { createToast } from "../../Utils/toastUtils"
|
||||||
|
import { logger } from "../../Utils/Logger";
|
||||||
|
|
||||||
const Status = () => {
|
const Status = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -13,13 +15,18 @@ const Status = () => {
|
|||||||
const {authToken} = useSelector((state) => state.auth);
|
const {authToken} = useSelector((state) => state.auth);
|
||||||
const {apiBaseUrl} = useSelector((state) => state.settings);
|
const {apiBaseUrl} = useSelector((state) => state.settings);
|
||||||
const [initForm, setInitForm] = useState({});
|
const [initForm, setInitForm] = useState({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getStatusPage = async () => {
|
const getStatusPage = async () => {
|
||||||
let config = { authToken: authToken, url: apiBaseUrl };
|
let config = { authToken: authToken, url: "status-page" };
|
||||||
let res = await networkService.getStatusPageByUrl(config);
|
try {
|
||||||
if(res && res.data)
|
let res = await networkService.getStatusPageByUrl(config);
|
||||||
setInitForm( res.data.data)
|
if(res && res.data)
|
||||||
|
setInitForm( res.data.data)
|
||||||
|
}catch (error) {
|
||||||
|
createToast({ body: "Failed to fetch status page data" });
|
||||||
|
logger.error("Failed to fetch status page", error);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
getStatusPage();
|
getStatusPage();
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
Reference in new issue
Block a user