Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pagination for Deployments #532

Merged
merged 3 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions pkg/app/api/api/web_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ func (a *WebAPI) ListDeployments(ctx context.Context, req *webservice.ListDeploy
if err != nil {
return nil, err
}
// TODO: Support pagination for Deployment list
orders := []datastore.Order{
{
Field: "UpdatedAt",
Expand Down Expand Up @@ -539,11 +538,19 @@ func (a *WebAPI) ListDeployments(ctx context.Context, req *webservice.ListDeploy
Value: o.EnvIds[0],
})
}
if o.MaxUpdatedAt != 0 {
filters = append(filters, datastore.ListFilter{
Field: "UpdatedAt",
Operator: "<",
Value: o.MaxUpdatedAt,
})
}
}

deployments, err := a.deploymentStore.ListDeployments(ctx, datastore.ListOptions{
Filters: filters,
Orders: orders,
Filters: filters,
Orders: orders,
PageSize: int(req.PageSize),
})
if err != nil {
a.logger.Error("failed to get deployments", zap.Error(err))
Expand Down
3 changes: 3 additions & 0 deletions pkg/app/api/service/webservice/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ message ListDeploymentsRequest {
repeated model.ApplicationKind kinds = 2;
repeated string application_ids = 3;
repeated string env_ids = 4;
// Returns the one before the specified time.
int64 max_updated_at = 5;
}
Options options = 1;
int32 page_size = 2;
}

message ListDeploymentsResponse {
Expand Down
2 changes: 2 additions & 0 deletions pkg/app/web/src/api/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const getDeployment = ({

export const getDeployments = ({
options,
pageSize,
}: ListDeploymentsRequest.AsObject): Promise<
ListDeploymentsResponse.AsObject
> => {
Expand All @@ -31,6 +32,7 @@ export const getDeployments = ({
opts.setKindsList(options.kindsList);
opts.setStatusesList(options.statusesList);
req.setOptions(opts);
req.setPageSize(pageSize);
}
return apiRequest(req, apiClient.listDeployments);
};
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/web/src/modules/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ export const fetchDeployments = createAsyncThunk<
kindsList: ApplicationKind[];
applicationIdsList: string[];
envIdsList: string[];
maxUpdatedAt: number;
}
>("deployments/fetchList", async (options) => {
const { deploymentsList } = await deploymentsApi.getDeployments({ options });
const { deploymentsList } = await deploymentsApi.getDeployments({ options, pageSize: ITEMS_PER_PAGE });
return (deploymentsList as Deployment[]) || [];
});

Expand Down