From 7d56d5b39e2f83a73b1c23fd99393eaa4e283e3a Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 3 Mar 2023 15:33:44 +0100 Subject: [PATCH] :bug: (sheets) Correctly parse variables when getting data --- .../integrations/googleSheets/googleSheets.spec.ts | 4 +++- .../integrations/googleSheets/api/utils/getRow.ts | 6 ++++-- .../integrations/googleSheets/api/utils/updateRow.ts | 11 +++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/builder/src/features/blocks/integrations/googleSheets/googleSheets.spec.ts b/apps/builder/src/features/blocks/integrations/googleSheets/googleSheets.spec.ts index 62ec180075b..d4ff9a99da9 100644 --- a/apps/builder/src/features/blocks/integrations/googleSheets/googleSheets.spec.ts +++ b/apps/builder/src/features/blocks/integrations/googleSheets/googleSheets.spec.ts @@ -136,7 +136,9 @@ test.describe.parallel('Google sheets integration', () => { .press('Enter') await expect( page.locator('typebot-standard').locator('text=Your name is:') - ).toHaveText(/John|Fred|Georges/) + ).toHaveText( + `Your name is: ["Georges","John","Fred","Georges","Georges"] ["Last name","Smith","Smith"]` + ) }) }) diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/getRow.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/getRow.ts index 5851ca49e11..719e76b8869 100644 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/getRow.ts +++ b/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/getRow.ts @@ -8,7 +8,7 @@ import { } from 'models' import { saveErrorLog } from '@/features/logs/api' import { getAuthenticatedGoogleDoc } from './helpers' -import { updateVariables } from '@/features/variables' +import { deepParseVariable, updateVariables } from '@/features/variables' import { isNotEmpty, byId, isDefined } from 'utils' import { ExecuteIntegrationResponse } from '@/features/chat' import type { GoogleSpreadsheetRow } from 'google-spreadsheet' @@ -20,7 +20,9 @@ export const getRow = async ( options, }: { outgoingEdgeId?: string; options: GoogleSheetsGetOptions } ): Promise => { - const { sheetId, cellsToExtract, referenceCell, filter } = options + const { sheetId, cellsToExtract, referenceCell, filter } = deepParseVariable( + state.typebot.variables + )(options) if (!sheetId) return { outgoingEdgeId } let log: ReplyLog | undefined diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/updateRow.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/updateRow.ts index d84fe002653..6aebc4393f1 100644 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/updateRow.ts +++ b/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/updateRow.ts @@ -2,7 +2,7 @@ import { SessionState, GoogleSheetsUpdateRowOptions, ReplyLog } from 'models' import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' import { getAuthenticatedGoogleDoc, parseCellValues } from './helpers' import { TRPCError } from '@trpc/server' -import { parseVariables } from '@/features/variables' +import { deepParseVariable } from '@/features/variables' import { ExecuteIntegrationResponse } from '@/features/chat' export const updateRow = async ( @@ -12,7 +12,7 @@ export const updateRow = async ( options, }: { outgoingEdgeId?: string; options: GoogleSheetsUpdateRowOptions } ): Promise => { - const { sheetId, referenceCell } = options + const { sheetId, referenceCell } = deepParseVariable(variables)(options) if (!options.cellsToUpsert || !sheetId || !referenceCell) return { outgoingEdgeId } @@ -23,10 +23,6 @@ export const updateRow = async ( spreadsheetId: options.spreadsheetId, }) - const parsedReferenceCell = { - column: referenceCell.column, - value: parseVariables(variables)(referenceCell.value), - } const parsedValues = parseCellValues(variables)(options.cellsToUpsert) try { @@ -34,8 +30,7 @@ export const updateRow = async ( const sheet = doc.sheetsById[sheetId] const rows = await sheet.getRows() const updatingRowIndex = rows.findIndex( - (row) => - row[parsedReferenceCell.column as string] === parsedReferenceCell.value + (row) => row[referenceCell.column as string] === referenceCell.value ) if (updatingRowIndex === -1) { new TRPCError({