Skip to content

Commit c72722f

Browse files
authored
Merge pull request #73 from metrico/jacovinus-mutiple-label-tooltip
fix: responsive styles for app
2 parents 8fbda9d + 6271d0a commit c72722f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4108
-2588
lines changed

Diff for: package-lock.json

+65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"react-dom": "^17.0.2",
3333
"react-flot": "^1.3.0",
3434
"react-redux": "^7.2.6",
35+
"react-responsive": "^9.0.0-beta.6",
3536
"react-router-dom": "^6.2.1",
3637
"redux-thunk": "^2.4.1",
3738
"slate": "^0.73.1",

Diff for: src/App.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { Provider } from "react-redux";
22
import MainView from "./components/MainView";
3-
import store from './store/store';
3+
import store from "./store/store";
44
export default function App() {
5-
6-
return (
7-
<Provider store={store}>
8-
9-
<MainView/>
10-
11-
</Provider>
12-
);
13-
5+
return (
6+
<Provider store={store}>
7+
<MainView />
8+
</Provider>
9+
);
1410
}

Diff for: src/actions/LoadLabels.js

+38-34
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import { setLabelsBrowserOpen } from "./setLabelsBrowserOpen";
77

88
export default function loadLabels(apiUrl) {
99
const origin = window.location.origin;
10-
const url = apiUrl
10+
const url = apiUrl;
1111
const headers = {
12-
1312
"Access-Control-Allow-Origin": origin,
14-
"Access-Control-Allow-Headers": ["Access-Control-Request-Headers", "Content-Type"],
13+
"Access-Control-Allow-Headers": [
14+
"Access-Control-Request-Headers",
15+
"Content-Type",
16+
],
1517
"Content-Type": "application/json",
16-
17-
}
18+
};
1819

1920
const options = {
2021
method: "GET",
@@ -23,35 +24,38 @@ export default function loadLabels(apiUrl) {
2324
};
2425

2526
return function (dispatch) {
26-
27-
axios.get(`${url.trim()}/loki/api/v1/labels`, options)
27+
axios
28+
.get(`${url.trim()}/loki/api/v1/labels`, options)
2829
?.then((response) => {
29-
if(response){
30-
if(response?.data?.data === []) console.log('no labels found')
31-
if (response?.data?.data?.length > 0) {
32-
33-
const labels = response?.data?.data.sort().map((label) => ({
34-
name: label,
35-
selected: false,
36-
values: [],
37-
}));
38-
dispatch(setLabels(labels || []));
39-
dispatch(setApiError(''))
40-
}
41-
42-
}else {
43-
dispatch(setLoading(false))
44-
dispatch(setApiError('API Not Found, Please adjust API URL'))
45-
dispatch(setLabelsBrowserOpen(true))
46-
dispatch(setLabels([]))
47-
}
48-
49-
}).catch(error => {
50-
console.log(error)
51-
dispatch(setLoading(false))
52-
const {message,status} = errorHandler(url, error)
53-
dispatch(setLabels([]))
54-
30+
if (response) {
31+
if (response?.data?.data === [])
32+
console.log("no labels found");
33+
if (response?.data?.data?.length > 0) {
34+
const labels = response?.data?.data
35+
.sort()
36+
.map((label) => ({
37+
name: label,
38+
selected: false,
39+
values: [],
40+
}));
41+
dispatch(setLabels(labels || []));
42+
dispatch(setApiError(""));
43+
}
44+
} else {
45+
dispatch(setLoading(false));
46+
dispatch(
47+
setApiError("API Not Found, Please adjust API URL")
48+
);
49+
dispatch(setLabelsBrowserOpen(true));
50+
dispatch(setLabels([]));
51+
}
5552
})
56-
}
53+
.catch((error) => {
54+
console.log(error);
55+
dispatch(setLoading(false));
56+
const { message, status } = errorHandler(url, error);
57+
dispatch(setApiError(`Status: ${status}, ${message}`));
58+
dispatch(setLabels([]));
59+
});
60+
};
5761
}

Diff for: src/actions/loadLogs.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ import setLoading from "./setLoading";
44
import store from "../store/store";
55
import setMatrixData from "./setMatrixData";
66
import { nanoid } from "nanoid";
7-
import { findRangeByLabel } from "../plugins/daterangepicker/utils";
87
import { setStartTime, setStopTime } from "./";
9-
// *query : LogQl Query
10-
// *limit : Limit of returned lines
11-
// *start : The start time for the query as a nanosecond Unix epoch. Defaults to one hour ago
12-
// *end : The end time for the query as a nanosecond Unix epoch. Defaults to now
13-
// *step : Resolution step width in either a duration [1s, 5s, 5m etc] or number of seconds
14-
// *direction : Determines sort order of logs. Either forward or backward. Default is backward
8+
import { findRangeByLabel } from "../components/StatusBar/components/daterangepicker/utils";
9+
1510

