From 37ff80e0dea1ecf0cd49d399f2eaaa4a45fcb2f5 Mon Sep 17 00:00:00 2001
From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com>
Date: Fri, 22 Nov 2024 11:04:59 +0530
Subject: [PATCH 1/4] fix: updating the test role page without reload
---
.../pages/testing/TestRoleSettings/TestRoleSettings.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/TestRoleSettings/TestRoleSettings.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/TestRoleSettings/TestRoleSettings.jsx
index dd30d7488..929db6fd1 100644
--- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/TestRoleSettings/TestRoleSettings.jsx
+++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/TestRoleSettings/TestRoleSettings.jsx
@@ -134,7 +134,7 @@ function TestRoleSettings() {
func.setToast(true, true, "Please select valid values for a test role")
} else {
if (isNew) {
- api.addTestRoles(roleName, andConditions, orConditions).then((res) => {
+ await api.addTestRoles(roleName, andConditions, orConditions).then((res) => {
func.setToast(true, false, "Test role added")
setChange(false);
navigate(null, { state: { name: roleName, endpoints: { andConditions: andConditions, orConditions: orConditions } },
From c49b1347f8beffd714ee1d1eb4bf39458240b649 Mon Sep 17 00:00:00 2001
From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com>
Date: Fri, 22 Nov 2024 11:59:38 +0530
Subject: [PATCH 2/4] fix: disabling the run test button if it's already
clicked
# Conflicts:
# apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx
---
.../dashboard/pages/observe/api_collections/RunTest.jsx | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx
index 7365689c4..c1058f988 100644
--- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx
+++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx
@@ -68,6 +68,8 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
const [optionsSelected, setOptionsSelected] = useState(initialArr)
const [slackIntegrated, setSlackIntegrated] = useState(false)
+ const [testAlreadyRunning, setTestAlreadyRunning] = useState(false)
+
const emptyCondition = {data: {key: '', value: ''}, operator: {'type': 'ADD_HEADER'}}
const [conditions, dispatchConditions] = useReducer(produce((draft, action) => func.conditionsReducer(draft, action)), [emptyCondition]);
@@ -413,6 +415,7 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
}
async function handleRun() {
+ setTestAlreadyRunning(true)
const { startTimestamp, recurringDaily, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert } = testRun
const collectionId = parseInt(apiCollectionId)
@@ -468,6 +471,7 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
)
+ setTestAlreadyRunning(false)
func.setToast(true, false,
{forwardLink}
)
}
@@ -530,7 +534,7 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
primaryAction={{
content: scheduleString(),
onAction: handleRun,
- disabled: !testRun.authMechanismPresent
+ disabled: !testRun.authMechanismPresent || testAlreadyRunning
}}
large
>
From ad873fcc46eeab7811b4a2dae52e2eea44302c47 Mon Sep 17 00:00:00 2001
From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com>
Date: Fri, 22 Nov 2024 14:49:03 +0530
Subject: [PATCH 3/4] fix: calling test role data in the background
---
.../TestRoleSettings/TestRoleSettings.jsx | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/TestRoleSettings/TestRoleSettings.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/TestRoleSettings/TestRoleSettings.jsx
index 929db6fd1..8f5b4827c 100644
--- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/TestRoleSettings/TestRoleSettings.jsx
+++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/TestRoleSettings/TestRoleSettings.jsx
@@ -134,30 +134,33 @@ function TestRoleSettings() {
func.setToast(true, true, "Please select valid values for a test role")
} else {
if (isNew) {
- await api.addTestRoles(roleName, andConditions, orConditions).then((res) => {
+ api.addTestRoles(roleName, andConditions, orConditions).then((_) => {
func.setToast(true, false, "Test role added")
setChange(false);
navigate(null, { state: { name: roleName, endpoints: { andConditions: andConditions, orConditions: orConditions } },
replace:true })
}).catch((err) => {
func.setToast(true, true, "Unable to add test role")
+ }).finally(() => {
+ setRefresh(!refresh)
})
+ func.setToast(true, false, "Creating a new test role.")
} else {
- await api.updateTestRoles(roleName, andConditions, orConditions).then((res) => {
+ api.updateTestRoles(roleName, andConditions, orConditions).then((_) => {
+ if(!updatedAuth){
+ func.setToast(true, false, "Test role updated successfully.")
+ }
setChange(false);
navigate(null, { state: { name: roleName, endpoints: { andConditions: andConditions, orConditions: orConditions }, authWithCondList: authWithCondLists || getAuthWithCondList()},
replace:true })
}).catch((err) => {
func.setToast(true, true, "Unable to update test role")
+ }).finally(() => {
+ setRefresh(!refresh)
})
- if(!updatedAuth){
- func.setToast(true, false, "Test role updated successfully.")
- }
+ func.setToast(true, false, "Updating test role.")
}
}
- setTimeout(() => {
- setRefresh(!refresh)
- },200)
}
const handleTextChange = (val) => {
From 0ac83d234260b9d009bd721174b6e8780a678fe7 Mon Sep 17 00:00:00 2001
From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com>
Date: Fri, 22 Nov 2024 17:53:02 +0530
Subject: [PATCH 4/4] fix: stop calling unused api calls in the run test
---
.../observe/api_collections/ApiDetails.jsx | 15 +---
.../pages/observe/api_collections/RunTest.jsx | 74 +++++++++++++------
.../dashboard/pages/observe/observeStore.js | 5 ++
3 files changed, 56 insertions(+), 38 deletions(-)
diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx
index a23c8d2f7..fb07dd001 100644
--- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx
+++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx
@@ -16,15 +16,11 @@ import PersistStore from "../../../../main/PersistStore";
import values from "@/util/values";
import { HorizontalDotsMinor, FileMinor } from "@shopify/polaris-icons"
-import LocalStore from "../../../../main/LocalStorageStore";
function ApiDetails(props) {
const { showDetails, setShowDetails, apiDetail, headers, getStatus, isGptActive } = props
- const localCategoryMap = LocalStore.getState().categoryMap
- const localSubCategoryMap = LocalStore.getState().subCategoryMap
-
const [sampleData, setSampleData] = useState([])
const [paramList, setParamList] = useState([])
const [selectedUrl, setSelectedUrl] = useState({})
@@ -36,8 +32,6 @@ function ApiDetails(props) {
const setSelectedSampleApi = PersistStore(state => state.setSelectedSampleApi)
const [disabledTabs, setDisabledTabs] = useState([])
- const [useLocalSubCategoryData, setUseLocalSubCategoryData] = useState(false)
-
const statusFunc = getStatus ? getStatus : (x) => {
try {
if (paramList && paramList.length > 0 &&
@@ -136,13 +130,6 @@ function ApiDetails(props) {
}
useEffect(() => {
- if (
- (localCategoryMap && Object.keys(localCategoryMap).length > 0) &&
- (localSubCategoryMap && Object.keys(localSubCategoryMap).length > 0)
- ) {
- setUseLocalSubCategoryData(true)
- }
-
fetchData();
}, [apiDetail])
@@ -260,7 +247,7 @@ function ApiDetails(props) {
apiCollectionId={apiDetail["apiCollectionId"]}
endpoints={[apiDetail]}
filtered={true}
- useLocalSubCategoryData={useLocalSubCategoryData}
+ useLocalData={true}
/>
diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx
index c1058f988..f75d4bc01 100644
--- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx
+++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx
@@ -9,13 +9,11 @@ import func from "@/util/func"
import { useNavigate } from "react-router-dom"
import PersistStore from "../../../../main/PersistStore";
import transform from "../../testing/transform";
-import LocalStore from "../../../../main/LocalStorageStore";
import AdvancedSettingsComponent from "./component/AdvancedSettingsComponent";
-
import {produce} from "immer"
+import ObserveStore from "../observeStore";
-
-function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction, useLocalSubCategoryData }) {
+function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction, useLocalData }) {
const initialState = {
categories: [],
@@ -70,12 +68,11 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
const [testAlreadyRunning, setTestAlreadyRunning] = useState(false)
+ const runTestModalData = useLocalData ? ObserveStore(state => state.runTestModalData) : {}
+ const setRunTestModalData = ObserveStore(state => state.setRunTestModalData)
const emptyCondition = {data: {key: '', value: ''}, operator: {'type': 'ADD_HEADER'}}
const [conditions, dispatchConditions] = useReducer(produce((draft, action) => func.conditionsReducer(draft, action)), [emptyCondition]);
- const localCategoryMap = LocalStore.getState().categoryMap
- const localSubCategoryMap = LocalStore.getState().subCategoryMap
-
function nameSuffixes(tests) {
return Object.entries(tests)
.filter(category => {
@@ -98,29 +95,45 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
async function fetchData() {
setLoading(true)
+ let tempRunTestModalData = {}
- observeApi.fetchSlackWebhooks().then((resp) => {
- const apiTokenList = resp.apiTokenList
- setSlackIntegrated(apiTokenList && apiTokenList.length > 0)
- })
-
- let metaDataObj = {
- categories: [],
- subCategories: [],
- testSourceConfigs: []
+ if(runTestModalData.slackIntegrated != null) {
+ setSlackIntegrated(runTestModalData.slackIntegrated)
+ } else {
+ observeApi.fetchSlackWebhooks().then((resp) => {
+ const apiTokenList = resp.apiTokenList
+ setSlackIntegrated(apiTokenList && apiTokenList.length > 0)
+ tempRunTestModalData = {
+ ...tempRunTestModalData,
+ slackIntegrated: (apiTokenList && apiTokenList.length > 0)
+ }
+ })
}
- if(!useLocalSubCategoryData) {
- metaDataObj = await transform.getAllSubcategoriesData(true, "runTests")
+
+ let metaDataObj = {}
+ if(runTestModalData.metaDataObj != null) {
+ metaDataObj = runTestModalData.metaDataObj
} else {
- metaDataObj = {
- categories: Object.values(localCategoryMap),
- subCategories: Object.values(localSubCategoryMap),
- testSourceConfigs: []
+ metaDataObj = await transform.getAllSubcategoriesData(true, "runTests")
+ tempRunTestModalData = {
+ ...tempRunTestModalData,
+ metaDataObj
}
}
let categories = metaDataObj.categories
let businessLogicSubcategories = metaDataObj.subCategories
- const testRolesResponse = await testingApi.fetchTestRoles()
+
+
+ let testRolesResponse
+ if(runTestModalData.testRolesResponse != null) {
+ testRolesResponse = runTestModalData.testRolesResponse
+ } else {
+ testRolesResponse = await testingApi.fetchTestRoles()
+ tempRunTestModalData = {
+ ...tempRunTestModalData,
+ testRolesResponse
+ }
+ }
var testRoles = testRolesResponse.testRoles.map(testRole => {
return {
"label": testRole.name,
@@ -152,7 +165,16 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
//Auth Mechanism
let authMechanismPresent = false
- const authMechanismDataResponse = await testingApi.fetchAuthMechanismData()
+ let authMechanismDataResponse
+ if(runTestModalData.authMechanismDataResponse != null) {
+ authMechanismDataResponse = runTestModalData.authMechanismDataResponse
+ } else {
+ authMechanismDataResponse = await testingApi.fetchAuthMechanismData()
+ tempRunTestModalData = {
+ ...tempRunTestModalData,
+ authMechanismDataResponse
+ }
+ }
if (authMechanismDataResponse.authMechanism)
authMechanismPresent = true
@@ -165,6 +187,10 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
authMechanismPresent: authMechanismPresent
}))
+ if(tempRunTestModalData != null && Object.keys(tempRunTestModalData).length > 0) {
+ setRunTestModalData(tempRunTestModalData)
+ }
+
setLoading(false)
}
diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js
index 3723ec584..4cda33255 100644
--- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js
+++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js
@@ -22,6 +22,11 @@ let observeStore = (set)=>({
setSelectedUrl:(selectedUrl)=>{
set({selectedUrl: selectedUrl})
},
+
+ runTestModalData: {},
+ setRunTestModalData: (runTestModalData)=>{
+ set({runTestModalData: runTestModalData})
+ }
})
observeStore = devtools(observeStore)