mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
feat(ui): pause fetches on alt+space
This commit is contained in:
committed by
Łukasz Mierzwa
parent
f8f193f6db
commit
a1197cfe44
@@ -7,6 +7,8 @@ import useDimensions from "react-cool-dimensions";
|
||||
|
||||
import { SizeDetail } from "bricks.js";
|
||||
|
||||
import { useHotkeys } from "react-hotkeys-hook";
|
||||
|
||||
import { AlertStore } from "Stores/AlertStore";
|
||||
import { Settings } from "Stores/Settings";
|
||||
import { SilenceFormStore } from "Stores/SilenceFormStore";
|
||||
@@ -52,6 +54,8 @@ const AlertGrid: FC<{
|
||||
[windowWidth, bodyWidth] // eslint-disable-line react-hooks/exhaustive-deps
|
||||
);
|
||||
|
||||
useHotkeys("alt+space", alertStore.status.togglePause);
|
||||
|
||||
return useObserver(() => (
|
||||
<React.Fragment>
|
||||
<div ref={ref as Ref<HTMLDivElement>} />
|
||||
|
||||
@@ -6,7 +6,7 @@ exports[`<FetchIndicator /> matches snapshot when fetch is in progress 1`] = `
|
||||
focusable=\\"false\\"
|
||||
data-prefix=\\"fas\\"
|
||||
data-icon=\\"circle-notch\\"
|
||||
class=\\"svg-inline--fa fa-circle-notch fa-w-16 fa-spin fa-lg mx-1 text-muted\\"
|
||||
class=\\"svg-inline--fa fa-circle-notch fa-w-16 fa-spin fa-lg mx-1 text-muted \\"
|
||||
role=\\"img\\"
|
||||
xmlns=\\"http://www.w3.org/2000/svg\\"
|
||||
viewbox=\\"0 0 512 512\\"
|
||||
@@ -26,7 +26,7 @@ exports[`<FetchIndicator /> matches snapshot when idle 1`] = `
|
||||
focusable=\\"false\\"
|
||||
data-prefix=\\"fas\\"
|
||||
data-icon=\\"circle-notch\\"
|
||||
class=\\"svg-inline--fa fa-circle-notch fa-w-16 fa-lg mx-1 text-muted\\"
|
||||
class=\\"svg-inline--fa fa-circle-notch fa-w-16 fa-lg mx-1 text-muted \\"
|
||||
role=\\"img\\"
|
||||
xmlns=\\"http://www.w3.org/2000/svg\\"
|
||||
viewbox=\\"0 0 512 512\\"
|
||||
@@ -42,21 +42,23 @@ exports[`<FetchIndicator /> matches snapshot when idle 1`] = `
|
||||
|
||||
exports[`<FetchIndicator /> matches snapshot when paused 1`] = `
|
||||
"
|
||||
<svg aria-hidden=\\"true\\"
|
||||
focusable=\\"false\\"
|
||||
data-prefix=\\"far\\"
|
||||
data-icon=\\"pause-circle\\"
|
||||
class=\\"svg-inline--fa fa-pause-circle fa-w-16 fa-lg mx-1 text-muted\\"
|
||||
role=\\"img\\"
|
||||
xmlns=\\"http://www.w3.org/2000/svg\\"
|
||||
viewbox=\\"0 0 512 512\\"
|
||||
style=\\"opacity: 1;\\"
|
||||
>
|
||||
<path fill=\\"currentColor\\"
|
||||
d=\\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm96-280v160c0 8.8-7.2 16-16 16h-48c-8.8 0-16-7.2-16-16V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16zm-112 0v160c0 8.8-7.2 16-16 16h-48c-8.8 0-16-7.2-16-16V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16z\\"
|
||||
<div class=\\" tooltip-trigger\\">
|
||||
<svg aria-hidden=\\"true\\"
|
||||
focusable=\\"false\\"
|
||||
data-prefix=\\"far\\"
|
||||
data-icon=\\"pause-circle\\"
|
||||
class=\\"svg-inline--fa fa-pause-circle fa-w-16 fa-lg mx-1 text-muted cursor-pointer\\"
|
||||
role=\\"img\\"
|
||||
xmlns=\\"http://www.w3.org/2000/svg\\"
|
||||
viewbox=\\"0 0 512 512\\"
|
||||
style=\\"opacity: 1;\\"
|
||||
>
|
||||
</path>
|
||||
</svg>
|
||||
<path fill=\\"currentColor\\"
|
||||
d=\\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm96-280v160c0 8.8-7.2 16-16 16h-48c-8.8 0-16-7.2-16-16V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16zm-112 0v160c0 8.8-7.2 16-16 16h-48c-8.8 0-16-7.2-16-16V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16z\\"
|
||||
>
|
||||
</path>
|
||||
</svg>
|
||||
</div>
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -66,7 +68,7 @@ exports[`<FetchIndicator /> matches snapshot when response is processed 1`] = `
|
||||
focusable=\\"false\\"
|
||||
data-prefix=\\"fas\\"
|
||||
data-icon=\\"circle-notch\\"
|
||||
class=\\"svg-inline--fa fa-circle-notch fa-w-16 fa-spin fa-lg mx-1 text-success\\"
|
||||
class=\\"svg-inline--fa fa-circle-notch fa-w-16 fa-spin fa-lg mx-1 text-success \\"
|
||||
role=\\"img\\"
|
||||
xmlns=\\"http://www.w3.org/2000/svg\\"
|
||||
viewbox=\\"0 0 512 512\\"
|
||||
|
||||
@@ -8,19 +8,22 @@ import { faCircleNotch } from "@fortawesome/free-solid-svg-icons/faCircleNotch";
|
||||
import { faPauseCircle } from "@fortawesome/free-regular-svg-icons/faPauseCircle";
|
||||
|
||||
import { AlertStore, AlertStoreStatuses } from "Stores/AlertStore";
|
||||
import { TooltipWrapper } from "Components/TooltipWrapper";
|
||||
|
||||
const FetchIcon: FC<{
|
||||
icon: IconDefinition;
|
||||
color?: string;
|
||||
visible?: boolean;
|
||||
spin?: boolean;
|
||||
}> = ({ icon, color = "muted", visible = true, spin = false }) => (
|
||||
onClick?: () => void;
|
||||
}> = ({ icon, color = "muted", visible = true, spin = false, onClick }) => (
|
||||
<FontAwesomeIcon
|
||||
style={{ opacity: visible ? 1 : 0 }}
|
||||
className={`mx-1 text-${color}`}
|
||||
className={`mx-1 text-${color} ${onClick ? "cursor-pointer" : ""}`}
|
||||
size="lg"
|
||||
icon={icon}
|
||||
spin={spin}
|
||||
onClick={onClick}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -29,7 +32,9 @@ const FetchIndicator: FC<{
|
||||
}> = ({ alertStore }) => {
|
||||
return useObserver(() =>
|
||||
alertStore.status.paused ? (
|
||||
<FetchIcon icon={faPauseCircle} />
|
||||
<TooltipWrapper title="Updates are paused, click to resume">
|
||||
<FetchIcon icon={faPauseCircle} onClick={alertStore.status.resume} />
|
||||
</TooltipWrapper>
|
||||
) : alertStore.status.value.toString() ===
|
||||
AlertStoreStatuses.Fetching.toString() ? (
|
||||
<FetchIcon
|
||||
|
||||
@@ -144,6 +144,15 @@ describe("AlertStore.status", () => {
|
||||
expect(store.status.value).toEqual(AlertStoreStatuses.Idle);
|
||||
expect(store.status.error).toBeNull();
|
||||
});
|
||||
|
||||
it("togglePause() toggles pause state", () => {
|
||||
const store = new AlertStore([]);
|
||||
expect(store.status.paused).toBe(false);
|
||||
store.status.togglePause();
|
||||
expect(store.status.paused).toBe(true);
|
||||
store.status.togglePause();
|
||||
expect(store.status.paused).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AlertStore.filters", () => {
|
||||
|
||||
@@ -343,6 +343,9 @@ class AlertStore {
|
||||
resume() {
|
||||
this.paused = false;
|
||||
},
|
||||
togglePause() {
|
||||
this.paused = !this.paused;
|
||||
},
|
||||
},
|
||||
{
|
||||
setIdle: action,
|
||||
@@ -351,6 +354,7 @@ class AlertStore {
|
||||
setFailure: action,
|
||||
pause: action.bound,
|
||||
resume: action.bound,
|
||||
togglePause: action.bound,
|
||||
},
|
||||
{ name: "Store status" }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user