From f8053429dc4c1e969a328724e7317572fe204ca3 Mon Sep 17 00:00:00 2001 From: Joel Guerra Date: Mon, 25 Nov 2024 20:15:39 +0100 Subject: [PATCH 1/4] fix: add token header --- packages/main/views/Main/helpers.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/main/views/Main/helpers.ts b/packages/main/views/Main/helpers.ts index 9f36f04e..d8da1044 100644 --- a/packages/main/views/Main/helpers.ts +++ b/packages/main/views/Main/helpers.ts @@ -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; @@ -45,6 +47,16 @@ export function updateDataSourcesWithUrl( let [user, pass] = auth.split(":"); + if( user === "token" ) { + + hasToken = true; + tokenHeader = { + header: "x-api-token", + value: pass + } + + } + if (user !== "" && pass !== "") { cookieAuth = { user, password: pass }; basicAuth = true; @@ -67,6 +79,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 }, From ebcd824ba5c11f91bd98633cf78b02a7ca300de6 Mon Sep 17 00:00:00 2001 From: Joel Guerra Date: Tue, 26 Nov 2024 11:10:07 +0100 Subject: [PATCH 2/4] fix: remove basic auth at token instance --- packages/main/views/Main/helpers.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/main/views/Main/helpers.ts b/packages/main/views/Main/helpers.ts index d8da1044..35c1917f 100644 --- a/packages/main/views/Main/helpers.ts +++ b/packages/main/views/Main/helpers.ts @@ -20,7 +20,7 @@ export function updateDataSourcesWithUrl( let urlApi = false; let hasToken = false; let cookieAuth: any = {}; - let tokenHeader: any = {}; + let tokenHeader: any = {}; if (haveUrl) { urlApi = true; @@ -47,17 +47,16 @@ export function updateDataSourcesWithUrl( let [user, pass] = auth.split(":"); - if( user === "token" ) { - + if (user === "token") { hasToken = true; + basicAuth = false; tokenHeader = { header: "x-api-token", - value: pass - } - + value: pass, + }; } - if (user !== "" && pass !== "") { + if (user !== "" && pass !== "" && user !== "token") { cookieAuth = { user, password: pass }; basicAuth = true; } @@ -79,7 +78,7 @@ export function updateDataSourcesWithUrl( const newDs = prevDs?.map((m: any) => ({ ...m, url: urlApi ? apiUrl : m.url, - headers: hasToken ? [...m.headers, { ...tokenHeader}] : [...m.headers], + headers: hasToken ? [...m.headers, { ...tokenHeader }] : [...m.headers], auth: { ...m.auth, basicAuth: { ...m.auth.basicAuth, value: basicAuth }, @@ -194,8 +193,8 @@ export async function checkLocalAPI( true ); - // activate web vitals - + // activate web vitals + isReady = true; } else { setResponseType(ResponseEnum.NODE); @@ -208,9 +207,9 @@ export async function checkLocalAPI( "Query Item", "Cardinality View", false - ) + ); - // deactivate web vitals + // deactivate web vitals isReady = true; } } From a52c1cc6f50133021fe43629227fe96100352d47 Mon Sep 17 00:00:00 2001 From: Joel Guerra Date: Wed, 27 Nov 2024 13:05:31 +0100 Subject: [PATCH 3/4] fix: metrics series request and switch button --- .../DataViews/components/Metrics/useMetricsList.ts | 4 +++- .../components/Metrics/useValuesFromMetrics.ts | 4 +++- .../QueryBuilder/hooks/useMetricsList.tsx | 4 +++- .../QueryTypeBar/components/QueryTypeSwitch.tsx | 13 ++++++------- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/main/src/components/DataViews/components/Metrics/useMetricsList.ts b/packages/main/src/components/DataViews/components/Metrics/useMetricsList.ts index 9365cbb1..2e091495 100644 --- a/packages/main/src/components/DataViews/components/Metrics/useMetricsList.ts +++ b/packages/main/src/components/DataViews/components/Metrics/useMetricsList.ts @@ -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 || []); } diff --git a/packages/main/src/components/DataViews/components/Metrics/useValuesFromMetrics.ts b/packages/main/src/components/DataViews/components/Metrics/useValuesFromMetrics.ts index 2e054b14..58cd62e3 100644 --- a/packages/main/src/components/DataViews/components/Metrics/useValuesFromMetrics.ts +++ b/packages/main/src/components/DataViews/components/Metrics/useValuesFromMetrics.ts @@ -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.options, + }); if (req?.status === 200) { setMetricNames(req?.data?.data || []); } diff --git a/packages/main/src/components/DataViews/components/QueryBuilder/hooks/useMetricsList.tsx b/packages/main/src/components/DataViews/components/QueryBuilder/hooks/useMetricsList.tsx index 33b9ffee..3be6d9fc 100644 --- a/packages/main/src/components/DataViews/components/QueryBuilder/hooks/useMetricsList.tsx +++ b/packages/main/src/components/DataViews/components/QueryBuilder/hooks/useMetricsList.tsx @@ -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 || []); } diff --git a/packages/main/src/components/QueryTypeBar/components/QueryTypeSwitch.tsx b/packages/main/src/components/QueryTypeBar/components/QueryTypeSwitch.tsx index 438171e2..4b409d6b 100644 --- a/packages/main/src/components/QueryTypeBar/components/QueryTypeSwitch.tsx +++ b/packages/main/src/components/QueryTypeBar/components/QueryTypeSwitch.tsx @@ -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}; @@ -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}` @@ -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%; From af75b136a629669b4bdd66771f7c07ec8570adb9 Mon Sep 17 00:00:00 2001 From: Joel Guerra Date: Wed, 27 Nov 2024 13:43:47 +0100 Subject: [PATCH 4/4] fix: metrics headers --- .../DataViews/components/Metrics/useValuesFromMetrics.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/main/src/components/DataViews/components/Metrics/useValuesFromMetrics.ts b/packages/main/src/components/DataViews/components/Metrics/useValuesFromMetrics.ts index 58cd62e3..75957473 100644 --- a/packages/main/src/components/DataViews/components/Metrics/useValuesFromMetrics.ts +++ b/packages/main/src/components/DataViews/components/Metrics/useValuesFromMetrics.ts @@ -34,9 +34,9 @@ export function useValuesFromMetrics(id: any, start, stop) { // setLoading(true); try { - const req = await axios.get(url, { - ...metricsHeaders.options, - }); + const req = await axios.get(url, + metricsHeaders, + ); if (req?.status === 200) { setMetricNames(req?.data?.data || []); }