Fix dynamic variable deletion and move utils
This commit is contained in:
parent
ab77c081bd
commit
5dc6917fb2
|
@ -120,62 +120,6 @@ export function flipHeaderState(headersActivity) {
|
||||||
return enabled
|
return enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert dynamic variables list to simple key/val object
|
|
||||||
export function getDynamicVariables(datasource, queryId) {
|
|
||||||
const variablesList = datasource?.config?.dynamicVariables
|
|
||||||
if (variablesList && variablesList.length > 0) {
|
|
||||||
const filtered = queryId
|
|
||||||
? variablesList.filter(variable => variable.queryId === queryId)
|
|
||||||
: variablesList
|
|
||||||
return filtered.reduce(
|
|
||||||
(acc, next) => ({ ...acc, [next.name]: next.value }),
|
|
||||||
{}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert dynamic variables object back to a list, enrich with query id
|
|
||||||
export function rebuildVariables(datasource, queryId, variables) {
|
|
||||||
let newVariables = []
|
|
||||||
if (variables) {
|
|
||||||
newVariables = Object.entries(variables).map(entry => {
|
|
||||||
return {
|
|
||||||
name: entry[0],
|
|
||||||
value: entry[1],
|
|
||||||
queryId,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
let existing = datasource?.config?.dynamicVariables || []
|
|
||||||
// filter out any by same name
|
|
||||||
existing = existing.filter(
|
|
||||||
variable =>
|
|
||||||
!newVariables.find(
|
|
||||||
newVar => newVar.name.toLowerCase() === variable.name.toLowerCase()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return [...existing, ...newVariables]
|
|
||||||
}
|
|
||||||
|
|
||||||
export function shouldShowVariables(dynamicVariables, variablesReadOnly) {
|
|
||||||
return !!(
|
|
||||||
dynamicVariables &&
|
|
||||||
// show when editable or when read only and not empty
|
|
||||||
(!variablesReadOnly || Object.keys(dynamicVariables).length > 0)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildAuthConfigs(datasource) {
|
|
||||||
if (datasource?.config?.authConfigs) {
|
|
||||||
return datasource.config.authConfigs.map(c => ({
|
|
||||||
label: c.name,
|
|
||||||
value: c._id,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
breakQueryString,
|
breakQueryString,
|
||||||
buildQueryString,
|
buildQueryString,
|
||||||
|
@ -184,8 +128,4 @@ export default {
|
||||||
keyValueToQueryParameters,
|
keyValueToQueryParameters,
|
||||||
queryParametersToKeyValue,
|
queryParametersToKeyValue,
|
||||||
schemaToFields,
|
schemaToFields,
|
||||||
getDynamicVariables,
|
|
||||||
rebuildVariables,
|
|
||||||
shouldShowVariables,
|
|
||||||
buildAuthConfigs,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,13 +52,10 @@
|
||||||
$: checkQueryName(url)
|
$: checkQueryName(url)
|
||||||
$: responseSuccess = response?.info?.code >= 200 && response?.info?.code < 400
|
$: responseSuccess = response?.info?.code >= 200 && response?.info?.code < 400
|
||||||
$: isGet = query?.queryVerb === "read"
|
$: isGet = query?.queryVerb === "read"
|
||||||
$: authConfigs = restUtils.buildAuthConfigs(datasource)
|
$: authConfigs = buildAuthConfigs(datasource)
|
||||||
$: schemaReadOnly = !responseSuccess
|
$: schemaReadOnly = !responseSuccess
|
||||||
$: variablesReadOnly = !responseSuccess
|
$: variablesReadOnly = !responseSuccess
|
||||||
$: showVariablesTab = restUtils.shouldShowVariables(
|
$: showVariablesTab = shouldShowVariables(dynamicVariables, variablesReadOnly)
|
||||||
dynamicVariables,
|
|
||||||
variablesReadOnly
|
|
||||||
)
|
|
||||||
|
|
||||||
function getSelectedQuery() {
|
function getSelectedQuery() {
|
||||||
return cloneDeep(
|
return cloneDeep(
|
||||||
|
@ -115,11 +112,7 @@
|
||||||
notifications.success(`Request saved successfully.`)
|
notifications.success(`Request saved successfully.`)
|
||||||
|
|
||||||
if (dynamicVariables) {
|
if (dynamicVariables) {
|
||||||
datasource.config.dynamicVariables = restUtils.rebuildVariables(
|
datasource.config.dynamicVariables = rebuildVariables(saveId)
|
||||||
datasource,
|
|
||||||
saveId,
|
|
||||||
dynamicVariables
|
|
||||||
)
|
|
||||||
datasource = await datasources.save(datasource)
|
datasource = await datasources.save(datasource)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -158,6 +151,16 @@
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildAuthConfigs = datasource => {
|
||||||
|
if (datasource?.config?.authConfigs) {
|
||||||
|
return datasource.config.authConfigs.map(c => ({
|
||||||
|
label: c.name,
|
||||||
|
value: c._id,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
const schemaMenuItems = [
|
const schemaMenuItems = [
|
||||||
{
|
{
|
||||||
text: "Create dynamic variable",
|
text: "Create dynamic variable",
|
||||||
|
@ -177,6 +180,44 @@
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// convert dynamic variables list to simple key/val object
|
||||||
|
const getDynamicVariables = (datasource, queryId) => {
|
||||||
|
const variablesList = datasource?.config?.dynamicVariables
|
||||||
|
if (variablesList && variablesList.length > 0) {
|
||||||
|
const filtered = queryId
|
||||||
|
? variablesList.filter(variable => variable.queryId === queryId)
|
||||||
|
: variablesList
|
||||||
|
return filtered.reduce(
|
||||||
|
(acc, next) => ({ ...acc, [next.name]: next.value }),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert dynamic variables object back to a list, enrich with query id
|
||||||
|
const rebuildVariables = queryId => {
|
||||||
|
let variables = []
|
||||||
|
if (dynamicVariables) {
|
||||||
|
variables = Object.entries(dynamicVariables).map(entry => {
|
||||||
|
return {
|
||||||
|
name: entry[0],
|
||||||
|
value: entry[1],
|
||||||
|
queryId,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return variables
|
||||||
|
}
|
||||||
|
|
||||||
|
const shouldShowVariables = (dynamicVariables, variablesReadOnly) => {
|
||||||
|
return !!(
|
||||||
|
dynamicVariables &&
|
||||||
|
// show when editable or when read only and not empty
|
||||||
|
(!variablesReadOnly || Object.keys(dynamicVariables).length > 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
query = getSelectedQuery()
|
query = getSelectedQuery()
|
||||||
// clear any unsaved changes to the datasource
|
// clear any unsaved changes to the datasource
|
||||||
|
@ -214,7 +255,7 @@
|
||||||
if (query && !query.fields.bodyType) {
|
if (query && !query.fields.bodyType) {
|
||||||
query.fields.bodyType = "none"
|
query.fields.bodyType = "none"
|
||||||
}
|
}
|
||||||
dynamicVariables = restUtils.getDynamicVariables(datasource, query._id)
|
dynamicVariables = getDynamicVariables(datasource, query._id)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue