Skip to content

Commit f303e8f

Browse files
committed
Use empty string for strings field
1 parent 1206f05 commit f303e8f

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

plugins/google-sheets/src/App.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { framer } from "framer-plugin"
22
import { useEffect, useLayoutEffect, useState } from "react"
33
import {
4+
CollectionFieldType,
45
getPluginContext,
56
PluginContext,
67
PluginContextUpdate,
@@ -166,6 +167,14 @@ export function App({ pluginContext }: AppProps) {
166167
} = context
167168
const [headerRow] = sheet.values
168169

170+
const colFieldTypes: Record<string, CollectionFieldType> = {}
171+
172+
// Determine if the field type is already configured, otherwise default to "string"
173+
for (const colName of headerRow) {
174+
const field = fields.find(field => field?.name === colName)
175+
colFieldTypes[colName] = field?.type ?? "string"
176+
}
177+
169178
syncSheet({
170179
ignoredColumns,
171180
slugColumn,
@@ -174,11 +183,7 @@ export function App({ pluginContext }: AppProps) {
174183
spreadsheetId,
175184
sheetTitle,
176185
fields,
177-
// Determine if the field type is already configured, otherwise default to "string"
178-
colFieldTypes: headerRow.map(colName => {
179-
const field = fields.find(field => field?.name === colName)
180-
return field?.type ?? "string"
181-
}),
186+
colFieldTypes,
182187
}).then(() => framer.closePlugin())
183188
}, [context, shouldSyncOnly])
184189

plugins/google-sheets/src/pages/MapSheetFields.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,17 @@ export function MapSheetFieldsPage({
222222
return field
223223
})
224224

225+
const colFieldTypes: Record<string, CollectionFieldType> = {}
226+
227+
for (const field of allFields) {
228+
colFieldTypes[field.id] = field.type
229+
}
230+
225231
onSubmit({
226232
fields: allFields,
227233
spreadsheetId,
228234
sheetTitle,
229-
colFieldTypes: fieldConfig.map(field => field.type ?? "string"),
235+
colFieldTypes,
230236
ignoredColumns: Array.from(disabledColumns),
231237
slugColumn,
232238
lastSyncedTime: getLastSyncedTime(pluginContext, slugColumn),

plugins/google-sheets/src/sheets.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export interface SyncResult extends SyncStatus {
258258
}
259259

260260
interface ProcessSheetRowParams {
261-
fieldTypes: CollectionFieldType[]
261+
fieldTypes: Record<string, CollectionFieldType>
262262
row: Row
263263
rowIndex: number
264264
uniqueHeaderRowNames: string[]
@@ -275,7 +275,7 @@ export interface SyncMutationOptions {
275275
fields: ManagedCollectionField[]
276276
slugColumn: string | null
277277
ignoredColumns: string[]
278-
colFieldTypes: CollectionFieldType[]
278+
colFieldTypes: Record<string, CollectionFieldType>
279279
lastSyncedTime: string | null
280280
}
281281

@@ -331,7 +331,11 @@ function getFieldValue(fieldType: CollectionFieldType, cellValue: CellValue) {
331331
case "formattedText":
332332
case "color":
333333
case "string": {
334-
return String(cellValue)
334+
if (typeof cellValue === "string") {
335+
return cellValue
336+
}
337+
338+
return ""
335339
}
336340
default:
337341
return null
@@ -355,18 +359,7 @@ function processSheetRow({
355359
for (const [colIndex, cell] of row.entries()) {
356360
if (ignoredFieldColumnIndexes.includes(colIndex)) continue
357361

358-
// +1 as zero-indexed, another +1 to account for header row
359-
const location = columnToLetter(colIndex + 1) + (rowIndex + 2)
360-
361-
const fieldValue = getFieldValue(fieldTypes[colIndex], cell)
362-
363-
if (fieldValue === null) {
364-
status.warnings.push({
365-
rowIndex,
366-
message: `Invalid cell value at ${location}.`,
367-
})
368-
continue
369-
}
362+
const fieldValue = getFieldValue(fieldTypes[uniqueHeaderRowNames[colIndex]], cell)
370363

371364
if (colIndex === slugFieldColumnIndex) {
372365
if (typeof fieldValue !== "string") {
@@ -394,7 +387,11 @@ function processSheetRow({
394387

395388
for (const headerRowName of uniqueHeaderRowNames) {
396389
if (!(headerRowName in fieldData)) {
397-
fieldData[headerRowName] = null
390+
if (["string", "formattedText"].includes(fieldTypes[headerRowName])) {
391+
fieldData[headerRowName] = ""
392+
} else {
393+
fieldData[headerRowName] = null
394+
}
398395
}
399396
}
400397

0 commit comments

Comments
 (0)