2
0

🚸 (webhook) Also add atomic deep keys selection

This commit is contained in:
Baptiste Arnaud
2023-03-02 11:34:57 +01:00
parent 506fe003d1
commit 73f4846e1b
2 changed files with 39 additions and 8 deletions

View File

@ -130,7 +130,39 @@ export const WebhookSettings = ({
if (error)
return showToast({ title: error.name, description: error.message })
setTestResponse(JSON.stringify(data, undefined, 2))
setResponseKeys(getDeepKeys(data))
setResponseKeys(
getDeepKeys({
employees: [
{
name: 'Shyam',
email: 'shyamjaiswal@gmail.com',
employees: [
{ name: 'Shyam', email: 'shyamjaiswal@gmail.com' },
{ name: 'Bob', email: 'bob32@gmail.com' },
{ name: 'Jai', email: 'jai87@gmail.com' },
],
},
{
name: 'Bob',
email: 'bob32@gmail.com',
employees: [
{ name: 'Shyam', email: 'shyamjaiswal@gmail.com' },
{ name: 'Bob', email: 'bob32@gmail.com' },
{ name: 'Jai', email: 'jai87@gmail.com' },
],
},
{
name: 'Jai',
email: 'jai87@gmail.com',
employees: [
{ name: 'Shyam', email: 'shyamjaiswal@gmail.com' },
{ name: 'Bob', email: 'bob32@gmail.com' },
{ name: 'Jai', email: 'jai87@gmail.com' },
],
},
],
})
)
setIsTestResponseLoading(false)
}

View File

@ -11,19 +11,18 @@ export const getDeepKeys = (obj: any): string[] => {
)
} else if (Array.isArray(obj[key])) {
if (obj[key].length === 0) continue
if (obj[key].length === 1) {
const subkeys = getDeepKeys(obj[key][0])
const subkeys = getDeepKeys(obj[key][0])
if (obj[key].length > 1) {
keys = keys.concat(
subkeys.map(function (subkey) {
return `${key}[0]${parseKey(subkey)}`
return `${key}.flatMap(item => item${parseKey(subkey)})`
})
)
continue
}
const subkeys = getDeepKeys(obj[key][0])
keys = keys.concat(
subkeys.map(function (subkey) {
return `${key}.flatMap(item => item${parseKey(subkey)})`
subkeys.map(function (subkey, idx) {
return `${key}[${idx}]${parseKey(subkey)}`
})
)
} else {