Skip to content
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

refactor: lift default value setting to the AccountSettings page #252

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

icatalina
Copy link
Contributor

@icatalina icatalina commented Feb 14, 2025

Jira: B2B-2158

What/Why?

This further separates the fetching of the field information from the data. Allowing for a cleaner API separation.

Rollout/Rollback

Revert

Testing

Manual

image

@icatalina icatalina requested review from a team as code owners February 14, 2025 16:42
Comment on lines 148 to 155
? [...contactInformation, ...additionalInformation, ...getPasswordModifiedFields()]
: [
...contactInformation,
...getAccountSettingsFields(),
...additionalInformation,
...getPasswordModifiedFields(),
];
Copy link
Contributor

Choose a reason for hiding this comment

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

when the order is the same, but something(s) are being omitted from the list, I quite like this pattern

const fields = [
  ...contactInformation,
  ...(isBCUser ? getAccountSettingsFields() : []),
  ...additionalInformation,
  ...getPasswordModifiedFields(),
];

we benefit from having one definition of the correct order, plus it's easier to focus on which aspect is conditional

the downside is it can look a bit new/unusual 🍹

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a huge fan of this pattern because of readability, but sure...

return accountInfoFormFields.map((item) => ({
...item,
default:
defaultValueMap[item.fieldId ?? ''] ??
Copy link
Contributor

Choose a reason for hiding this comment

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

aren't fieldIds mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be, but I don't trust anything anymore 😂

defaultValueMap[item.fieldId ?? ''] ??
formFields[item.bcLabel ?? ''] ??
extraFields[item.label ?? ''] ??
item.default ??
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm struggling to mentally map this one

is there a possibility of (A) multiple objects (defaultValueMap, formFields, etc) holding a value for a single item?
Or (B) would we only expect one of them to contain a value?


if (A) the ordering of the object look ups matters, e.g.
formFields[item.bcLabel] ?? extraFields[item.label] vs
extraFields[item.label] ?? formFields[item.bcLabel]


if (B) the ordering doesn't matter, as we only every expect one of them to be truth-y


at the moment I don't if we need to care about the ordering or not 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me see if I can clarify things without murking the waters even further.

The value for a specific field should only be held in one of the object.

  • defaultValueMap holds values for all 'standard' fields (firstName, lastName, etc)
  • formFields holds vales for the BC custom fields
  • extraFields holds values for B2B custom fields

There's however, the possibility of clashes. If you were to label a custom field like another one or an existing default field, there will be issues with the saving of them.

The only order that matters is that last item.default, that's the actual field's default value, and should be last in preference.

Copy link
Contributor

@leeBigCommerce leeBigCommerce Feb 20, 2025

Choose a reason for hiding this comment

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

gotcha, I guess ideally we'd go for something that makes that clearer in code, e.g.

    const defaultValuesByType = {
      defaultValueMap,
      formFields,
      extraFields,
    };

    return accountInfoFormFields.map((item) => ({
      ...item,
      default: defaultValuesByType[item.type][item.label] ?? item.default ?? '',
     // etc etc

but these types are a long way from allowing something like that (or something better)

worth a comment to explain the mutually exclusivity in the mean time?

Comment on lines -34 to -36
xs: 12,
variant: 'filled',
size: 'small',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are responsibility of the view, we probably want all fields to look the same within one page.

defaultValueMap[item.fieldId ?? ''] ??
formFields[item.bcLabel ?? ''] ??
extraFields[item.label ?? ''] ??
item.default ??
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me see if I can clarify things without murking the waters even further.

The value for a specific field should only be held in one of the object.

  • defaultValueMap holds values for all 'standard' fields (firstName, lastName, etc)
  • formFields holds vales for the BC custom fields
  • extraFields holds values for B2B custom fields

There's however, the possibility of clashes. If you were to label a custom field like another one or an existing default field, there will be issues with the saving of them.

The only order that matters is that last item.default, that's the actual field's default value, and should be last in preference.

return accountInfoFormFields.map((item) => ({
...item,
default:
defaultValueMap[item.fieldId ?? ''] ??
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be, but I don't trust anything anymore 😂

Comment on lines 148 to 155
? [...contactInformation, ...additionalInformation, ...getPasswordModifiedFields()]
: [
...contactInformation,
...getAccountSettingsFields(),
...additionalInformation,
...getPasswordModifiedFields(),
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a huge fan of this pattern because of readability, but sure...

@icatalina icatalina force-pushed the icatalina/B2B-2158/lift-default-values branch from 8486fd0 to 86b862e Compare February 19, 2025 15:27
This further separates the fetching of the field information from the
data. Allowing for a cleaner API separation.
@icatalina icatalina force-pushed the icatalina/B2B-2158/lift-default-values branch from 86b862e to f0a0a6e Compare February 19, 2025 15:32
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