Skip to content

Commit 709abde

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

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

plugins/google-sheets/src/App.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,13 @@ export function App({ pluginContext }: AppProps) {
175175
sheetTitle,
176176
fields,
177177
// Determine if the field type is already configured, otherwise default to "string"
178-
colFieldTypes: headerRow.map(colName => {
178+
colFieldTypes: headerRow.reduce((acc, colName) => {
179179
const field = fields.find(field => field?.name === colName)
180-
return field?.type ?? "string"
181-
}),
180+
return {
181+
...acc,
182+
[colName]: field?.type ?? "string",
183+
}
184+
}, {}),
182185
}).then(() => framer.closePlugin())
183186
}, [context, shouldSyncOnly])
184187

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,13 @@ export function MapSheetFieldsPage({
226226
fields: allFields,
227227
spreadsheetId,
228228
sheetTitle,
229-
colFieldTypes: fieldConfig.map(field => field.type ?? "string"),
229+
colFieldTypes: fieldConfig.reduce(
230+
(acc, field) => ({
231+
...acc,
232+
[field.id]: field.type,
233+
}),
234+
{}
235+
),
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)