Skip to content

Commit 8869091

Browse files
committed
Revert "TestRuns. Add pagination"
This reverts commit 7d4fe0a.
1 parent 7d4fe0a commit 8869091

File tree

3 files changed

+22
-63
lines changed

3 files changed

+22
-63
lines changed

src/contexts/testRun.context.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { PaginatedData, TestRun } from "../types";
2+
import { TestRun } from "../types";
33
import { testRunService } from "../services";
44

55
interface IRequestAction {
@@ -9,7 +9,7 @@ interface IRequestAction {
99

1010
interface IGetAction {
1111
type: "get";
12-
payload: PaginatedData<TestRun>;
12+
payload: TestRun[];
1313
}
1414

1515
interface ISelectAction {
@@ -63,9 +63,6 @@ type State = {
6363
selectedTestRunId: string | undefined;
6464
selectedTestRunIndex: number | undefined;
6565
testRuns: TestRun[];
66-
total: number;
67-
take: number;
68-
skip: number;
6966
loading: boolean;
7067
};
7168

@@ -80,9 +77,6 @@ const initialState: State = {
8077
selectedTestRunId: undefined,
8178
selectedTestRunIndex: undefined,
8279
testRuns: [],
83-
take: 10,
84-
skip: 0,
85-
total: 0,
8680
loading: false,
8781
};
8882

@@ -107,13 +101,9 @@ function testRunReducer(state: State, action: IAction): State {
107101
loading: true,
108102
};
109103
case "get":
110-
const { data, take, skip, total } = action.payload;
111104
return {
112105
...state,
113-
testRuns: data,
114-
take,
115-
skip,
116-
total,
106+
testRuns: action.payload,
117107
loading: false,
118108
};
119109
case "delete":
@@ -173,18 +163,12 @@ function useTestRunDispatch() {
173163
return context;
174164
}
175165

176-
async function getTestRunList(
177-
dispatch: Dispatch,
178-
buildId: string,
179-
page: number
180-
): Promise<void> {
166+
async function getTestRunList(dispatch: Dispatch, buildId: string) {
181167
dispatch({ type: "request" });
182168

183-
return testRunService
184-
.getList(buildId, initialState.take, initialState.take * (page - 1))
185-
.then((response) => {
186-
dispatch({ type: "get", payload: response });
187-
});
169+
return testRunService.getList(buildId).then((items) => {
170+
dispatch({ type: "get", payload: items });
171+
});
188172
}
189173

190174
async function deleteTestRun(dispatch: Dispatch, id: string) {

src/pages/ProjectPage.tsx

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ const ProjectPage = () => {
5858
const buildDispatch = useBuildDispatch();
5959
const { selectedProjectId } = useProjectState();
6060
const projectDispatch = useProjectDispatch();
61-
const {
62-
testRuns,
63-
selectedTestRunIndex,
64-
total: testRunTotal,
65-
take: testRunTake,
66-
} = useTestRunState();
61+
const { testRuns, selectedTestRunIndex } = useTestRunState();
6762
const testRunDispatch = useTestRunDispatch();
6863

6964
// filter
@@ -86,6 +81,16 @@ const ProjectPage = () => {
8681
}
8782
}, [projectId, projectDispatch]);
8883

84+
useEffect(() => {
85+
if (selectedBuildId) {
86+
getTestRunList(testRunDispatch, selectedBuildId).catch((err) =>
87+
enqueueSnackbar(err, {
88+
variant: "error",
89+
})
90+
);
91+
}
92+
}, [selectedBuildId, testRunDispatch, enqueueSnackbar]);
93+
8994
useEffect(() => {
9095
if (queryParams.buildId) {
9196
selectBuild(buildDispatch, queryParams.buildId);
@@ -112,18 +117,6 @@ const ProjectPage = () => {
112117
);
113118
}, [query, os, device, browser, viewport, testStatus, testRuns]);
114119

115-
const getTestRunListCalback: any = React.useCallback(
116-
(page: number) =>
117-
selectedBuildId &&
118-
getTestRunList(testRunDispatch, selectedBuildId, page).catch(
119-
(err: string) =>
120-
enqueueSnackbar(err, {
121-
variant: "error",
122-
})
123-
),
124-
[testRunDispatch, enqueueSnackbar, selectedBuildId]
125-
);
126-
127120
const getBuildListCalback: any = React.useCallback(
128121
(page: number) =>
129122
selectedProjectId &&
@@ -136,10 +129,6 @@ const ProjectPage = () => {
136129
[buildDispatch, enqueueSnackbar, selectedProjectId]
137130
);
138131

139-
React.useEffect(() => {
140-
getTestRunListCalback(1);
141-
}, [getTestRunListCalback]);
142-
143132
React.useEffect(() => {
144133
getBuildListCalback(1);
145134
}, [getBuildListCalback]);
@@ -173,19 +162,9 @@ const ProjectPage = () => {
173162
viewportState={[viewport, setViewport]}
174163
testStatusState={[testStatus, setTestStatus]}
175164
/>
176-
<Box height="70%" my={0.5}>
165+
<Box height="75%">
177166
<TestRunList items={filteredTestRuns} />
178167
</Box>
179-
<Grid container justify="center">
180-
<Grid item>
181-
<Pagination
182-
size="small"
183-
defaultPage={1}
184-
count={Math.ceil(testRunTotal / testRunTake)}
185-
onChange={(event, page) => getTestRunListCalback(page)}
186-
/>
187-
</Grid>
188-
</Grid>
189168

190169
{selectedTestRunIndex !== undefined && testRuns[selectedTestRunIndex] && (
191170
<Dialog open={true} fullScreen className={classes.modal}>

src/services/testRun.service.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import { PaginatedData, TestRun } from "../types";
1+
import { TestRun } from "../types";
22
import { handleResponse, authHeader } from "../_helpers/service.helpers";
33
import { API_URL } from "../_config/env.config";
44
import { IgnoreArea } from "../types/ignoreArea";
55

66
const ENDPOINT_URL = "/test-runs";
77

8-
async function getList(
9-
buildId: string,
10-
take: number,
11-
skip: number
12-
): Promise<PaginatedData<TestRun>> {
8+
async function getList(buildId: string): Promise<TestRun[]> {
139
const requestOptions = {
1410
method: "GET",
1511
headers: authHeader(),
1612
};
1713

1814
return fetch(
19-
`${API_URL}${ENDPOINT_URL}?buildId=${buildId}&take=${take}&skip=${skip}`,
15+
`${API_URL}${ENDPOINT_URL}?buildId=${buildId}`,
2016
requestOptions
2117
).then(handleResponse);
2218
}

0 commit comments

Comments
 (0)