Mirror of https://github.com/roostorg/osprey
github.com/roostorg/osprey
1import HTTPUtils, { HTTPResponse } from '../utils/HTTPUtils';
2
3export async function getGraphJson(
4 type: string,
5 names: string[],
6 showLabelUpstream: boolean,
7 showLabelDownstream: boolean
8) {
9 if (type === 'label') {
10 return await getLabelsViewGraphJson(names, showLabelUpstream, showLabelDownstream);
11 } else if (type === 'action') {
12 return await getActionsViewGraphJson(names);
13 }
14 return {
15 errorMessage: 'Cannot formulate request: unrecognized selected feature type.',
16 selectedFeature: names[0],
17 };
18}
19
20async function getActionsViewGraphJson(action_names: Array<string>): Promise<any> {
21 const response: HTTPResponse = await HTTPUtils.post(`/rules_visualizer/actions_view/`, { action_names });
22 const selection = {
23 selectedFeature: action_names[0],
24 selectedFeatureType: 'Action',
25 };
26
27 if (response.ok) {
28 return {
29 ...response.data,
30 ...selection,
31 errorMessage: undefined,
32 };
33 }
34 return {
35 errorMessage: response.error.message,
36 ...selection,
37 };
38}
39
40async function getLabelsViewGraphJson(
41 label_names: Array<string>,
42 showLabelUpstream: boolean,
43 showLabelDownstream: boolean
44): Promise<any> {
45 const response: HTTPResponse = await HTTPUtils.post(`/rules_visualizer/labels_view/`, {
46 label_names,
47 show_upstream: showLabelUpstream,
48 show_downstream: showLabelDownstream,
49 });
50 const selection = {
51 selectedFeature: label_names[0],
52 selectedFeatureType: 'Label',
53 };
54
55 if (response.ok) {
56 return {
57 ...response.data,
58 ...selection,
59 errorMessage: undefined,
60 };
61 }
62 return {
63 errorMessage: response.error.message,
64 ...selection,
65 };
66}