1611
export default function loadLogs() {
17-
// const step = 120
18-
// const direction = 'backward'
12+
1913
const localStore = store.getState();
2014
const { query, limit, step, apiUrl, label: rangeLabel } = localStore;
2115
let { start: startTs, stop: stopTs } = localStore;
@@ -51,8 +45,8 @@ export default function loadLogs() {
5145
},
5246
};
5347

54-
const fromNanoSec = (ts) => parseInt(ts / 1000000); // stream type will come in Nanoseconds
55-
const toMiliseC = (ts) => parseInt(ts * 1000); // matrix type will come without millisec
48+
const fromNanoSec = (ts) => parseInt(ts / 1000000);
49+
const toMiliseC = (ts) => parseInt(ts * 1000);
5650
const getTimestamp = (type) => (ts) =>
5751
type === "streams"
5852
? fromNanoSec(ts)
@@ -108,7 +102,7 @@ export default function loadLogs() {
108102
}
109103

110104
if (type === "matrix") {
111-
const idResult = result.map((m) => ({ ...m, id: nanoid() }));
105+
const idResult = result?.map((m) => ({ ...m, id: nanoid() }))||[];
112106
dispatch(setMatrixData(idResult || []));
113107
dispatch(setLoading(false));
114108
}

Diff for: src/actions/setLoading.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
export default (loading) => (dispatch) => {
1+
const setLoading = (loading) => (dispatch) => {
22
dispatch({
3-
type: 'SET_LOADING',
4-
loading
3+
type: "SET_LOADING",
4+
loading,
55
});
6-
}
6+
};
7+
8+
export default setLoading;

Diff for: src/actions/setLogs.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
export default (logs) => (dispatch) => {
1+
const setLogs = (logs) => (dispatch) => {
22
dispatch({
3-
type: 'SET_LOGS',
4-
logs
3+
type: "SET_LOGS",
4+
logs,
55
});
6-
}
6+
};
7+
8+
export default setLogs;

Diff for: src/components/DataView/DataView.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React, { Component } from "react";
2+
import { connect } from "react-redux";
3+
4+
import { DataViewCont, DataViewStyled, Loader } from "./styled";
5+
6+
import ClokiChart from "../../plugins/charts";
7+
import QueryHistory from "../../plugins/queryhistory";
8+
import LogsRow from "./LogsRow";
9+
import EmptyView from "./EmptyView";
10+
11+
class DataView extends Component {
12+
constructor(props) {
13+
super(props);
14+
this.state = {
15+
limit: props.limit || 100,
16+
messages: props.messages || [],
17+
matrixData: props.matrixData || [],
18+
loading: false,
19+
};
20+
}
21+
22+
getMatrixForChart = () => {
23+
return this.props.matrixData;
24+
};
25+
getLimit = () => {
26+
return this.props.limit;
27+
};
28+
29+
render() {
30+
return (
31+
<DataViewStyled>
32+
<DataViewCont>
33+
{this.props.messages.length > 0 &&
34+
this.getMatrixForChart().length < 1
35+
? this.props.messages.map((message, key) => (
36+
<LogsRow
37+
message={message}
38+
toggleTagsActive={this.toggleTagsActive}
39+
key={key}
40+
/>
41+
))
42+
: null}
43+
44+
{this.getMatrixForChart().length > 0 ? (
45+
<ClokiChart
46+
chartLimit={this.getLimit()}
47+
matrixData={this.getMatrixForChart()}
48+
/>
49+
) : null}
50+
{this.props.messages.length < 1 &&
51+
this.getMatrixForChart().length < 1 &&
52+
!this.props.loading && <EmptyView />}
53+
<QueryHistory />
54+
{this.props.loading && <Loader />}
55+
</DataViewCont>
56+
</DataViewStyled>
57+
);
58+
}
59+
}
60+
61+
const mapStateToProps = (state) => {
62+
return {
63+
messages: state.logs,
64+
start: state.start,
65+
stop: state.stop,
66+
limit: state.limit,
67+
loading: state.loading,
68+
matrixData: state.matrixData,
69+
};
70+
};
71+
72+
export default connect(mapStateToProps)(DataView);

Diff for: src/components/DataView/EmptyView.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { EmptyViewContainer } from "./styled";
2+
3+
export default function EmptyView() {
4+
return (
5+
<EmptyViewContainer>
6+
{"Please adjust search parameters and click on ‘Show Logs’ button"}
7+
</EmptyViewContainer>
8+
);
9+
}

0 commit comments

Comments
 (0)