Skip to content

Conversation

@triozer
Copy link
Member

@triozer triozer commented Feb 12, 2025

Description

This pull request ensures that when a field does not have a defined value it's set to null. Allowing to clear it.

Context

https://framer-team.slack.com/archives/C06L5H5ADK2/p1739362411251979

Testing

  • Set values to null when re-syncing a spreadsheet
    • Import a spreadsheet
    • Remove any value (not the slug)
    • Re-sync the spreadsheet
    • Check that the field value is either unset or set to the default value (in case of a number)

@tom-james-watson
Copy link
Contributor

This won't work right - because we don't accept null at the moment for anything other than collection references.

@triozer triozer force-pushed the fix/sheets-clear-values branch from f947f40 to 1206f05 Compare March 10, 2025 18:23
@triozer triozer marked this pull request as ready for review March 10, 2025 18:24
@triozer
Copy link
Member Author

triozer commented Mar 10, 2025

This won't work right - because we don't accept null at the moment for anything other than collection references.

This got merged, so this works now 🕺🏽

Copy link
Contributor

@tom-james-watson tom-james-watson left a comment

Choose a reason for hiding this comment

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

Comment on lines +388 to +396
for (const headerRowName of uniqueHeaderRowNames) {
if (!(headerRowName in fieldData)) {
if (["string", "formattedText"].includes(fieldTypes[headerRowName])) {
fieldData[headerRowName] = ""
} else {
fieldData[headerRowName] = null
}
}
}
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: {} }])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants