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

feat: pass field to FormlyFieldConfigPresetProvider.getConfiguration #3594

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

Conversation

MaxKless
Copy link
Collaborator

@MaxKless MaxKless commented Feb 14, 2023

refer to #3456 for details

@aitboudad the problem is that reverseDeepMerge completely ignores arrays, which sucks for the fieldGroup merging use case. So I copied and modified it to also handle arrays.

@netlify
Copy link

netlify bot commented Feb 14, 2023

Deploy Preview for formly-dev ready!

Name Link
🔨 Latest commit dbdbd54
🔍 Latest deploy log https://app.netlify.com/sites/formly-dev/deploys/63eba4a5f391f30008a01b68
😎 Deploy Preview https://deploy-preview-3594--formly-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@MaxKless MaxKless force-pushed the feat/fieldgroup-presets branch 3 times, most recently from 24cf3bf to 1c8846d Compare February 14, 2023 15:01
Copy link
Member

@aitboudad aitboudad left a comment

Choose a reason for hiding this comment

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

I think its better to keep the reverseDeepMerge, for two main reasons:

  1. It may introduce a breaking change
  2. The order of merging an array is relevant for some use-case and that's why I do prefer to let user decide how to merge their data.

@MaxKless
Copy link
Collaborator Author

If I keep reverseDeepMerge as it is, this example you provided won't work anymore:

export class AdressPresetProvider {
    constructor(@Inject(ADDRESS_OPTIONS) private adressOptions: string[]) {}
    getConfiguration(f: FormlyFieldConfig): FormlyFieldConfig {
        return {
          fieldGroup: [ 
            { key: 'province', ... },
            { key: 'city', ... },
            ...f.fieldGroup,
          ]
        }
    }
}

I put some logs into preset-subsitution.extension.ts to show what's happening:
image

you can see that the preset merges the fieldGroup correctly but it's ignored by reverseDeepMerge.

Do you have a proposal for how to solve this?

@aitboudad
Copy link
Member

I see, so it seems a blocking part for now anyway I'll try to further check later and let you know if I find something!

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

Successfully merging this pull request may close these issues.

None yet

2 participants