Skip to content

Explicitly set undefined column value to null #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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.

2 participants