add placeholder
This commit is contained in:
1 parent
94ecaddae2
commit
2319b67d05
6 files changed
+43
-22
No files matched your search
@@ -4,22 +4,59 @@ import type { SelectProps } from "@mui/material/Select";
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { FieldLabel } from "./FieldLabel";
|
import { FieldLabel } from "./FieldLabel";
|
||||||
import { ChevronDown } from "lucide-react";
|
import { ChevronDown } from "lucide-react";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
interface SelectInputProps<T> extends Omit<SelectProps<T>, "label"> {
|
interface SelectInputProps<T> extends Omit<SelectProps<T>, "label"> {
|
||||||
fieldLabel?: string;
|
fieldLabel?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
|
placeholder?: string;
|
||||||
|
placeholderColor?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SelectInput = <T,>({
|
export const SelectInput = <T,>({
|
||||||
fieldLabel,
|
fieldLabel,
|
||||||
required,
|
required,
|
||||||
|
placeholder,
|
||||||
|
placeholderColor,
|
||||||
...props
|
...props
|
||||||
}: SelectInputProps<T>) => {
|
}: SelectInputProps<T>) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const emptyPlaceholderColor = placeholderColor || theme.palette.text.disabled;
|
||||||
|
|
||||||
|
const renderValue = (selected: any) => {
|
||||||
|
const isMultiple = Boolean((props as any).multiple);
|
||||||
|
const isEmpty = isMultiple
|
||||||
|
? !Array.isArray(selected) || selected.length === 0
|
||||||
|
: selected === undefined || selected === null || selected === "";
|
||||||
|
|
||||||
|
if (isEmpty && placeholder) {
|
||||||
|
return (
|
||||||
|
<Typography sx={{ color: emptyPlaceholderColor }}>
|
||||||
|
{placeholder}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMultiple) {
|
||||||
|
const items: string[] = Array.isArray(selected) ? selected : [];
|
||||||
|
const capitalized = items.map(
|
||||||
|
(item) => item.charAt(0).toUpperCase() + item.slice(1)
|
||||||
|
);
|
||||||
|
return <Typography>{capitalized.join(" | ")}</Typography> as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
return selected as any;
|
||||||
|
};
|
||||||
|
|
||||||
const select = (
|
const select = (
|
||||||
<Select<T>
|
<Select<T>
|
||||||
{...props}
|
{...props}
|
||||||
|
displayEmpty
|
||||||
|
renderValue={renderValue}
|
||||||
|
inputProps={{
|
||||||
|
...(props.inputProps || {}),
|
||||||
|
"aria-placeholder": placeholder,
|
||||||
|
}}
|
||||||
IconComponent={() => (
|
IconComponent={() => (
|
||||||
<ChevronDown
|
<ChevronDown
|
||||||
size={18}
|
size={18}
|
||||||
|
|||||||
@@ -12,16 +12,6 @@ import {
|
|||||||
type MonitorStatus,
|
type MonitorStatus,
|
||||||
} from "@/types/monitor";
|
} from "@/types/monitor";
|
||||||
|
|
||||||
const formatValue = (value: string[], fallback: string) => {
|
|
||||||
if (value.length === 0) {
|
|
||||||
return fallback;
|
|
||||||
}
|
|
||||||
const capitalized = value.map(
|
|
||||||
(item) => item.charAt(0).toUpperCase() + item.slice(1)
|
|
||||||
);
|
|
||||||
return capitalized.join(" | ");
|
|
||||||
};
|
|
||||||
|
|
||||||
type HeaderFilterProps = {
|
type HeaderFilterProps = {
|
||||||
selectedTypes: UptimeMonitorType[];
|
selectedTypes: UptimeMonitorType[];
|
||||||
selectedStatuses: MonitorStatus[];
|
selectedStatuses: MonitorStatus[];
|
||||||
@@ -56,12 +46,10 @@ export const HeaderFilter = ({
|
|||||||
<Stack spacing={theme.spacing(4)} direction={{ xs: "column", sm: "row" }}>
|
<Stack spacing={theme.spacing(4)} direction={{ xs: "column", sm: "row" }}>
|
||||||
<Select
|
<Select
|
||||||
fieldLabel="Monitor type"
|
fieldLabel="Monitor type"
|
||||||
|
placeholder="Monitor type"
|
||||||
multiple
|
multiple
|
||||||
value={selectedTypes}
|
value={selectedTypes}
|
||||||
onChange={handleTypeChange}
|
onChange={handleTypeChange}
|
||||||
renderValue={(selected) => (
|
|
||||||
<Typography>{formatValue(selected, "All Monitor Types")}</Typography>
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{UptimeMonitorTypes.map((type) => (
|
{UptimeMonitorTypes.map((type) => (
|
||||||
<MenuItem key={type} value={type}>
|
<MenuItem key={type} value={type}>
|
||||||
@@ -72,14 +60,10 @@ export const HeaderFilter = ({
|
|||||||
</Select>
|
</Select>
|
||||||
<Select
|
<Select
|
||||||
fieldLabel="Monitor status"
|
fieldLabel="Monitor status"
|
||||||
|
placeholder="Monitor status"
|
||||||
multiple
|
multiple
|
||||||
value={selectedStatuses}
|
value={selectedStatuses}
|
||||||
onChange={handleStatusChange}
|
onChange={handleStatusChange}
|
||||||
renderValue={(selected) => (
|
|
||||||
<Typography>
|
|
||||||
{formatValue(selected, "All Monitor Statuses")}
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{MonitorStatuses.map((status) => (
|
{MonitorStatuses.map((status) => (
|
||||||
<MenuItem key={status} value={status}>
|
<MenuItem key={status} value={status}>
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ const UptimeMonitors = () => {
|
|||||||
setSortField={setSortField}
|
setSortField={setSortField}
|
||||||
sortOrder={sortOrder}
|
sortOrder={sortOrder}
|
||||||
setSortOrder={setSortOrder}
|
setSortOrder={setSortOrder}
|
||||||
count={count}
|
count={monitors?.length || 0}
|
||||||
page={page}
|
page={page}
|
||||||
setPage={setPage}
|
setPage={setPage}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
|
|||||||
Generated
-1
@@ -5379,7 +5379,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz",
|
||||||
"integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==",
|
"integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"accepts": "^2.0.0",
|
"accepts": "^2.0.0",
|
||||||
"body-parser": "^2.2.0",
|
"body-parser": "^2.2.0",
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import {
|
|||||||
|
|
||||||
export interface IMonitorController {
|
export interface IMonitorController {
|
||||||
create(req: Request, res: Response, next: NextFunction): Promise<void>;
|
create(req: Request, res: Response, next: NextFunction): Promise<void>;
|
||||||
|
getSummary(req: Request, res: Response, next: NextFunction): Promise<void>;
|
||||||
|
get(req: Request, res: Response, next: NextFunction): Promise<void>;
|
||||||
getAll(req: Request, res: Response, next: NextFunction): Promise<void>;
|
getAll(req: Request, res: Response, next: NextFunction): Promise<void>;
|
||||||
getChecks(req: Request, res: Response, next: NextFunction): Promise<void>;
|
getChecks(req: Request, res: Response, next: NextFunction): Promise<void>;
|
||||||
togglePause(req: Request, res: Response, next: NextFunction): Promise<void>;
|
togglePause(req: Request, res: Response, next: NextFunction): Promise<void>;
|
||||||
get(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
||||||
update(req: Request, res: Response, next: NextFunction): Promise<void>;
|
update(req: Request, res: Response, next: NextFunction): Promise<void>;
|
||||||
delete(req: Request, res: Response, next: NextFunction): Promise<void>;
|
delete(req: Request, res: Response, next: NextFunction): Promise<void>;
|
||||||
testNotifications(
|
testNotifications(
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class MonitorService implements IMonitorService {
|
|||||||
|
|
||||||
const countResult = await Monitor.aggregate([
|
const countResult = await Monitor.aggregate([
|
||||||
{
|
{
|
||||||
$match: matchConditions,
|
$match: { teamId: teamObjectId },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
|
|||||||
Reference in new issue
Block a user