Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions plugins/google-sheets/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { framer } from "framer-plugin"
import { useEffect, useLayoutEffect, useState } from "react"
import {
CollectionFieldType,
getPluginContext,
PluginContext,
PluginContextUpdate,
Expand Down Expand Up @@ -166,6 +167,14 @@ export function App({ pluginContext }: AppProps) {
} = context
const [headerRow] = sheet.values

const colFieldTypes: Record<string, CollectionFieldType> = {}

// Determine if the field type is already configured, otherwise default to "string"
for (const colName of headerRow) {
const field = fields.find(field => field?.name === colName)
colFieldTypes[colName] = field?.type ?? "string"
}

syncSheet({
ignoredColumns,
slugColumn,
Expand All @@ -174,11 +183,7 @@ export function App({ pluginContext }: AppProps) {
spreadsheetId,
sheetTitle,
fields,
// Determine if the field type is already configured, otherwise default to "string"
colFieldTypes: headerRow.map(colName => {
const field = fields.find(field => field?.name === colName)
return field?.type ?? "string"
}),
colFieldTypes,
}).then(() => framer.closePlugin())
}, [context, shouldSyncOnly])

Expand Down
8 changes: 7 additions & 1 deletion plugins/google-sheets/src/pages/MapSheetFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,17 @@ export function MapSheetFieldsPage({
return field
})

const colFieldTypes: Record<string, CollectionFieldType> = {}

for (const field of allFields) {
colFieldTypes[field.id] = field.type
}

onSubmit({
fields: allFields,
spreadsheetId,
sheetTitle,
colFieldTypes: fieldConfig.map(field => field.type ?? "string"),
colFieldTypes,
ignoredColumns: Array.from(disabledColumns),
slugColumn,
lastSyncedTime: getLastSyncedTime(pluginContext, slugColumn),
Expand Down
33 changes: 18 additions & 15 deletions plugins/google-sheets/src/sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export interface SyncResult extends SyncStatus {
}

interface ProcessSheetRowParams {
fieldTypes: CollectionFieldType[]
fieldTypes: Record<string, CollectionFieldType>
row: Row
rowIndex: number
uniqueHeaderRowNames: string[]
Expand All @@ -275,7 +275,7 @@ export interface SyncMutationOptions {
fields: ManagedCollectionField[]
slugColumn: string | null
ignoredColumns: string[]
colFieldTypes: CollectionFieldType[]
colFieldTypes: Record<string, CollectionFieldType>
lastSyncedTime: string | null
}

Expand Down Expand Up @@ -331,7 +331,11 @@ function getFieldValue(fieldType: CollectionFieldType, cellValue: CellValue) {
case "formattedText":
case "color":
case "string": {
return String(cellValue)
if (typeof cellValue === "string") {
return cellValue
}

return ""
}
default:
return null
Expand All @@ -355,18 +359,7 @@ function processSheetRow({
for (const [colIndex, cell] of row.entries()) {
if (ignoredFieldColumnIndexes.includes(colIndex)) continue

// +1 as zero-indexed, another +1 to account for header row
const location = columnToLetter(colIndex + 1) + (rowIndex + 2)

const fieldValue = getFieldValue(fieldTypes[colIndex], cell)

if (fieldValue === null) {
status.warnings.push({
rowIndex,
message: `Invalid cell value at ${location}.`,
})
continue
}
const fieldValue = getFieldValue(fieldTypes[uniqueHeaderRowNames[colIndex]], cell)

if (colIndex === slugFieldColumnIndex) {
if (typeof fieldValue !== "string") {
Expand All @@ -392,6 +385,16 @@ function processSheetRow({
return null
}

for (const headerRowName of uniqueHeaderRowNames) {
if (!(headerRowName in fieldData)) {
if (["string", "formattedText"].includes(fieldTypes[headerRowName])) {
fieldData[headerRowName] = ""
} else {
fieldData[headerRowName] = null
}
}
}
Comment on lines +388 to +396
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait why are we not just omitting these values? It's not required that you pass values for all fields.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing so would keep the previously set value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That feels like we made a bad design decision there 🤔

Copy link
Member Author

@triozer triozer Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So yeah, this won't unset the value but just keep it as is

const managedCollection = await framer.getActiveManagedCollection()

await managedCollection.addItems([
  {
    id: "test",
    slug: "test",
    fieldData: {
      "First Name": {
         type: "string",
         value: "John",
      },
    },
  },
])

await managedCollection.addItems([{ id: "test", slug: "test", fieldData: {} }])


return {
id: itemId,
slug: slugValue,
Expand Down