2
0

♻️ Replace schemas with merge and discriminated unions

Closes #374
This commit is contained in:
Baptiste Arnaud
2023-03-14 16:42:12 +01:00
parent ff09814ead
commit d154c4e2f2
52 changed files with 3217 additions and 4328 deletions

View File

@ -14,7 +14,7 @@ import {
GoogleSheetsUpdateRowOptions,
} from 'models'
import React, { useMemo } from 'react'
import { isDefined, omit } from 'utils'
import { isDefined } from 'utils'
import { SheetsDropdown } from './SheetsDropdown'
import { SpreadsheetsDropdown } from './SpreadsheetDropdown'
import { CellWithValueStack } from './CellWithValueStack'
@ -50,8 +50,11 @@ export const GoogleSheetsSettingsBody = ({
() => sheets?.find((s) => s.id === options?.sheetId),
[sheets, options?.sheetId]
)
const handleCredentialsIdChange = (credentialsId?: string) =>
onOptionsChange({ ...omit(options, 'credentialsId'), credentialsId })
const handleCredentialsIdChange = (credentialsId: string | undefined) =>
onOptionsChange({
...options,
credentialsId,
})
const handleSpreadsheetIdChange = (spreadsheetId: string | undefined) =>
onOptionsChange({ ...options, spreadsheetId })
const handleSheetIdChange = (sheetId: string | undefined) =>
@ -137,7 +140,7 @@ export const GoogleSheetsSettingsBody = ({
/>
</>
)}
{'action' in options && (
{options.action && (
<ActionOptions
options={options}
sheet={sheet}

View File

@ -26,7 +26,7 @@ export const listTypebotsProcedure = authenticatedProcedure
icon: true,
id: true,
})
.and(z.object({ publishedTypebotId: z.string().optional() }))
.merge(z.object({ publishedTypebotId: z.string().optional() }))
),
})
)

View File

@ -1033,38 +1033,28 @@
"typebots": {
"type": "array",
"items": {
"allOf": [
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"icon": {
"type": "string",
"nullable": true
},
"id": {
"type": "string"
}
},
"required": [
"name",
"icon",
"id"
],
"additionalProperties": false
"type": "object",
"properties": {
"name": {
"type": "string"
},
{
"type": "object",
"properties": {
"publishedTypebotId": {
"type": "string"
}
},
"additionalProperties": false
"icon": {
"type": "string",
"nullable": true
},
"id": {
"type": "string"
},
"publishedTypebotId": {
"type": "string"
}
]
},
"required": [
"name",
"icon",
"id"
],
"additionalProperties": false
}
}
},
@ -1444,128 +1434,116 @@
"results": {
"type": "array",
"items": {
"allOf": [
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"typebotId": {
"type": "string"
},
"variables": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"value": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"required": [
"id",
"name",
"value"
],
"additionalProperties": false
}
},
"isCompleted": {
"type": "boolean"
},
"hasStarted": {
"type": "boolean",
"nullable": true
},
"isArchived": {
"type": "boolean",
"nullable": true
}
},
"required": [
"id",
"createdAt",
"typebotId",
"variables",
"isCompleted",
"hasStarted",
"isArchived"
],
"additionalProperties": false
"type": "object",
"properties": {
"id": {
"type": "string"
},
{
"type": "object",
"properties": {
"answers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"createdAt": {
"type": "string",
"format": "date-time"
},
"resultId": {
"createdAt": {
"type": "string",
"format": "date-time"
},
"typebotId": {
"type": "string"
},
"variables": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"value": {
"anyOf": [
{
"type": "string"
},
"blockId": {
"type": "string"
},
"groupId": {
"type": "string"
},
"variableId": {
"type": "string",
"nullable": true
},
"content": {
"type": "string"
},
"storageUsed": {
"type": "number",
"nullable": true
{
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"createdAt",
"resultId",
"blockId",
"groupId",
"variableId",
"content",
"storageUsed"
],
"additionalProperties": false
]
}
}
},
"required": [
"answers"
],
"additionalProperties": false
},
"required": [
"id",
"name",
"value"
],
"additionalProperties": false
}
},
"isCompleted": {
"type": "boolean"
},
"hasStarted": {
"type": "boolean",
"nullable": true
},
"isArchived": {
"type": "boolean",
"nullable": true
},
"answers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"createdAt": {
"type": "string",
"format": "date-time"
},
"resultId": {
"type": "string"
},
"blockId": {
"type": "string"
},
"groupId": {
"type": "string"
},
"variableId": {
"type": "string",
"nullable": true
},
"content": {
"type": "string"
},
"storageUsed": {
"type": "number",
"nullable": true
}
},
"required": [
"createdAt",
"resultId",
"blockId",
"groupId",
"variableId",
"content",
"storageUsed"
],
"additionalProperties": false
}
}
]
},
"required": [
"id",
"createdAt",
"typebotId",
"variables",
"isCompleted",
"hasStarted",
"isArchived",
"answers"
],
"additionalProperties": false
}
},
"nextCursor": {

File diff suppressed because it is too large Load Diff

View File

@ -8,9 +8,9 @@ export const executeGoogleSheetBlock = async (
state: SessionState,
block: GoogleSheetsBlock
): Promise<ExecuteIntegrationResponse> => {
if (!('action' in block.options))
return { outgoingEdgeId: block.outgoingEdgeId }
switch (block.options.action) {
const action = block.options.action
if (!action) return { outgoingEdgeId: block.outgoingEdgeId }
switch (action) {
case GoogleSheetsAction.INSERT_ROW:
return insertRow(state, {
options: block.options,