Skip to content

Commit

Permalink
Merge pull request #185 from Thiht/issue-154-filters
Browse files Browse the repository at this point in the history
Issue 154 filters
  • Loading branch information
Thiht authored Apr 20, 2021
2 parents 2fda2c5 + 8a00f2d commit 45254cb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.cache/
.DS_Store
.vscode/
build/
client/dist/
Expand Down
4 changes: 2 additions & 2 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
http://localhost:8082 {
uri strip_prefix /smocker
reverse_proxy localhost:8081
uri strip_prefix /smocker
reverse_proxy localhost:8081
}
8 changes: 8 additions & 0 deletions client/components/History.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
}
}

// These rules are used for the inline filters (sort by, filter, etc.)
.ant-btn-link {
padding: 6px;
.ant-select-selector {
padding: 0;
}
}

.entry {
border-radius: 3px;
background-color: white;
Expand Down
40 changes: 35 additions & 5 deletions client/components/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PageHeader,
Pagination,
Row,
Select,
Spin,
Tag,
Typography,
Expand Down Expand Up @@ -193,6 +194,7 @@ const HistoryComponent = ({
"history.order.by.entry.field",
"response"
);
const [filter, setFilter] = useLocalStorage("history.filter", "all");
const [page, setPage] = React.useState(1);
const [pageSize, setPageSize] = React.useState(minPageSize);
const [polling, togglePolling] = usePoll(10000, fetch, sessionID);
Expand All @@ -216,10 +218,20 @@ const HistoryComponent = ({
historyEntry,
`${entryField}.date`,
order as "asc" | "desc"
).slice(
Math.max((page - 1) * pageSize, 0),
Math.min(page * pageSize, historyEntry.length)
);
)
.slice(
Math.max((page - 1) * pageSize, 0),
Math.min(page * pageSize, historyEntry.length)
)
.filter((entry) => {
if (filter === "http-errors") {
return entry.response.status >= 400 && entry.response.status <= 599;
}
if (filter === "smocker-errors") {
return entry.response.status >= 600 && entry.response.status <= 699;
}
return true;
});
const handleDisplayNewMock = (entry: Entry) => () => {
const request = cleanupRequest(entry);
const response =
Expand Down Expand Up @@ -274,6 +286,7 @@ const HistoryComponent = ({
const onSort = () =>
setEntryField(entryField === "request" ? "response" : "request");
const onSortDate = () => setOrder(order === "asc" ? "desc" : "asc");
const onFilter = (value: string) => setFilter(value);
return (
<div className="history" ref={ref}>
<PageHeader
Expand Down Expand Up @@ -319,7 +332,24 @@ const HistoryComponent = ({
<Button onClick={onSortDate} type="link">
{order === "asc" ? "oldest" : "newest"}
</Button>
are displayed first.
are displayed first. Show
<Select
defaultValue={filter}
bordered={false}
showArrow={false}
className="ant-btn-link"
dropdownStyle={{
minWidth: 180, // required to allow all the text to fit in the dropdown
}}
onChange={onFilter}
>
<Select.Option value="all">everything</Select.Option>
<Select.Option value="http-errors">HTTP errors only</Select.Option>
<Select.Option value="smocker-errors">
Smocker errors only
</Select.Option>
</Select>
.
</p>
<Spin delay={300} spinning={loading && historyEntry.length === 0}>
{body}
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3223,9 +3223,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001043, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001111:
version "1.0.30001122"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001122.tgz#2c8ff631330d986a07a7ba7125cce77a1373b475"
integrity sha512-pxjw28CThdrqfz06nJkpAc5SXM404TXB/h5f4UJX+rrXJKE/1bu/KAILc2AY+O6cQIFtRjV9qOR2vaEp9LDGUA==
version "1.0.30001214"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001214.tgz"
integrity sha512-O2/SCpuaU3eASWVaesQirZv1MSjUNOvmugaD8zNSJqw6Vv5SGwoOpA9LJs3pNPfM745nxqPvfZY3MQKY4AKHYg==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 45254cb

Please sign in to comment.