2020-10-29 20:54:17 +01:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Checkbox,
|
|
|
|
CircularProgress,
|
|
|
|
ClickAwayListener,
|
|
|
|
FormControlLabel,
|
|
|
|
InputBase,
|
|
|
|
Paper,
|
|
|
|
Popper,
|
|
|
|
Tooltip,
|
|
|
|
useTheme,
|
2022-01-28 20:20:15 +01:00
|
|
|
} from "@mui/material";
|
|
|
|
import IconButton from "@mui/material/IconButton";
|
|
|
|
import SearchIcon from "@mui/icons-material/Search";
|
|
|
|
import FilterListIcon from "@mui/icons-material/FilterList";
|
|
|
|
import DeleteIcon from "@mui/icons-material/Delete";
|
2020-10-29 20:54:17 +01:00
|
|
|
import React, { useRef, useState } from "react";
|
2020-11-28 15:48:19 +01:00
|
|
|
import { gql, useMutation, useQuery } from "@apollo/client";
|
2020-10-29 20:54:17 +01:00
|
|
|
import { withoutTypename } from "../../lib/omitTypename";
|
2022-01-28 20:20:15 +01:00
|
|
|
import { Alert } from "@mui/lab";
|
2020-11-28 15:48:19 +01:00
|
|
|
import { useClearHTTPRequestLog } from "./hooks/useClearHTTPRequestLog";
|
2022-01-28 20:20:15 +01:00
|
|
|
import { ConfirmationDialog, useConfirmationDialog } from "./ConfirmationDialog";
|
2020-10-29 20:54:17 +01:00
|
|
|
|
|
|
|
const FILTER = gql`
|
|
|
|
query HttpRequestLogFilter {
|
|
|
|
httpRequestLogFilter {
|
|
|
|
onlyInScope
|
2020-12-21 12:50:09 +01:00
|
|
|
searchExpression
|
2020-10-29 20:54:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const SET_FILTER = gql`
|
|
|
|
mutation SetHttpRequestLogFilter($filter: HttpRequestLogFilterInput) {
|
|
|
|
setHttpRequestLogFilter(filter: $filter) {
|
|
|
|
onlyInScope
|
2020-12-21 12:50:09 +01:00
|
|
|
searchExpression
|
2020-10-29 20:54:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export interface SearchFilter {
|
|
|
|
onlyInScope: boolean;
|
2020-12-21 12:50:09 +01:00
|
|
|
searchExpression: string;
|
2020-10-29 20:54:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function Search(): JSX.Element {
|
|
|
|
const theme = useTheme();
|
|
|
|
|
2020-12-21 12:50:09 +01:00
|
|
|
const [searchExpr, setSearchExpr] = useState("");
|
2022-01-28 20:20:15 +01:00
|
|
|
const {
|
|
|
|
loading: filterLoading,
|
|
|
|
error: filterErr,
|
|
|
|
data: filter,
|
|
|
|
} = useQuery(FILTER, {
|
|
|
|
onCompleted: (data) => {
|
|
|
|
setSearchExpr(data.httpRequestLogFilter?.searchExpression || "");
|
|
|
|
},
|
|
|
|
});
|
2020-10-29 20:54:17 +01:00
|
|
|
|
2022-01-28 20:20:15 +01:00
|
|
|
const [setFilterMutate, { error: setFilterErr, loading: setFilterLoading }] = useMutation<{
|
2020-10-29 20:54:17 +01:00
|
|
|
setHttpRequestLogFilter: SearchFilter | null;
|
|
|
|
}>(SET_FILTER, {
|
2022-01-28 20:20:15 +01:00
|
|
|
update(cache, { data }) {
|
2020-11-28 15:48:19 +01:00
|
|
|
cache.writeQuery({
|
2020-10-29 20:54:17 +01:00
|
|
|
query: FILTER,
|
|
|
|
data: {
|
2022-01-28 20:20:15 +01:00
|
|
|
httpRequestLogFilter: data?.setHttpRequestLogFilter,
|
2020-10-29 20:54:17 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2020-12-29 20:46:42 +01:00
|
|
|
onError: () => {},
|
2020-10-29 20:54:17 +01:00
|
|
|
});
|
|
|
|
|
2022-01-28 20:20:15 +01:00
|
|
|
const [clearHTTPRequestLog, clearHTTPRequestLogResult] = useClearHTTPRequestLog();
|
2020-11-28 15:48:19 +01:00
|
|
|
const clearHTTPConfirmationDialog = useConfirmationDialog();
|
|
|
|
|
2022-01-28 20:20:15 +01:00
|
|
|
const filterRef = useRef<HTMLFormElement>(null);
|
2020-10-29 20:54:17 +01:00
|
|
|
const [filterOpen, setFilterOpen] = useState(false);
|
|
|
|
|
|
|
|
const handleSubmit = (e: React.SyntheticEvent) => {
|
2020-12-21 12:50:09 +01:00
|
|
|
setFilterMutate({
|
|
|
|
variables: {
|
|
|
|
filter: {
|
|
|
|
...withoutTypename(filter?.httpRequestLogFilter),
|
|
|
|
searchExpression: searchExpr,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
setFilterOpen(false);
|
2020-10-29 20:54:17 +01:00
|
|
|
e.preventDefault();
|
|
|
|
};
|
|
|
|
|
2022-01-28 20:20:15 +01:00
|
|
|
const handleClickAway = (event: MouseEvent | TouchEvent) => {
|
|
|
|
if (filterRef?.current && filterRef.current.contains(event.target as HTMLElement)) {
|
2020-10-29 20:54:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
setFilterOpen(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-11-28 15:48:19 +01:00
|
|
|
<Box>
|
|
|
|
<Error prefix="Error fetching filter" error={filterErr} />
|
|
|
|
<Error prefix="Error setting filter" error={setFilterErr} />
|
2022-01-28 20:20:15 +01:00
|
|
|
<Error prefix="Error clearing all HTTP logs" error={clearHTTPRequestLogResult.error} />
|
2020-11-28 15:48:19 +01:00
|
|
|
<Box style={{ display: "flex", flex: 1 }}>
|
|
|
|
<ClickAwayListener onClickAway={handleClickAway}>
|
|
|
|
<Paper
|
|
|
|
component="form"
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
ref={filterRef}
|
2022-01-28 20:20:15 +01:00
|
|
|
sx={{
|
|
|
|
padding: "2px 4px",
|
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
width: 400,
|
|
|
|
}}
|
2020-11-28 15:48:19 +01:00
|
|
|
>
|
|
|
|
<Tooltip title="Toggle filter options">
|
|
|
|
<IconButton
|
|
|
|
onClick={() => setFilterOpen(!filterOpen)}
|
2022-01-28 20:20:15 +01:00
|
|
|
sx={{
|
|
|
|
p: 1,
|
|
|
|
color: filter?.httpRequestLogFilter?.onlyInScope ? "primary.main" : "inherit",
|
2020-11-28 15:48:19 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{filterLoading || setFilterLoading ? (
|
2022-01-28 20:20:15 +01:00
|
|
|
<CircularProgress sx={{ color: theme.palette.text.primary }} size={23} />
|
2020-11-28 15:48:19 +01:00
|
|
|
) : (
|
|
|
|
<FilterListIcon />
|
|
|
|
)}
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
<InputBase
|
2022-01-28 20:20:15 +01:00
|
|
|
sx={{
|
|
|
|
ml: 1,
|
|
|
|
flex: 1,
|
|
|
|
}}
|
2020-11-28 15:48:19 +01:00
|
|
|
placeholder="Search proxy logs…"
|
2020-12-21 12:50:09 +01:00
|
|
|
value={searchExpr}
|
|
|
|
onChange={(e) => setSearchExpr(e.target.value)}
|
2020-11-28 15:48:19 +01:00
|
|
|
onFocus={() => setFilterOpen(true)}
|
|
|
|
/>
|
|
|
|
<Tooltip title="Search">
|
2022-01-28 20:20:15 +01:00
|
|
|
<IconButton type="submit" sx={{ padding: 1.25 }}>
|
2020-11-28 15:48:19 +01:00
|
|
|
<SearchIcon />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
<Popper
|
|
|
|
open={filterOpen}
|
|
|
|
anchorEl={filterRef.current}
|
2022-01-28 20:20:15 +01:00
|
|
|
placement="bottom"
|
|
|
|
style={{ zIndex: theme.zIndex.appBar }}
|
2020-10-29 20:54:17 +01:00
|
|
|
>
|
2022-01-28 20:20:15 +01:00
|
|
|
<Paper
|
|
|
|
sx={{
|
|
|
|
width: 400,
|
|
|
|
marginTop: 0.5,
|
|
|
|
p: 1.5,
|
|
|
|
}}
|
|
|
|
>
|
2020-11-28 15:48:19 +01:00
|
|
|
<FormControlLabel
|
|
|
|
control={
|
|
|
|
<Checkbox
|
2022-01-28 20:20:15 +01:00
|
|
|
checked={filter?.httpRequestLogFilter?.onlyInScope ? true : false}
|
2020-11-28 15:48:19 +01:00
|
|
|
disabled={filterLoading || setFilterLoading}
|
|
|
|
onChange={(e) =>
|
|
|
|
setFilterMutate({
|
|
|
|
variables: {
|
|
|
|
filter: {
|
|
|
|
...withoutTypename(filter?.httpRequestLogFilter),
|
|
|
|
onlyInScope: e.target.checked,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
2020-10-29 20:54:17 +01:00
|
|
|
}
|
2020-11-28 15:48:19 +01:00
|
|
|
label="Only show in-scope requests"
|
2020-10-29 20:54:17 +01:00
|
|
|
/>
|
2020-11-28 15:48:19 +01:00
|
|
|
</Paper>
|
|
|
|
</Popper>
|
2020-10-29 20:54:17 +01:00
|
|
|
</Paper>
|
2020-11-28 15:48:19 +01:00
|
|
|
</ClickAwayListener>
|
|
|
|
<Box style={{ marginLeft: "auto" }}>
|
|
|
|
<Tooltip title="Clear all">
|
|
|
|
<IconButton onClick={clearHTTPConfirmationDialog.open}>
|
|
|
|
<DeleteIcon />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
</Box>
|
2020-10-29 20:54:17 +01:00
|
|
|
</Box>
|
2020-11-28 15:48:19 +01:00
|
|
|
<ConfirmationDialog
|
|
|
|
isOpen={clearHTTPConfirmationDialog.isOpen}
|
|
|
|
onClose={clearHTTPConfirmationDialog.close}
|
|
|
|
onConfirm={clearHTTPRequestLog}
|
|
|
|
>
|
|
|
|
All proxy logs are going to be removed. This action cannot be undone.
|
|
|
|
</ConfirmationDialog>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Error(props: { prefix: string; error?: Error }) {
|
|
|
|
if (!props.error) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box mb={4}>
|
|
|
|
<Alert severity="error">
|
|
|
|
{props.prefix}: {props.error.message}
|
|
|
|
</Alert>
|
|
|
|
</Box>
|
2020-10-29 20:54:17 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Search;
|