2
0

🚸 (results) Add progress bar to export results modal

This commit is contained in:
Baptiste Arnaud
2024-01-11 10:36:48 +01:00
parent 03258e0f64
commit 5d971f7b6f
8 changed files with 62 additions and 34 deletions

View File

@@ -39,9 +39,7 @@ test.describe('Url input block', () => {
)
await page.click('text=Restart')
await page
.locator(`input[placeholder="Your URL..."]`)
.fill('https://https://test')
await page.locator(`input[placeholder="Your URL..."]`).fill('test')
await page.locator('button >> text="Go"').click()
await expect(page.locator('text=Try again bro')).toBeVisible()
await page

View File

@@ -25,7 +25,7 @@ test.describe('Condition block', () => {
await page.click('button:has-text("Greater than")', { force: true })
await page.fill('input[placeholder="Type a number..."]', '80')
await page.click('button:has-text("Add a comparison")')
await page.click('button:has-text("Add comparison")')
await page.fill(
':nth-match(input[placeholder="Search for a variable"], 2)',

View File

@@ -14,6 +14,8 @@ import {
ModalHeader,
ModalOverlay,
Stack,
Progress,
Text,
} from '@chakra-ui/react'
import { TRPCError } from '@trpc/server'
import { unparse } from 'papaparse'
@@ -35,9 +37,10 @@ export const ExportAllResultsModal = ({ isOpen, onClose }: Props) => {
const workspaceId = typebot?.workspaceId
const typebotId = typebot?.id
const { showToast } = useToast()
const { resultHeader: existingResultHeader } = useResults()
const { resultHeader: existingResultHeader, totalResults } = useResults()
const trpcContext = trpc.useContext()
const [isExportLoading, setIsExportLoading] = useState(false)
const [exportProgressValue, setExportProgressValue] = useState(0)
const [areDeletedBlocksIncluded, setAreDeletedBlocksIncluded] =
useState(false)
@@ -55,6 +58,7 @@ export const ExportAllResultsModal = ({ isOpen, onClose }: Props) => {
if (!workspaceId || !typebotId) return []
const allResults = []
let cursor: string | undefined
setExportProgressValue(0)
do {
try {
const { results, nextCursor } =
@@ -64,9 +68,11 @@ export const ExportAllResultsModal = ({ isOpen, onClose }: Props) => {
cursor,
})
allResults.push(...results)
setExportProgressValue((allResults.length / totalResults) * 100)
cursor = nextCursor ?? undefined
} catch (error) {
showToast({ description: (error as TRPCError).message })
return []
}
} while (cursor)
@@ -80,6 +86,8 @@ export const ExportAllResultsModal = ({ isOpen, onClose }: Props) => {
const results = await getAllResults()
if (!results.length) return setIsExportLoading(false)
const resultHeader = areDeletedBlocksIncluded
? parseResultHeader(
publishedTypebot,
@@ -144,7 +152,17 @@ export const ExportAllResultsModal = ({ isOpen, onClose }: Props) => {
initialValue={false}
onCheckChange={setAreDeletedBlocksIncluded}
/>
<AlertInfo>The export may take up to 1 minute.</AlertInfo>
{totalResults > 2000 ? (
<AlertInfo>The export may take a while.</AlertInfo>
) : (
<AlertInfo>The export may take up to 1 minute.</AlertInfo>
)}
{isExportLoading && (
<Stack>
<Text>Fetching all results...</Text>
<Progress value={exportProgressValue} borderRadius="md" />
</Stack>
)}
</ModalBody>
<ModalFooter as={HStack}>
<Button onClick={onClose} variant="ghost" size="sm">

View File

@@ -23,7 +23,6 @@ export type WorkspaceInApp = Omit<
| 'chatsLimitSecondEmailSentAt'
| 'storageLimitFirstEmailSentAt'
| 'storageLimitSecondEmailSentAt'
| 'customChatsLimit'
| 'customStorageLimit'
| 'additionalChatsIndex'
| 'additionalStorageIndex'

View File

@@ -31,7 +31,6 @@ export const getWorkspace = authenticatedProcedure
chatsLimitSecondEmailSentAt: true,
storageLimitFirstEmailSentAt: true,
storageLimitSecondEmailSentAt: true,
customChatsLimit: true,
customStorageLimit: true,
additionalChatsIndex: true,
additionalStorageIndex: true,