2
0

🐛 (sheets) Correctly parse variables when getting data

This commit is contained in:
Baptiste Arnaud
2023-03-03 15:33:44 +01:00
parent 6cd1db7ba7
commit 7d56d5b39e
3 changed files with 10 additions and 11 deletions

View File

@@ -136,7 +136,9 @@ test.describe.parallel('Google sheets integration', () => {
.press('Enter') .press('Enter')
await expect( await expect(
page.locator('typebot-standard').locator('text=Your name is:') 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"]`
)
}) })
}) })

View File

@@ -8,7 +8,7 @@ import {
} from 'models' } from 'models'
import { saveErrorLog } from '@/features/logs/api' import { saveErrorLog } from '@/features/logs/api'
import { getAuthenticatedGoogleDoc } from './helpers' import { getAuthenticatedGoogleDoc } from './helpers'
import { updateVariables } from '@/features/variables' import { deepParseVariable, updateVariables } from '@/features/variables'
import { isNotEmpty, byId, isDefined } from 'utils' import { isNotEmpty, byId, isDefined } from 'utils'
import { ExecuteIntegrationResponse } from '@/features/chat' import { ExecuteIntegrationResponse } from '@/features/chat'
import type { GoogleSpreadsheetRow } from 'google-spreadsheet' import type { GoogleSpreadsheetRow } from 'google-spreadsheet'
@@ -20,7 +20,9 @@ export const getRow = async (
options, options,
}: { outgoingEdgeId?: string; options: GoogleSheetsGetOptions } }: { outgoingEdgeId?: string; options: GoogleSheetsGetOptions }
): Promise<ExecuteIntegrationResponse> => { ): Promise<ExecuteIntegrationResponse> => {
const { sheetId, cellsToExtract, referenceCell, filter } = options const { sheetId, cellsToExtract, referenceCell, filter } = deepParseVariable(
state.typebot.variables
)(options)
if (!sheetId) return { outgoingEdgeId } if (!sheetId) return { outgoingEdgeId }
let log: ReplyLog | undefined let log: ReplyLog | undefined

View File

@@ -2,7 +2,7 @@ import { SessionState, GoogleSheetsUpdateRowOptions, ReplyLog } from 'models'
import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' import { saveErrorLog, saveSuccessLog } from '@/features/logs/api'
import { getAuthenticatedGoogleDoc, parseCellValues } from './helpers' import { getAuthenticatedGoogleDoc, parseCellValues } from './helpers'
import { TRPCError } from '@trpc/server' import { TRPCError } from '@trpc/server'
import { parseVariables } from '@/features/variables' import { deepParseVariable } from '@/features/variables'
import { ExecuteIntegrationResponse } from '@/features/chat' import { ExecuteIntegrationResponse } from '@/features/chat'
export const updateRow = async ( export const updateRow = async (
@@ -12,7 +12,7 @@ export const updateRow = async (
options, options,
}: { outgoingEdgeId?: string; options: GoogleSheetsUpdateRowOptions } }: { outgoingEdgeId?: string; options: GoogleSheetsUpdateRowOptions }
): Promise<ExecuteIntegrationResponse> => { ): Promise<ExecuteIntegrationResponse> => {
const { sheetId, referenceCell } = options const { sheetId, referenceCell } = deepParseVariable(variables)(options)
if (!options.cellsToUpsert || !sheetId || !referenceCell) if (!options.cellsToUpsert || !sheetId || !referenceCell)
return { outgoingEdgeId } return { outgoingEdgeId }
@@ -23,10 +23,6 @@ export const updateRow = async (
spreadsheetId: options.spreadsheetId, spreadsheetId: options.spreadsheetId,
}) })
const parsedReferenceCell = {
column: referenceCell.column,
value: parseVariables(variables)(referenceCell.value),
}
const parsedValues = parseCellValues(variables)(options.cellsToUpsert) const parsedValues = parseCellValues(variables)(options.cellsToUpsert)
try { try {
@@ -34,8 +30,7 @@ export const updateRow = async (
const sheet = doc.sheetsById[sheetId] const sheet = doc.sheetsById[sheetId]
const rows = await sheet.getRows() const rows = await sheet.getRows()
const updatingRowIndex = rows.findIndex( const updatingRowIndex = rows.findIndex(
(row) => (row) => row[referenceCell.column as string] === referenceCell.value
row[parsedReferenceCell.column as string] === parsedReferenceCell.value
) )
if (updatingRowIndex === -1) { if (updatingRowIndex === -1) {
new TRPCError({ new TRPCError({