Skip to content

Commit

Permalink
fix(results): 🐛 Exporting many results
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 14, 2022
1 parent e50ce64 commit 281fddc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 2 additions & 3 deletions apps/builder/layouts/results/SubmissionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ export const SubmissionsContent = ({

const getAllTableData = async () => {
if (!publishedTypebot) return []
const { data, error } = await getAllResults(typebotId)
if (error) toast({ description: error.message, title: error.name })
return convertResultsToTableData(data?.results, resultHeader)
const results = await getAllResults(typebotId)
return convertResultsToTableData(results, resultHeader)
}

const tableData: { [key: string]: string }[] = useMemo(
Expand Down
21 changes: 16 additions & 5 deletions apps/builder/services/typebots/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,22 @@ export const deleteAllResults = async (typebotId: string) =>
method: 'DELETE',
})

export const getAllResults = async (typebotId: string) =>
sendRequest<{ results: ResultWithAnswers[] }>({
url: `/api/typebots/${typebotId}/results`,
method: 'GET',
})
export const getAllResults = async (typebotId: string) => {
const results = []
let hasMore = true
let lastResultId: string | undefined = undefined
do {
const query = stringify({ limit: 200, lastResultId })
const { data } = await sendRequest<{ results: ResultWithAnswers[] }>({
url: `/api/typebots/${typebotId}/results?${query}`,
method: 'GET',
})
results.push(...(data?.results ?? []))
lastResultId = results[results.length - 1]?.id as string | undefined
if (data?.results.length === 0) hasMore = false
} while (hasMore)
return results
}

export const parseDateToReadable = (dateStr: string): string => {
const date = new Date(dateStr)
Expand Down

4 comments on commit 281fddc

@vercel
Copy link

@vercel vercel bot commented on 281fddc Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 281fddc Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 281fddc Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.