Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check for props in parser func #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/utils/queries.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { limitResponse } from './utils'

export function getAllQueries (dbUrl) {
return {
'id-regex': {
Expand All @@ -13,7 +15,7 @@ export function getAllQueries (dbUrl) {
// tip: chrome dev tools, right-click on logged object, store as global variable
console.log(response)
// limit doc length to display so we don't crash the browser
return Object.assign({}, response, { docs: response.docs.slice(0, 50) })
return limitResponse(response, 0, 50)
},
startRow: 6,
startColumn: 19
Expand All @@ -31,7 +33,7 @@ export function getAllQueries (dbUrl) {
// tip: chrome dev tools, right-click on logged object, store as global variable
console.log(response)
// limit doc length to display so we don't crash the browser
return Object.assign({}, response, { docs: response.rows.slice(0, 50) })
return limitResponse(response, 0, 50)
},
startRow: 5,
startColumn: 25
Expand Down Expand Up @@ -84,7 +86,7 @@ export function getAllQueries (dbUrl) {
// tip: chrome dev tools, right-click on logged object, store as global variable
console.log(response)
// limit doc length to display so we don't crash the browser
return Object.assign({}, response, { docs: response.rows.slice(0, 50) })
return limitResponse(response, 0, 50)
},
startRow: 5,
startColumn: 25
Expand Down
21 changes: 21 additions & 0 deletions app/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,24 @@ export const debounce = (callback, time = 950) => {
}, time)
}
}

export const limitResponse = (response, start = 0, end = 50) => {
let responseRows
if (Array.isArray(response)) {
responseRows = response
}
if (!Array.isArray(response) && typeof response === 'object') {
if (response.docs) {
responseRows = response.docs
}

if (response.rows) {
responseRows = response.rows
}
}
if (!Array.isArray(responseRows)) {
console.log('Invalid Response: ', response)
return response
}
return Object.assign({}, response, { docs: responseRows.slice(0, 50) })
}