mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -51,12 +51,13 @@ type User struct {
|
||||
type GetParams struct {
|
||||
url string
|
||||
user User
|
||||
page string
|
||||
}
|
||||
|
||||
func (c TestContext) Get(params GetParams) *http.Response {
|
||||
c.t.Helper()
|
||||
|
||||
resp, err := http.Get(c.getURL(params.url, params.user))
|
||||
fmtUrl := fmt.Sprintf("%s?page=%s", params.url, params.page)
|
||||
resp, err := http.Get(c.getURL(fmtUrl, params.user))
|
||||
require.NoError(c.t, err)
|
||||
|
||||
return resp
|
||||
|
||||
@@ -42,17 +42,18 @@ func TestIntegrationReadCorrelation(t *testing.T) {
|
||||
res := ctx.Get(GetParams{
|
||||
url: "/api/datasources/correlations",
|
||||
user: adminUser,
|
||||
page: "0",
|
||||
})
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
|
||||
responseBody, err := io.ReadAll(res.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
var response []correlations.Correlation
|
||||
var response correlations.GetCorrelationsResponseBody
|
||||
err = json.Unmarshal(responseBody, &response)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, response, 0)
|
||||
require.Len(t, response.Correlations, 0)
|
||||
|
||||
require.NoError(t, res.Body.Close())
|
||||
})
|
||||
@@ -147,12 +148,12 @@ func TestIntegrationReadCorrelation(t *testing.T) {
|
||||
responseBody, err := io.ReadAll(res.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
var response []correlations.Correlation
|
||||
var response correlations.GetCorrelationsResponseBody
|
||||
err = json.Unmarshal(responseBody, &response)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, response, 1)
|
||||
require.EqualValues(t, correlation, response[0])
|
||||
require.Len(t, response.Correlations, 1)
|
||||
require.EqualValues(t, correlation, response.Correlations[0])
|
||||
|
||||
require.NoError(t, res.Body.Close())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user