Correlations: Create paginated API (#65241)
* Add pagination params and apply to sql * Create getCorrelationsResponse that returns metadata * Set up pagination, change correlations fetch to only get source datasource correlations * Move correlations from root to pane, only fetch correlations for one datasource when initialized or datasource is changed * Fix tests * Fix remaining tests * Use functional component to handle state * Remove unneeded mocks, fix tests * Change perPage to limit * Fix Go Tests * Fix linter * Remove parameter * Account for mixed datasources * Delete unused hook * add source UID filter to API, start backing out front end hook changes * add source IDs to API, use when loading or changing datasource * Fix prettier * Mock correlations response * Get correlations for all datasources in mixed scenario * Add documentation for new parameters * Attempt to fix swagger * Fix correlations page * add swagger and openapi docs * Add mocks to failing test * Change API for consistency, remove extra hooks and unused function * Add max to limit and re-gen api docs * Move the page to the previous page if deleting all the rows on the page * Only fetch if remove does not have value * Change page to a reference hook * Fix documentation, a test and some logic thinking page could be 0
This commit is contained in:
@@ -76,7 +76,7 @@ type CreateCorrelationParams struct {
|
||||
SourceUID string `json:"sourceUID"`
|
||||
}
|
||||
|
||||
//swagger:response createCorrelationResponse
|
||||
// swagger:response createCorrelationResponse
|
||||
type CreateCorrelationResponse struct {
|
||||
// in: body
|
||||
Body CreateCorrelationResponseBody `json:"body"`
|
||||
@@ -192,7 +192,7 @@ type UpdateCorrelationParams struct {
|
||||
Body UpdateCorrelationCommand `json:"body"`
|
||||
}
|
||||
|
||||
//swagger:response updateCorrelationResponse
|
||||
// swagger:response updateCorrelationResponse
|
||||
type UpdateCorrelationResponse struct {
|
||||
// in: body
|
||||
Body UpdateCorrelationResponseBody `json:"body"`
|
||||
@@ -282,7 +282,7 @@ type GetCorrelationsBySourceUIDParams struct {
|
||||
DatasourceUID string `json:"sourceUID"`
|
||||
}
|
||||
|
||||
//swagger:response getCorrelationsBySourceUIDResponse
|
||||
// swagger:response getCorrelationsBySourceUIDResponse
|
||||
type GetCorrelationsBySourceUIDResponse struct {
|
||||
// in: body
|
||||
Body []Correlation `json:"body"`
|
||||
@@ -298,8 +298,25 @@ type GetCorrelationsBySourceUIDResponse struct {
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (s *CorrelationsService) getCorrelationsHandler(c *contextmodel.ReqContext) response.Response {
|
||||
limit := c.QueryInt64("limit")
|
||||
if limit <= 0 {
|
||||
limit = 100
|
||||
} else if limit > 1000 {
|
||||
limit = 1000
|
||||
}
|
||||
|
||||
page := c.QueryInt64("page")
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
sourceUIDs := c.QueryStrings("sourceUID")
|
||||
|
||||
query := GetCorrelationsQuery{
|
||||
OrgId: c.OrgID,
|
||||
OrgId: c.OrgID,
|
||||
Limit: limit,
|
||||
Page: page,
|
||||
SourceUIDs: sourceUIDs,
|
||||
}
|
||||
|
||||
correlations, err := s.getCorrelations(c.Req.Context(), query)
|
||||
@@ -314,6 +331,27 @@ func (s *CorrelationsService) getCorrelationsHandler(c *contextmodel.ReqContext)
|
||||
return response.JSON(http.StatusOK, correlations)
|
||||
}
|
||||
|
||||
// swagger:parameters getCorrelations
|
||||
type GetCorrelationsParams struct {
|
||||
// Limit the maximum number of correlations to return per page
|
||||
// in:query
|
||||
// required:false
|
||||
// default:100
|
||||
// maximum: 1000
|
||||
Limit int64 `json:"limit"`
|
||||
// Page index for starting fetching correlations
|
||||
// in:query
|
||||
// required:false
|
||||
// default:1
|
||||
Page int64 `json:"page"`
|
||||
// Source datasource UID filter to be applied to correlations
|
||||
// in:query
|
||||
// type: array
|
||||
// collectionFormat: multi
|
||||
// required:false
|
||||
SourceUIDs []string `json:"sourceUID"`
|
||||
}
|
||||
|
||||
//swagger:response getCorrelationsResponse
|
||||
type GetCorrelationsResponse struct {
|
||||
// in: body
|
||||
|
||||
Reference in New Issue
Block a user