Skip to content

Commit d56fa32

Browse files
authored
Build update event does not respect selected project #256 (#169)
closes Visual-Regression-Tracker/Visual-Regression-Tracker#256
1 parent 0a5ca37 commit d56fa32

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/contexts/socket.context.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
deleteTestRun,
1515
} from "./testRun.context";
1616
import { API_URL } from "../_config/env.config";
17+
import { useProjectState } from "./project.context";
1718

1819
interface IConnectAction {
1920
type: "connect";
@@ -53,6 +54,7 @@ function socketReducer(state: State, action: IAction): State {
5354
function SocketProvider({ children }: SocketProviderProps) {
5455
const [state, dispatch] = React.useReducer(socketReducer, initialState);
5556
const { selectedBuild } = useBuildState();
57+
const { selectedProjectId } = useProjectState();
5658
const testRunDispatch = useTestRunDispatch();
5759
const buildDispatch = useBuildDispatch();
5860

@@ -65,11 +67,16 @@ function SocketProvider({ children }: SocketProviderProps) {
6567
state.socket.removeAllListeners();
6668

6769
state.socket.on("build_created", function (build: Build) {
68-
addBuild(buildDispatch, build);
70+
if (build.projectId === selectedProjectId) {
71+
addBuild(buildDispatch, build);
72+
}
6973
});
7074

7175
state.socket.on("build_updated", function (builds: Array<Build>) {
72-
updateBuild(buildDispatch, builds);
76+
updateBuild(
77+
buildDispatch,
78+
builds.filter((build) => build.projectId === selectedProjectId)
79+
);
7380
});
7481

7582
state.socket.on("testRun_created", function (testRuns: Array<TestRun>) {
@@ -104,7 +111,13 @@ function SocketProvider({ children }: SocketProviderProps) {
104111
);
105112
});
106113
}
107-
}, [state.socket, selectedBuild, buildDispatch, testRunDispatch]);
114+
}, [
115+
state.socket,
116+
selectedBuild,
117+
selectedProjectId,
118+
buildDispatch,
119+
testRunDispatch,
120+
]);
108121

109122
return (
110123
<SocketStateContext.Provider value={state}>

src/types/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface Build {
55
id: string;
66
ciBuildId: string;
77
number: number;
8+
projectId: string;
89
projectName: string;
910
branchName: string;
1011
status: BuildStatus;

0 commit comments

Comments
 (0)