From 8cf06ad2fffb5143ef031214e089dd0be1c061b5 Mon Sep 17 00:00:00 2001 From: Charles Wahome Date: Tue, 28 Feb 2023 12:26:53 +0300 Subject: [PATCH 1/3] check whether a query should run based on exceptions --- .../query-runner/query-input/QueryInput.tsx | 6 +++- .../sidebar/sample-queries/SampleQueries.tsx | 8 +++--- .../sample-queries/sample-query-utils.ts | 28 ++++++++++++++++--- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/app/views/query-runner/query-input/QueryInput.tsx b/src/app/views/query-runner/query-input/QueryInput.tsx index 2a46fe861..f98ce01cb 100644 --- a/src/app/views/query-runner/query-input/QueryInput.tsx +++ b/src/app/views/query-runner/query-input/QueryInput.tsx @@ -10,6 +10,7 @@ import { getStyleFor } from '../../../utils/http-methods.utils'; import { parseSampleUrl } from '../../../utils/sample-url-generation'; import { translateMessage } from '../../../utils/translate-messages'; import SubmitButton from '../../../views/common/submit-button/SubmitButton'; +import { shouldRunQuery } from '../../sidebar/sample-queries/sample-query-utils'; import { queryRunnerStyles } from '../QueryRunner.styles'; import { AutoComplete } from './auto-complete'; import { ShareQuery } from './share-query'; @@ -36,7 +37,10 @@ const QueryInput = (props: IQueryInputProps) => { const authenticated = !!authToken.token; const { mobileScreen } = sidebarProperties; - const showError = !authenticated && sampleQuery.selectedVerb !== 'GET'; + const showError = shouldRunQuery({ + method: sampleQuery.selectedVerb, authenticated, + url: sampleQuery.sampleUrl + }); const { queryButtonStyles, verbSelector, shareQueryButtonStyles } = queryRunnerStyles(); verbSelector.title = { ...verbSelector.title, diff --git a/src/app/views/sidebar/sample-queries/SampleQueries.tsx b/src/app/views/sidebar/sample-queries/SampleQueries.tsx index 0de028dd1..f53fb1b00 100644 --- a/src/app/views/sidebar/sample-queries/SampleQueries.tsx +++ b/src/app/views/sidebar/sample-queries/SampleQueries.tsx @@ -25,7 +25,7 @@ import { classNames } from '../../classnames'; import { NoResultsFound } from '../sidebar-utils/SearchResult'; import { sidebarStyles } from '../Sidebar.styles'; import { - isJsonString, performSearch, trackDocumentLinkClickedEvent, + isJsonString, performSearch, shouldRunQuery, trackDocumentLinkClickedEvent, trackSampleQueryClickEvent } from './sample-query-utils'; @@ -167,7 +167,7 @@ const UnstyledSampleQueries = (sampleProps?: ISampleQueriesProps): JSX.Element = onRender: (item: ISampleQuery) => { const signInText = translateMessage('Sign In to try this sample'); - if (item.method === 'GET' || tokenPresent) { + if (!shouldRunQuery({ method: item.method, authenticated: tokenPresent, url: item.requestUrl })) { return