From 5d971f7b6ff60f87a4c01144da420172c43dd24c Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 11 Jan 2024 10:36:48 +0100 Subject: [PATCH] :children_crossing: (results) Add progress bar to export results modal --- .../features/blocks/inputs/url/url.spec.ts | 4 +- .../blocks/logic/condition/condition.spec.ts | 2 +- .../table/ExportAllResultsModal.tsx | 22 +++++++- .../features/workspace/WorkspaceProvider.tsx | 1 - .../features/workspace/api/getWorkspace.ts | 1 - .../blocks/inputs/url/validateUrl.ts | 12 ++--- packages/prisma/package.json | 4 +- pnpm-lock.yaml | 50 +++++++++++++------ 8 files changed, 62 insertions(+), 34 deletions(-) diff --git a/apps/builder/src/features/blocks/inputs/url/url.spec.ts b/apps/builder/src/features/blocks/inputs/url/url.spec.ts index ae407dae7..58813472e 100644 --- a/apps/builder/src/features/blocks/inputs/url/url.spec.ts +++ b/apps/builder/src/features/blocks/inputs/url/url.spec.ts @@ -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 diff --git a/apps/builder/src/features/blocks/logic/condition/condition.spec.ts b/apps/builder/src/features/blocks/logic/condition/condition.spec.ts index c855217be..889349d50 100644 --- a/apps/builder/src/features/blocks/logic/condition/condition.spec.ts +++ b/apps/builder/src/features/blocks/logic/condition/condition.spec.ts @@ -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)', diff --git a/apps/builder/src/features/results/components/table/ExportAllResultsModal.tsx b/apps/builder/src/features/results/components/table/ExportAllResultsModal.tsx index 9391d2935..02a56d4b2 100644 --- a/apps/builder/src/features/results/components/table/ExportAllResultsModal.tsx +++ b/apps/builder/src/features/results/components/table/ExportAllResultsModal.tsx @@ -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} /> - The export may take up to 1 minute. + {totalResults > 2000 ? ( + The export may take a while. + ) : ( + The export may take up to 1 minute. + )} + {isExportLoading && ( + + Fetching all results... + + + )}