Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

[Bug fix] Use default max size to call getAll ES API #224

Merged
merged 5 commits into from
Nov 26, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kibana-reports/public/components/main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function Main(props) {

const pagination = {
initialPageSize: 10,
pageSizeOptions: [8, 10, 13],
pageSizeOptions: [5, 10, 20],
};

useEffect(() => {
Expand Down
30 changes: 16 additions & 14 deletions kibana-reports/server/backend/opendistro-es-reports-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ export default function (Client: any, config: any, components: any) {
esReports.getReports = clientAction({
url: {
fmt: `${ES_REPORTS_API.LIST_REPORT_INSTANCES}`,
//TODO: wrong format error thrown even required = false, need to figure it out the correct setting to make it truly optional
// req: {
// fromIndex: {
// type: 'string',
// required: false,
// },
// },
params: {
fromIndex: {
type: 'number',
},
maxItems: {
type: 'number',
},
},
},
method: 'GET',
});
Expand Down Expand Up @@ -128,13 +129,14 @@ export default function (Client: any, config: any, components: any) {
esReports.getReportDefinitions = clientAction({
url: {
fmt: `${ES_REPORTS_API.LIST_REPORT_DEFINITIONS}`,
//TODO: wrong format error thrown even required = false, need to figure it out the correct setting to make it truly optional
// req: {
// fromIndex: {
// type: 'string',
// required: false,
// },
// },
params: {
fromIndex: {
type: 'number',
},
maxItems: {
type: 'number',
},
},
},
method: 'GET',
});
Expand Down
18 changes: 7 additions & 11 deletions kibana-reports/server/routes/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { API_PREFIX } from '../../common';
import { createReport } from './lib/createReport';
import { reportSchema } from '../model';
import { errorResponse } from './utils/helpers';
import { DELIVERY_TYPE } from './utils/constants';
import { DEFAULT_MAX_SIZE, DELIVERY_TYPE } from './utils/constants';
import {
backendToUiReport,
backendToUiReportsList,
Expand Down Expand Up @@ -206,10 +206,8 @@ export default function (router: IRouter) {
path: `${API_PREFIX}/reports`,
validate: {
query: schema.object({
size: schema.maybe(schema.string()),
sortField: schema.maybe(schema.string()),
sortDirection: schema.maybe(schema.string()),
fromIndex: schema.maybe(schema.string()),
fromIndex: schema.maybe(schema.number()),
maxItems: schema.maybe(schema.number()),
}),
},
},
Expand All @@ -218,23 +216,21 @@ export default function (router: IRouter) {
request,
response
): Promise<IKibanaResponse<any | ResponseError>> => {
const { fromIndex } = request.query as {
size: string;
sortField: string;
sortDirection: string;
fromIndex: string;
const { fromIndex, maxItems } = request.query as {
fromIndex: number;
maxItems: number;
};

try {
// @ts-ignore
const esReportsClient: ILegacyScopedClusterClient = context.reporting_plugin.esReportsClient.asScoped(
request
);

const esResp = await esReportsClient.callAsCurrentUser(
'es_reports.getReports',
{
fromIndex: fromIndex,
maxItems: maxItems || DEFAULT_MAX_SIZE,
}
);

Expand Down
16 changes: 7 additions & 9 deletions kibana-reports/server/routes/reportDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
backendToUiReportDefinitionsList,
} from './utils/converters/backendToUi';
import { updateReportDefinition } from './lib/updateReportDefinition';
import { DEFAULT_MAX_SIZE } from './utils/constants';

export default function (router: IRouter) {
// Create report Definition
Expand Down Expand Up @@ -137,10 +138,8 @@ export default function (router: IRouter) {
path: `${API_PREFIX}/reportDefinitions`,
validate: {
query: schema.object({
size: schema.maybe(schema.string()),
sortField: schema.maybe(schema.string()),
sortDirection: schema.maybe(schema.string()),
fromIndex: schema.maybe(schema.string()),
fromIndex: schema.maybe(schema.number()),
maxItems: schema.maybe(schema.number()),
}),
},
},
Expand All @@ -149,11 +148,9 @@ export default function (router: IRouter) {
request,
response
): Promise<IKibanaResponse<any | ResponseError>> => {
const { fromIndex } = request.query as {
size: string;
sortField: string;
sortDirection: string;
fromIndex: string;
const { fromIndex, maxItems } = request.query as {
fromIndex: number;
maxItems: number;
};

try {
Expand All @@ -166,6 +163,7 @@ export default function (router: IRouter) {
'es_reports.getReportDefinitions',
{
fromIndex: fromIndex,
maxItems: maxItems || DEFAULT_MAX_SIZE,
}
);

Expand Down