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

CSV APIs endpoints for data reports. #50

Merged
merged 7 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"eslint-plugin-react": "^7.12.4",
"jest": "^26.0.1",
"prettier": "2.0.5",
"react-test-renderer": "^16.13.1"
"react-test-renderer": "^16.13.1",
"elastic-builder": "^2.7.1",
"json-2-csv": "^3.7.6"
}
}
160 changes: 80 additions & 80 deletions server/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,104 +15,104 @@

import { schema } from '@kbn/config-schema';

// TODO: needs update when we integrate csv feature
const dataReportSchema = schema.object({
saved_search_id: schema.string(),
time_range: schema.string(),
report_format: schema.oneOf([schema.literal('csv'), schema.literal('xlsx')]),
export const dataReportSchema = schema.object({
saved_search_id: schema.string(),
start: schema.string(),
end: schema.string(),
report_format: schema.oneOf([schema.literal('csv'), schema.literal('xlsx')]),
Comment on lines +19 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the same 2-space indentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use prettier to format the code base. There is also a .prettoerrc config file in the root path of this project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

});

const visualReportSchema = schema.object({
url: schema.uri(),
window_width: schema.number({ defaultValue: 1200 }),
window_height: schema.number({ defaultValue: 800 }),
report_format: schema.oneOf([schema.literal('pdf'), schema.literal('png')]),
url: schema.uri(),
window_width: schema.number({ defaultValue: 1200 }),
window_height: schema.number({ defaultValue: 800 }),
report_format: schema.oneOf([schema.literal('pdf'), schema.literal('png')]),
});

export const scheduleSchema = schema.object({
schedule_type: schema.oneOf([
schema.literal('Now'),
schema.literal('Future Date'),
schema.literal('Recurring'),
schema.literal('Cron Based'),
]),
schedule: schema.any(),
schedule_type: schema.oneOf([
schema.literal('Now'),
schema.literal('Future Date'),
schema.literal('Recurring'),
schema.literal('Cron Based'),
]),
schedule: schema.any(),
});

export const intervalSchema = schema.object({
interval: schema.object({
period: schema.number(),
// Refer to job scheduler SPI https://github.com/opendistro-for-elasticsearch/job-scheduler/blob/b333469c183a15ddbf496a690300cc9e34d937fb/spi/src/main/java/com/amazon/opendistroforelasticsearch/jobscheduler/spi/schedule/IntervalSchedule.java
unit: schema.oneOf([
schema.literal('MINUTES'),
schema.literal('HOURS'),
schema.literal('DAYS'),
]),
// timeStamp
start_time: schema.number(),
}),
interval: schema.object({
period: schema.number(),
// Refer to job scheduler SPI https://github.com/opendistro-for-elasticsearch/job-scheduler/blob/b333469c183a15ddbf496a690300cc9e34d937fb/spi/src/main/java/com/amazon/opendistroforelasticsearch/jobscheduler/spi/schedule/IntervalSchedule.java
unit: schema.oneOf([
schema.literal('MINUTES'),
schema.literal('HOURS'),
schema.literal('DAYS'),
]),
// timeStamp
start_time: schema.number(),
}),
});

export const cronSchema = schema.object({
corn: schema.object({
expression: schema.string(),
time_zone: schema.string(),
}),
corn: schema.object({
expression: schema.string(),
time_zone: schema.string(),
}),
});

export const emailSchema = schema.object({
subject: schema.string(),
body: schema.string(),
has_attachment: schema.boolean({ defaultValue: true }),
recipients: schema.arrayOf(schema.string(), { minSize: 1 }),
subject: schema.string(),
body: schema.string(),
has_attachment: schema.boolean({ defaultValue: true }),
recipients: schema.arrayOf(schema.string(), { minSize: 1 }),
});

export const reportSchema = schema.object({
report_name: schema.string(),
report_source: schema.oneOf([
schema.literal('Dashboard'),
schema.literal('Visualization'),
schema.literal('Saved search'),
]),
report_type: schema.oneOf([
schema.literal('Download'),
schema.literal('Alert'),
schema.literal('Schedule'),
]),
description: schema.string(),
report_params: schema.conditional(
schema.siblingRef('report_source'),
'Saved search',
dataReportSchema,
visualReportSchema
),
report_name: schema.string(),
report_source: schema.oneOf([
schema.literal('Dashboard'),
schema.literal('Visualization'),
schema.literal('Saved search'),
]),
report_type: schema.oneOf([
schema.literal('Download'),
schema.literal('Alert'),
schema.literal('Schedule'),
]),
description: schema.string(),
report_params: schema.conditional(
schema.siblingRef('report_source'),
'Saved search',
dataReportSchema,
visualReportSchema
),

delivery: schema.maybe(
schema.object({
channel: schema.oneOf([
schema.literal('Email'),
schema.literal('Slack'),
schema.literal('Chime'),
schema.literal('Kibana User'),
]),
//TODO: no validation on delivery settings for now, because @kbn/config-schema has no support for more than 2 conditions
delivery_params: schema.any(),
})
),
delivery: schema.maybe(
schema.object({
channel: schema.oneOf([
schema.literal('Email'),
schema.literal('Slack'),
schema.literal('Chime'),
schema.literal('Kibana User'),
]),
//TODO: no validation on delivery settings for now, because @kbn/config-schema has no support for more than 2 conditions
delivery_params: schema.any(),
})
),

trigger: schema.maybe(
schema.object({
trigger_type: schema.oneOf([
schema.literal('Alert'),
schema.literal('Schedule'),
]),
trigger_params: schema.conditional(
schema.siblingRef('trigger_type'),
'Alert',
// TODO: add alerting schema here once we finished the design for alerting integration
schema.any(),
scheduleSchema
),
})
),
trigger: schema.maybe(
schema.object({
trigger_type: schema.oneOf([
schema.literal('Alert'),
schema.literal('Schedule'),
]),
trigger_params: schema.conditional(
schema.siblingRef('trigger_type'),
'Alert',
// TODO: add alerting schema here once we finished the design for alerting integration
schema.any(),
scheduleSchema
),
})
),
});
Loading