Skip to content

Commit

Permalink
Merge pull request #172 from metrico/dev
Browse files Browse the repository at this point in the history
Weekly update
  • Loading branch information
jacovinus authored Dec 21, 2022
2 parents 83430ad + cd5304c commit f5ee973
Show file tree
Hide file tree
Showing 169 changed files with 3,506 additions and 2,488 deletions.
56 changes: 53 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"papaparse": "^5.3.2",
"prismjs": "^1.27.0",
"react": "^17.0.2",
"react-cookie": "^4.1.1",
"react-custom-scrollbars-2": "^4.4.0",
"react-dom": "^17.0.2",
"react-flot": "^1.3.0",
Expand Down Expand Up @@ -122,8 +123,8 @@
"@types/moment": "^2.13.0",
"@types/papaparse": "^5.3.5",
"@types/react-redux": "^7.1.24",
"@types/tinycolor2": "^1.4.3",
"@types/react-resizable": "^3.0.3",
"@types/tinycolor2": "^1.4.3",
"babel-loader": "^8.2.3",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
Expand All @@ -134,6 +135,7 @@
"file-loader": "^6.2.0",
"html-loader": "^3.1.0",
"html-webpack-plugin": "^5.5.0",
"http-proxy-middleware": "^2.0.6",
"mini-css-extract-plugin": "^2.5.3",
"react-hot-loader": "^4.13.0",
"react-scripts": "^5.0.0",
Expand All @@ -147,7 +149,6 @@
"webpack": "^5.67.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.3",
"webpack-merge": "^5.8.0",
"http-proxy-middleware": "^2.0.6"
"webpack-merge": "^5.8.0"
}
}
2 changes: 1 addition & 1 deletion src/actions/createAlert.js → src/actions/createAlert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import store from '../store/store';

export const createAlert = ( action) => (dispatch) => {
export const createAlert = (action: any) => (dispatch: Function) => {
const notifications = store.getState().notifications
notifications.push({
message: action.message,
Expand Down
138 changes: 69 additions & 69 deletions src/actions/errorHandler.js → src/actions/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
export const errorHandler = (error) => {

const LABELS_URL = "/loki/api/v1/label";
const QUERY_URL = "/loki/api/v1/query_range";

const { request, response } = error;
const url = error?.response?.request?.responseURL


let type = () => {
switch(url) {
case url?.includes(LABELS_URL):
return 'label';
case url?.includes(QUERY_URL):
return 'query'
default: return 'label'
}
}

if (response?.statusText) {
const status = response?.status;

return {
message: "API " + response.statusText + ", Please adjust API URL",
status,
type: type()
};
} else if (url && !url.includes(window.location.protocol)) {

return {
message: "Mixed Content Error, your View should be over same protocol as your API",
status: 500,
type : type()
};
} else if (request) {
if (error.stack.includes('Network Error')) {
return {
message: "Invalid API URL, please adjust API URL",
status: 500,
type: type()
}
}
return {
message: "server time out",
status: response?.status,
type: type()
};
} else if (error?.stack?.includes("Invalid URL")) {
return {
message: "Invalid API URL, please adjust API URL",
stauts: response?.status,
type: type()
};
} else if (error?.response?.status === 404) {
return {
message: "Invalid API URL, please adjust API URL",
status: response?.status,
type: type()
};
} else {
if (type === 'labels') return;

return {
message: "something went wrong with request",
status: response?.status,
type: type()
};
}
};
export const errorHandler = (error: any) => {

const LABELS_URL = "/loki/api/v1/label";
const QUERY_URL = "/loki/api/v1/query_range";

const { request, response } = error;
const url = error?.response?.request?.responseURL


let type = () => {
switch(url) {
case url?.includes(LABELS_URL):
return 'label';
case url?.includes(QUERY_URL):
return 'query'
default: return 'label'
}
}

if (response?.statusText) {
const status = response?.status;

return {
message: "API " + response.statusText + ", Please adjust API URL",
status,
type: type()
};
} else if (url && !url.includes(window.location.protocol)) {

return {
message: "Mixed Content Error, your View should be over same protocol as your API",
status: 500,
type : type()
};
} else if (request) {
if (error.stack.includes('Network Error')) {
return {
message: "Invalid API URL, please adjust API URL",
status: 500,
type: type()
}
}
return {
message: "server time out",
status: response?.status,
type: type()
};
} else if (error?.stack?.includes("Invalid URL")) {
return {
message: "Invalid API URL, please adjust API URL",
stauts: response?.status,
type: type()
};
} else if (error?.response?.status === 404) {
return {
message: "Invalid API URL, please adjust API URL",
status: response?.status,
type: type()
};
} else {
// if (type === 'labels') return;

return {
message: "something went wrong with request",
status: response?.status,
type: type()
};
}
};
31 changes: 23 additions & 8 deletions src/actions/getData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { getTimeSpan } from "./helpers/getTimeSpan";
import { boscoSend } from "./helpers/boscoRequest";
import { setLeftPanel } from "./setLeftPanel";
import { setRightPanel } from "./setRightPanel";
import { DataViews } from "../store/store.model";
import { setLeftDataView } from "./setLeftDataView";
import { setRightDataView } from "./setRightDataView";

/**
*
Expand All @@ -36,11 +39,16 @@ function panelDispatch(panel: string, dispatch: Function, data: any) {
return dispatch(setRightPanel(data));
}
}

export function dataViewDispatch(panel: string, dataViews: DataViews, dispatch: Function) {
if (panel === "left") {
return dispatch(setLeftDataView(dataViews));
}
return dispatch(setRightDataView(dataViews));
}
function changeLoadingState(panel: any[], id: string, state: boolean) {
return [...panel].map((m) => {
if (m.id === id) {
return { ...m, loading: state };
return { ...m, loading: state || false };
}
return m;
});
Expand Down Expand Up @@ -150,10 +158,17 @@ export default function getData(
);

const endpoint = getEndpoint(type, queryType, params);

const setLoading = (state: boolean, dispatch: Function) => {
const dataViews: DataViews = store.getState()?.[`${panel}DataView`];
const dataView = dataViews?.find((view) => view.id === id);
if (dataView) {
dataView.loading = state;
}
dataViewDispatch(panel, dataViews, dispatch);
}
return async function (dispatch: Function) {
await resetParams(dispatch, panel);
dispatch(setLoading(true));
setLoading(true, dispatch);
loadingState(dispatch, true);
let cancelToken: any;

Expand Down Expand Up @@ -187,13 +202,13 @@ export default function getData(
.catch((error) => {
resetNoData(dispatch);
dispatch(setIsEmptyView(true));
dispatch(setLoading(false));
setLoading(false, dispatch)
if (debugMode) {
console.log("Error loading flux data", error);
}
})
.finally(() => {
dispatch(setLoading(false));
setLoading(false, dispatch)
loadingState(dispatch, false);
});
} else if (options?.method === "GET") {
Expand Down Expand Up @@ -224,7 +239,7 @@ export default function getData(
.catch((error) => {
resetNoData(dispatch);
dispatch(setIsEmptyView(true));
dispatch(setLoading(false));
setLoading(false, dispatch)
loadingState(dispatch, false);
if (debugMode) {
boscoSend(
Expand All @@ -240,7 +255,7 @@ export default function getData(
})
.finally(() => {
loadingState(dispatch, false);
dispatch(setLoading(false));
setLoading(false, dispatch)
});
}
} catch (e) {
Expand Down
Loading

0 comments on commit f5ee973

Please sign in to comment.