diff options
Diffstat (limited to 'src/components/RequestList/RequestList.tsx')
| -rw-r--r-- | src/components/RequestList/RequestList.tsx | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/components/RequestList/RequestList.tsx b/src/components/RequestList/RequestList.tsx index 8217229..1ab53d8 100644 --- a/src/components/RequestList/RequestList.tsx +++ b/src/components/RequestList/RequestList.tsx | |||
| @@ -21,9 +21,14 @@ type EnabledMethods = { | |||
| 21 | [method in Method]: boolean; | 21 | [method in Method]: boolean; |
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | type EnabledHosts = { | ||
| 25 | [host: string]: boolean; | ||
| 26 | }; | ||
| 27 | |||
| 24 | export default function RequestList() { | 28 | export default function RequestList() { |
| 25 | const { darkMode } = useContext(SettingsContext); | 29 | const { darkMode } = useContext(SettingsContext); |
| 26 | const { | 30 | const { |
| 31 | config, | ||
| 27 | calls: requests, | 32 | calls: requests, |
| 28 | selectedCall, | 33 | selectedCall, |
| 29 | setSelectedCall, | 34 | setSelectedCall, |
| @@ -33,6 +38,20 @@ export default function RequestList() { | |||
| 33 | const [search, setSearch] = useState(""); | 38 | const [search, setSearch] = useState(""); |
| 34 | const [enableRegex, setEnableRegex] = useState(false); | 39 | const [enableRegex, setEnableRegex] = useState(false); |
| 35 | 40 | ||
| 41 | const [hosts, setHosts] = useState<EnabledHosts>({}); | ||
| 42 | |||
| 43 | useEffect(() => { | ||
| 44 | setHosts((oldValues) => | ||
| 45 | (config?.urls ?? []).reduce((acc, url) => { | ||
| 46 | const { host } = new URL(url); | ||
| 47 | return { | ||
| 48 | ...acc, | ||
| 49 | [host]: oldValues[host] ?? true, | ||
| 50 | }; | ||
| 51 | }, {}) | ||
| 52 | ); | ||
| 53 | }, [config?.urls]); | ||
| 54 | |||
| 36 | const [methods, setMethods] = useState<EnabledMethods>({ | 55 | const [methods, setMethods] = useState<EnabledMethods>({ |
| 37 | GET: true, | 56 | GET: true, |
| 38 | HEAD: true, | 57 | HEAD: true, |
| @@ -95,6 +114,17 @@ export default function RequestList() { | |||
| 95 | 114 | ||
| 96 | return requests | 115 | return requests |
| 97 | .reverse() | 116 | .reverse() |
| 117 | .filter((request) => { | ||
| 118 | const [_, hostHeader] = request.request.headers.find( | ||
| 119 | ([key]) => key.toLowerCase() === "host" | ||
| 120 | ) ?? [null, null]; | ||
| 121 | |||
| 122 | if (hostHeader === null) { | ||
| 123 | return true; | ||
| 124 | } | ||
| 125 | |||
| 126 | return hosts[hostHeader] ?? false; | ||
| 127 | }) | ||
| 98 | .filter( | 128 | .filter( |
| 99 | (request) => | 129 | (request) => |
| 100 | enabledMethods.length === 0 || | 130 | enabledMethods.length === 0 || |
| @@ -103,7 +133,7 @@ export default function RequestList() { | |||
| 103 | .filter( | 133 | .filter( |
| 104 | (request) => search === "" || searchRegex.test(request.request.path) | 134 | (request) => search === "" || searchRegex.test(request.request.path) |
| 105 | ); | 135 | ); |
| 106 | }, [requests, search, enabledMethods, enableRegex]); | 136 | }, [requests, search, hosts, enabledMethods, enableRegex]); |
| 107 | 137 | ||
| 108 | return ( | 138 | return ( |
| 109 | <div className={classNames(styles.listContainer, "d-flex")}> | 139 | <div className={classNames(styles.listContainer, "d-flex")}> |
| @@ -205,6 +235,20 @@ export default function RequestList() { | |||
| 205 | /> | 235 | /> |
| 206 | </Form.Group> | 236 | </Form.Group> |
| 207 | <Form.Group className="mb-4"> | 237 | <Form.Group className="mb-4"> |
| 238 | <Form.Label className="fw-bold">Hosts</Form.Label> | ||
| 239 | {Object.entries(hosts).map(([host, enabled]) => ( | ||
| 240 | <Form.Check | ||
| 241 | key={host} | ||
| 242 | type="switch" | ||
| 243 | label={host} | ||
| 244 | checked={enabled} | ||
| 245 | onChange={() => | ||
| 246 | setHosts((values) => ({ ...values, [host]: !enabled })) | ||
| 247 | } | ||
| 248 | /> | ||
| 249 | ))} | ||
| 250 | </Form.Group> | ||
| 251 | <Form.Group className="mb-4"> | ||
| 208 | <Form.Label className="fw-bold">Method</Form.Label> | 252 | <Form.Label className="fw-bold">Method</Form.Label> |
| 209 | {Object.entries(methods).map(([method, enabled]) => ( | 253 | {Object.entries(methods).map(([method, enabled]) => ( |
| 210 | <Form.Check | 254 | <Form.Check |
| @@ -212,7 +256,9 @@ export default function RequestList() { | |||
| 212 | type="switch" | 256 | type="switch" |
| 213 | label={method} | 257 | label={method} |
| 214 | checked={enabled} | 258 | checked={enabled} |
| 215 | onChange={() => setMethods({ ...methods, [method]: !enabled })} | 259 | onChange={() => |
| 260 | setMethods((values) => ({ ...values, [method]: !enabled })) | ||
| 261 | } | ||
| 216 | /> | 262 | /> |
| 217 | ))} | 263 | ))} |
| 218 | </Form.Group> | 264 | </Form.Group> |
