Skip to content

Commit

Permalink
Merge pull request #59 from metrico/jacovinus-labels-fix
Browse files Browse the repository at this point in the history
fixes: #56 Manually removing label does not update state
  • Loading branch information
jacovinus authored Mar 10, 2022
2 parents f465086 + bce33d1 commit 908d48b
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 184 deletions.
3 changes: 0 additions & 3 deletions src/actions/LoadLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export default function loadLabels(apiUrl) {
const labels = response?.data?.data.sort().map((label) => ({
name: label,
selected: false,
loading: false,
values: [],
hidden: false,
facets: 0,
}));
dispatch(setLabels(labels || []));
}
Expand Down
4 changes: 0 additions & 4 deletions src/actions/loadLabelValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export default function loadLabelValues(label, labelList, apiUrl) {
const values = response?.data?.data?.map?.((value) => ({
name: value,
selected: false,
loading: false,
hidden: false,
inverted: false
}));

Expand All @@ -55,8 +53,6 @@ export default function loadLabelValues(label, labelList, apiUrl) {
dispatch(setApiError(''))
dispatch(setLabelValues(response?.data?.data));



}).catch(error => {
dispatch(setLoading(false))
const { message } = errorHandler(url, error)
Expand Down
6 changes: 3 additions & 3 deletions src/actions/loadLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function loadLogs() {
// const step = 120
// const direction = 'backward'
const localStore = store.getState();
const { query: label, limit, step, apiUrl, label: rangeLabel } = localStore;
const { query, limit, step, apiUrl, label: rangeLabel } = localStore;
let { start: startTs, stop: stopTs } = localStore;

if (findRangeByLabel(rangeLabel)) {
Expand All @@ -39,9 +39,9 @@ export default function loadLogs() {

const queryStep = `&step=${step || 120}`;

const query = `${encodeURIComponent(label)}`;
const encodedQuery = `${encodeURIComponent(query)}`;

const getUrl = `${url}/loki/api/v1/query_range?query=${query}&limit=${limit}${parsedTime}${queryStep}`;
const getUrl = `${url}/loki/api/v1/query_range?query=${encodedQuery}&limit=${limit}${parsedTime}${queryStep}`;

const options = {
method: "GET",
Expand Down
14 changes: 9 additions & 5 deletions src/components/LabelBrowser/QueryBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import HistoryIcon from "@mui/icons-material/History";
import styled from "@emotion/styled";
import setHistoryOpen from "../../actions/setHistoryOpen";
import { Tooltip } from "@mui/material";
import Badge from '@mui/material/Badge';
import { decodeQuery } from "../UpdateStateFromQueryParams";
import localUrl from "../../services/localUrl";


const HistoryButton = styled.button`
background: none;
Expand All @@ -27,6 +29,7 @@ export const QueryBar = () => {
const labelsBrowserOpen = useSelector((store) => store.labelsBrowserOpen);
const debug = useSelector((store) => store.debug);
const query = useSelector((store) => store.query);
const apiUrl = useSelector((store) => store.apiUrl)
const isSubmit = useSelector((store) => store.isSubmit);
const historyOpen = useSelector((store) => store.historyOpen)
const [queryInput, setQueryInput] = useState(query);
Expand All @@ -36,7 +39,7 @@ export const QueryBar = () => {
const LOG_BROWSER = "Log Browser";
const queryHistory = useSelector((store) => store.queryHistory)
const [historyItems, setHistoryItems] = useState(queryHistory.length>0)

const saveUrl = localUrl()
useEffect(()=>{
setHistoryItems(queryHistory.length>0)
},[queryHistory])
Expand All @@ -60,7 +63,6 @@ export const QueryBar = () => {
);
// here
dispatch(setLoading(true));

dispatch(loadLogs());

setTimeout(() => {
Expand Down Expand Up @@ -107,15 +109,17 @@ export const QueryBar = () => {

dispatch(setQuery(queryInput));

if (onQueryValid(query)) {
if (onQueryValid(queryInput)) {
try {
const historyUpdated = historyService.add({
data: query,
data: queryInput,
url: window.location.hash,
});
dispatch(setQueryHistory(historyUpdated));
dispatch(setLabelsBrowserOpen(false));
decodeQuery(query,apiUrl)
dispatch(loadLogs());
saveUrl.add({data: window.location.href, description:'From Query Submit'})
} catch (e) {
console.log(e);
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/LabelBrowser/ValuesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const ValuesList = (props) => {
const [labelsSelected, setLabelsSelected] = useState([]);
const labels = useSelector(state => {
const selected = state.labels.filter((f) => f.selected);
console.log(JSON.stringify(selected) !== JSON.stringify(labelsSelected))
if (JSON.stringify(selected) !== JSON.stringify(labelsSelected)) {
setLabelsSelected(selected);
}
Expand All @@ -47,7 +46,7 @@ export const ValuesList = (props) => {
if(debug) console.log('🚧 LOGIC/LabelBrowser/ValuesList', apiUrl)
const labelsBrowserOpen = useSelector((store) => store.labelsBrowserOpen)

const CLOSE = "close"
const CLEAR = "clear"
/**
* TODO: FILTER VALUES INSIDE LABELS
*/
Expand Down Expand Up @@ -191,7 +190,7 @@ export const ValuesList = (props) => {
onClick={(e) =>
onLabelOpen(e, labelSelected)
}
>{CLOSE}</span>
>{CLEAR}</span>
</div>
<div className={"valuelist-content column"}>
{labelSelected?.values?.map(
Expand Down
7 changes: 4 additions & 3 deletions src/components/LabelBrowser/helpers/querybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { setQuery } from "../../../actions";
import store from "../../../store/store";

export function queryBuilder(labels) {
console.log(labels)
const selectedLabels = [];
for (const label of labels) {
if (label.selected && label.values && label.values.length > 0) {
Expand Down Expand Up @@ -30,6 +31,6 @@ export function queryBuilder(labels) {
export function queryBuilderWithLabels() {
const labels = store.getState().labels;
console.log(labels)
const query = queryBuilder(labels)
store.dispatch(setQuery(query));
}
const query = queryBuilder(labels)
store.dispatch(setQuery(query));
}
Loading

0 comments on commit 908d48b

Please sign in to comment.