forked from parseablehq/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.ts
53 lines (46 loc) · 1.37 KB
/
dashboard.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Axios } from './axios';
import {
CREATE_DASHBOARDS_URL,
DELETE_DASHBOARDS_URL,
LIST_DASHBOARDS,
LOG_QUERY_URL,
UPDATE_DASHBOARDS_URL,
} from './constants';
import timeRangeUtils from '@/utils/timeRangeUtils';
import _ from 'lodash';
import {
CreateDashboardType,
Dashboard,
ImportDashboardType,
TileQuery,
TileQueryResponse,
UpdateDashboardType,
} from '@/@types/parseable/api/dashboards';
const { optimizeEndTime } = timeRangeUtils;
export const getDashboards = () => {
return Axios().get<Dashboard[]>(LIST_DASHBOARDS);
};
export const putDashboard = (dashboardId: string, dashboard: UpdateDashboardType) => {
return Axios().put(UPDATE_DASHBOARDS_URL(dashboardId), dashboard);
};
export const postDashboard = (dashboard: CreateDashboardType | ImportDashboardType) => {
return Axios().post(CREATE_DASHBOARDS_URL, { ...dashboard });
};
export const removeDashboard = (dashboardId: string) => {
return Axios().delete(DELETE_DASHBOARDS_URL(dashboardId));
};
// using just for the dashboard tile now
// refactor once the fields are included in the /query in the response
export const getQueryData = (opts?: TileQuery) => {
if (_.isEmpty(opts)) throw 'Invalid Arguments';
const { query, startTime, endTime } = opts;
return Axios().post<TileQueryResponse>(
LOG_QUERY_URL({ fields: true }),
{
query,
startTime,
endTime: optimizeEndTime(endTime),
},
{},
);
};