Skip to content

Commit 781b203

Browse files
Fix pagination boundary edge case for transfers, deployments, and executions
Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
1 parent d3ec8bd commit 781b203

4 files changed

Lines changed: 62 additions & 34 deletions

File tree

src/sources/DeploymentSource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class DeploymentSourceUtils {
6161
class DeploymentSource {
6262
async getDeployments(options?: {
6363
skipLog?: boolean;
64+
quietError?: boolean;
6465
limit?: number;
6566
marker?: string | null;
6667
}): Promise<DeploymentItem[]> {
@@ -75,6 +76,7 @@ class DeploymentSource {
7576
const response = await Api.send({
7677
url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/deployments${queryString}`,
7778
skipLog: options?.skipLog,
79+
quietError: options?.quietError,
7880
});
7981
const deployments = response.data.deployments;
8082
if (options?.limit === undefined) {

src/sources/TransferSource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class TransferSource {
161161
options?: {
162162
limit?: number;
163163
marker?: string | null;
164+
quietError?: boolean;
164165
},
165166
): Promise<Execution[]> {
166167
const params: string[] = [];
@@ -173,6 +174,7 @@ class TransferSource {
173174
const queryString = params.length > 0 ? `?${params.join("&")}` : "";
174175
const response = await Api.send({
175176
url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/transfers/${transferId}/executions${queryString}`,
177+
quietError: options?.quietError,
176178
});
177179
const executions: Execution[] = response.data.executions;
178180
return TransferSourceUtils.filterDeletedExecutions(executions);

src/stores/DeploymentStore.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,28 @@ class DeploymentStore {
7575
this.loading = true;
7676
}
7777

78+
const marker = this.deploymentPageMarkers[this.deploymentsPage - 1] ?? null;
79+
const isPaginationRequest = marker !== null;
80+
7881
try {
79-
const marker =
80-
this.deploymentPageMarkers[this.deploymentsPage - 1] ?? null;
8182
const raw = await DeploymentSource.getDeployments({
8283
skipLog: options?.skipLog,
83-
limit: this.deploymentsItemsPerPage + 1,
84+
quietError: isPaginationRequest,
85+
limit: this.deploymentsItemsPerPage,
8486
marker,
8587
});
86-
const hasNextPage = raw.length > this.deploymentsItemsPerPage;
87-
const deployments = hasNextPage
88-
? raw.slice(0, this.deploymentsItemsPerPage)
89-
: raw;
90-
const nextMarker =
91-
deployments.length > 0 ? deployments[deployments.length - 1].id : null;
88+
if (isPaginationRequest && raw.length === 0) {
89+
runInAction(() => {
90+
this.deploymentsHasNextPage = false;
91+
this.deploymentsPage = Math.max(1, this.deploymentsPage - 1);
92+
this.loading = false;
93+
});
94+
return;
95+
}
96+
const hasNextPage = raw.length === this.deploymentsItemsPerPage;
97+
const nextMarker = raw.length > 0 ? raw[raw.length - 1].id : null;
9298
runInAction(() => {
93-
this.deployments = deployments;
99+
this.deployments = raw;
94100
this.deploymentsHasNextPage = hasNextPage;
95101
if (nextMarker !== null) {
96102
this.deploymentPageMarkers[this.deploymentsPage] = nextMarker;
@@ -99,6 +105,14 @@ class DeploymentStore {
99105
this.deploymentsLoaded = true;
100106
});
101107
} catch (ex) {
108+
if (isPaginationRequest) {
109+
runInAction(() => {
110+
this.deploymentsHasNextPage = false;
111+
this.deploymentsPage = Math.max(1, this.deploymentsPage - 1);
112+
this.loading = false;
113+
});
114+
return;
115+
}
102116
runInAction(() => {
103117
this.loading = false;
104118
});

src/stores/TransferStore.ts

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,12 @@ class TransferStore {
117117

118118
try {
119119
const raw = await TransferSource.getExecutions(transferId, {
120-
limit: this.executionsPageSize + 1,
120+
limit: this.executionsPageSize,
121121
});
122-
const hasOlderPage = raw.length > this.executionsPageSize;
123-
const executions = hasOlderPage
124-
? raw.slice(0, this.executionsPageSize)
125-
: raw;
126-
TransferSourceUtils.sortExecutions(executions);
122+
const hasOlderPage = raw.length === this.executionsPageSize;
123+
TransferSourceUtils.sortExecutions(raw);
127124
runInAction(() => {
128-
this.executionsList = executions;
125+
this.executionsList = raw;
129126
this.executionsHasOlderPage = hasOlderPage;
130127
this.executionsLoading = false;
131128
});
@@ -152,21 +149,20 @@ class TransferStore {
152149

153150
try {
154151
const raw = await TransferSource.getExecutions(transferId, {
155-
limit: this.executionsPageSize + 1,
152+
limit: this.executionsPageSize,
156153
marker,
154+
quietError: true,
157155
});
158-
const hasOlderPage = raw.length > this.executionsPageSize;
159-
const executions = hasOlderPage
160-
? raw.slice(0, this.executionsPageSize)
161-
: raw;
162-
TransferSourceUtils.sortExecutions(executions);
156+
const hasOlderPage = raw.length === this.executionsPageSize;
157+
TransferSourceUtils.sortExecutions(raw);
163158
runInAction(() => {
164-
this.executionsList = [...executions, ...this.executionsList];
159+
this.executionsList = [...raw, ...this.executionsList];
165160
this.executionsHasOlderPage = hasOlderPage;
166161
this.executionsLoading = false;
167162
});
168163
} catch (err) {
169164
runInAction(() => {
165+
this.executionsHasOlderPage = false;
170166
this.executionsLoading = false;
171167
});
172168
console.error(err);
@@ -197,21 +193,35 @@ class TransferStore {
197193
this.loading = true;
198194
}
199195

196+
const marker = this.transferPageMarkers[this.transfersPage - 1] ?? null;
197+
const isPaginationRequest = marker !== null;
198+
200199
try {
201-
const marker = this.transferPageMarkers[this.transfersPage - 1] ?? null;
202200
const raw = await TransferSource.getTransfers({
203201
skipLog: options?.skipLog,
204-
quietError: options?.quietError,
205-
limit: this.transfersItemsPerPage + 1,
202+
quietError: options?.quietError || isPaginationRequest,
203+
limit: this.transfersItemsPerPage,
206204
marker,
207205
});
208-
const hasNextPage = raw.length > this.transfersItemsPerPage;
209-
const transfers = hasNextPage
210-
? raw.slice(0, this.transfersItemsPerPage)
211-
: raw;
212-
const nextMarker =
213-
transfers.length > 0 ? transfers[transfers.length - 1].id : null;
214-
this.getTransfersSuccess(transfers, hasNextPage, nextMarker);
206+
if (isPaginationRequest && raw.length === 0) {
207+
runInAction(() => {
208+
this.transfersHasNextPage = false;
209+
this.transfersPage = Math.max(1, this.transfersPage - 1);
210+
});
211+
return;
212+
}
213+
const hasNextPage = raw.length === this.transfersItemsPerPage;
214+
const nextMarker = raw.length > 0 ? raw[raw.length - 1].id : null;
215+
this.getTransfersSuccess(raw, hasNextPage, nextMarker);
216+
} catch (err) {
217+
if (isPaginationRequest) {
218+
runInAction(() => {
219+
this.transfersHasNextPage = false;
220+
this.transfersPage = Math.max(1, this.transfersPage - 1);
221+
});
222+
return;
223+
}
224+
throw err;
215225
} finally {
216226
this.getTransfersDone();
217227
}

0 commit comments

Comments
 (0)