MCPcopy Create free account
hub / github.com/chartbrew/chartbrew / getChart

Function getChart

client/src/actions/chart.js:12–59  ·  view source on GitHub ↗
(projectId, chartId, password, fromInterval = false)

Source from the content-addressed store, hash-verified

10export const UPDATE_CHART_FIELDS = "UPDATE_CHART_FIELDS";
11
12export function getChart(projectId, chartId, password, fromInterval = false) {
13 return (dispatch, getState) => {
14 // -------------------------------------------
15 // do not get the chart if already loading and if coming from an interval
16 // there is currently a bug with useInterval() and it triggers twice
17 if (fromInterval) {
18 try {
19 const selectedChart = getState().chart.data.find((c) => c.id === chartId);
20 if (selectedChart && selectedChart.loading) {
21 return new Promise((resolve) => resolve());
22 }
23 } catch (e) {
24 // do nothing
25 }
26 }
27 // --------------------------------------------
28
29 const token = cookie.load("brewToken");
30 let url = `${API_HOST}/project/${projectId}/chart/${chartId}`;
31 const method = "GET";
32 const headers = new Headers({
33 "Accept": "application/json",
34 "authorization": `Bearer ${token}`,
35 });
36
37 if (password || !token) {
38 url = `${API_HOST}/chart/${chartId}?password=${password}`;
39 }
40
41 dispatch({ type: FETCH_CHART, chartId });
42 return fetch(url, { method, headers })
43 .then((response) => {
44 if (!response.ok) {
45 dispatch(addError(response.status));
46 return new Promise((resolve, reject) => reject(response.statusText));
47 }
48
49 return response.json();
50 })
51 .then((chart) => {
52 dispatch({ type: FETCH_CHART_SUCCESS, chart });
53 return new Promise(resolve => resolve(chart));
54 })
55 .catch((error) => {
56 return new Promise((resolve, reject) => reject(error));
57 });
58 };
59}
60
61export function getProjectCharts(projectId) {
62 return (dispatch) => {

Callers 3

ChartFunction · 0.90
_onGetChartFunction · 0.90
fetchChartDataFunction · 0.90

Calls 2

addErrorFunction · 0.90
dispatchFunction · 0.50

Tested by

no test coverage detected