Skip to content

Commit

Permalink
Merge pull request #614 from gigapipehq/dev
Browse files Browse the repository at this point in the history
fix: add token requests
  • Loading branch information
jacovinus authored Nov 27, 2024
2 parents 3a28309 + 7837e16 commit 2b60d5d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export function useMetricsList(id: any, value: any, start, stop) {
const url = `${dataSource.url}/api/v1/series?start=${timeParams.start}&end=${timeParams.end}&${valueFormatter}`;
const apiRequest = async () => {
try {
const req = await axios.get(url, metricsHeaders);
const req = await axios.get(url, {
...metricsHeaders.options,
});
if (req?.status === 200) {
setMetricNames(req?.data?.data || []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export function useValuesFromMetrics(id: any, start, stop) {
// setLoading(true);

try {
const req = await axios.get(url, metricsHeaders);
const req = await axios.get(url,
metricsHeaders,
);
if (req?.status === 200) {
setMetricNames(req?.data?.data || []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export function useMetricsList(id: string, value: string, start, stop) {
const url = `${dataSource.url}/api/v1/series?start=${timeParams.start}&end=${timeParams.end}&${valueFormatter}`;
const apiRequest = async () => {
try {
const req = await axios.get(url, metricsHeaders);
const req = await axios.get(url, {
...metricsHeaders.options,
});
if (req?.status === 200) {
setMetricNames(req?.data?.data || []);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from "@emotion/styled";
import { useEffect, useMemo, useState } from "react";
import { type QrynTheme } from "@ui/theme/types";
const Label: any = styled.div`
color: ${(props: any) => props.theme.contrast};
background: ${(props: any) => props.theme.shadow};
Expand All @@ -22,14 +23,12 @@ const QuerySwitchCont: any = styled.div`
margin-right: 10px;
`;

const QuerySwitchBtn: any = styled.div`
const QuerySwitchBtn: any = styled.div<{ theme: QrynTheme; selected: boolean }>`
cursor: pointer;
display: flex;
align-items: center;
background: ${(props: any) =>
props.selected
? props.theme.neutral
: props.theme.shadow};
background: ${(props) =>
props.selected ? props.theme.alphaPlusNeutral : props.theme.shadow};
border-left: ${(props: any) =>
props.position === "last"
? `1px solid ${props.theme.accentNeutral}`
Expand All @@ -42,8 +41,8 @@ const QuerySwitchBtn: any = styled.div`
position === "first"
? "3px 0px 0px 3px"
: position === "last"
? "0px 3px 3px 0px"
: "0px"};
? "0px 3px 3px 0px"
: "0px"};
flex: 1;
height: 90%;
Expand Down
22 changes: 17 additions & 5 deletions packages/main/views/Main/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export function updateDataSourcesWithUrl(
let apiUrl = "";
let basicAuth = false;
let urlApi = false;
let hasToken = false;
let cookieAuth: any = {};
let tokenHeader: any = {};

if (haveUrl) {
urlApi = true;
Expand All @@ -45,7 +47,16 @@ export function updateDataSourcesWithUrl(

let [user, pass] = auth.split(":");

if (user !== "" && pass !== "") {
if (user === "token") {
hasToken = true;
basicAuth = false;
tokenHeader = {
header: "x-api-token",
value: pass,
};
}

if (user !== "" && pass !== "" && user !== "token") {
cookieAuth = { user, password: pass };
basicAuth = true;
}
Expand All @@ -67,6 +78,7 @@ export function updateDataSourcesWithUrl(
const newDs = prevDs?.map((m: any) => ({
...m,
url: urlApi ? apiUrl : m.url,
headers: hasToken ? [...m.headers, { ...tokenHeader }] : [...m.headers],
auth: {
...m.auth,
basicAuth: { ...m.auth.basicAuth, value: basicAuth },
Expand Down Expand Up @@ -181,8 +193,8 @@ export async function checkLocalAPI(
true
);

// activate web vitals
// activate web vitals

isReady = true;
} else {
setResponseType(ResponseEnum.NODE);
Expand All @@ -195,9 +207,9 @@ export async function checkLocalAPI(
"Query Item",
"Cardinality View",
false
)
);

// deactivate web vitals
// deactivate web vitals
isReady = true;
}
}
Expand Down

0 comments on commit 2b60d5d

Please sign in to comment.