Skip to content

Commit

Permalink
🚸 (sheets) Show info log instead of error when no rows are found
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 15, 2023
1 parent b89da5b commit fbe63aa
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
7 changes: 5 additions & 2 deletions apps/builder/src/features/preview/components/WebPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ export const WebPreview = () => {
details: log.details
? {
lang: 'json',
content: JSON.stringify(log.details, null, 2),
content:
typeof log.details === 'string'
? log.details
: JSON.stringify(log.details, null, 2),
}
: undefined,
})
console.error(log)
if (log.status === 'error') console.error(log)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { saveErrorLog } from '@/features/logs/saveErrorLog'
import { updateVariables } from '@/features/variables/updateVariables'
import { deepParseVariables } from '@/features/variables/deepParseVariable'
import { matchFilter } from './helpers/matchFilter'
import { saveInfoLog } from '@/features/logs/saveInfoLog'

export const getRow = async (
state: SessionState,
Expand Down Expand Up @@ -48,10 +49,11 @@ export const getRow = async (
)
if (filteredRows.length === 0) {
log = {
status: 'error',
status: 'info',
description: `Couldn't find any rows matching the filter`,
details: JSON.stringify(filter, null, 2),
}
await saveErrorLog({
await saveInfoLog({
resultId,
message: log.description,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ExecuteIntegrationResponse } from '@/features/chat/types'
import { saveErrorLog } from '@/features/logs/saveErrorLog'
import { saveSuccessLog } from '@/features/logs/saveSuccessLog'
import { matchFilter } from './helpers/matchFilter'
import { saveInfoLog } from '@/features/logs/saveInfoLog'

export const updateRow = async (
{ result, typebot: { variables } }: SessionState,
Expand Down Expand Up @@ -42,12 +43,12 @@ export const updateRow = async (
)
if (filteredRows.length === 0) {
log = {
status: 'error',
status: 'info',
description: `Could not find any row that matches the filter`,
details: JSON.stringify(filter, null, 2),
}
result &&
(await saveErrorLog({
(await saveInfoLog({
resultId: result.id,
message: log.description,
details: log.details,
Expand Down
2 changes: 1 addition & 1 deletion apps/viewer/src/features/logs/saveErrorLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const saveErrorLog = ({
resultId: string | undefined
message: string
details?: unknown
}) => saveLog('error', resultId, message, details)
}) => saveLog({ status: 'error', resultId, message, details })
11 changes: 11 additions & 0 deletions apps/viewer/src/features/logs/saveInfoLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { saveLog } from './saveLog'

export const saveInfoLog = ({
resultId,
message,
details,
}: {
resultId: string | undefined
message: string
details?: unknown
}) => saveLog({ status: 'info', resultId, message, details })
12 changes: 7 additions & 5 deletions apps/viewer/src/features/logs/saveLog.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import prisma from '@/lib/prisma'
import { isNotDefined } from '@typebot.io/lib'

export const saveLog = (
status: 'error' | 'success',
resultId: string | undefined,
message: string,
type Props = {
status: 'error' | 'success' | 'info'
resultId: string | undefined
message: string
details?: unknown
) => {
}

export const saveLog = ({ status, resultId, message, details }: Props) => {
if (!resultId || resultId === 'undefined') return
return prisma.log.create({
data: {
Expand Down
2 changes: 1 addition & 1 deletion apps/viewer/src/features/logs/saveSuccessLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const saveSuccessLog = ({
resultId: string | undefined
message: string
details?: unknown
}) => saveLog('success', resultId, message, details)
}) => saveLog({ status: 'success', resultId, message, details })

0 comments on commit fbe63aa

Please sign in to comment.