2
0

🐛 (results) Fix export results when more than 200

This commit is contained in:
Baptiste Arnaud
2022-11-21 14:49:03 +01:00
parent fbd33046a1
commit 8c15fd17a1
3 changed files with 14 additions and 16 deletions

View File

@ -62,16 +62,17 @@ export const ResultsActionButtons = ({
const getAllTableData = async () => { const getAllTableData = async () => {
if (!workspaceId || !typebotId) return [] if (!workspaceId || !typebotId) return []
const allResults = [] const allResults = []
let cursor: string | undefined | null let cursor: string | undefined
do { do {
try { try {
const { results, nextCursor } = const { results, nextCursor } =
await trpcContext.results.getResults.fetch({ await trpcContext.results.getResults.fetch({
typebotId, typebotId,
limit: '200', limit: '200',
cursor,
}) })
allResults.push(...results) allResults.push(...results)
cursor = nextCursor cursor = nextCursor ?? undefined
} catch (error) { } catch (error) {
showToast({ description: (error as TRPCError).message }) showToast({ description: (error as TRPCError).message })
} }

View File

@ -24,7 +24,7 @@ import { ResultsActionButtons } from './ResultsActionButtons'
import { Row } from './Row' import { Row } from './Row'
import { HeaderRow } from './HeaderRow' import { HeaderRow } from './HeaderRow'
import { CellValueType, TableData } from '../../types' import { CellValueType, TableData } from '../../types'
import { HeaderIcon } from '../../utils' import { HeaderIcon, parseAccessor } from '../../utils'
import { IndeterminateCheckbox } from './IndeterminateCheckbox' import { IndeterminateCheckbox } from './IndeterminateCheckbox'
type ResultsTableProps = { type ResultsTableProps = {
@ -111,7 +111,7 @@ export const ResultsTable = ({
}, },
...resultHeader.map<ColumnDef<TableData>>((header) => ({ ...resultHeader.map<ColumnDef<TableData>>((header) => ({
id: header.id, id: header.id,
accessorKey: header.label, accessorKey: parseAccessor(header.label),
size: 200, size: 200,
header: () => ( header: () => (
<HStack overflow="hidden" data-testid={`${header.label} header`}> <HStack overflow="hidden" data-testid={`${header.label} header`}>
@ -120,14 +120,9 @@ export const ResultsTable = ({
</HStack> </HStack>
), ),
cell: (info) => { cell: (info) => {
try { const value = info?.getValue() as CellValueType | undefined
const value = info?.getValue() as CellValueType | undefined if (!value) return
if (!value) return return value.element || value.plainText || ''
return value.element || value.plainText || ''
} catch (err) {
console.error(err)
return
}
}, },
})), })),
{ {

View File

@ -20,7 +20,9 @@ export const parseDateToReadable = (date: Date): string =>
minute: '2-digit', minute: '2-digit',
}) })
export const parseSubmissionsColumns = ( export const parseAccessor = (label: string) => label.replaceAll('.', '')
export const parseHeaderCells = (
resultHeader: ResultHeaderCell[] resultHeader: ResultHeaderCell[]
): HeaderCell[] => ): HeaderCell[] =>
resultHeader.map((header) => ({ resultHeader.map((header) => ({
@ -30,7 +32,7 @@ export const parseSubmissionsColumns = (
<Text>{header.label}</Text> <Text>{header.label}</Text>
</HStack> </HStack>
), ),
accessor: header.label, accessor: parseAccessor(header.label),
})) }))
export const HeaderIcon = ({ header }: { header: ResultHeaderCell }) => export const HeaderIcon = ({ header }: { header: ResultHeaderCell }) =>
@ -66,7 +68,7 @@ export const convertResultsToTableData = (
if (!header || !header.blocks || !header.blockType) return o if (!header || !header.blocks || !header.blockType) return o
return { return {
...o, ...o,
[header.label]: { [parseAccessor(header.label)]: {
element: parseContent(answer.content, header.blockType), element: parseContent(answer.content, header.blockType),
plainText: answer.content, plainText: answer.content,
}, },
@ -80,7 +82,7 @@ export const convertResultsToTableData = (
if (isDefined(o[key])) return o if (isDefined(o[key])) return o
return { return {
...o, ...o,
[key]: { plainText: variable.value?.toString() }, [parseAccessor(key)]: { plainText: variable.value?.toString() },
} }
}, {}), }, {}),
})) }))