fix(keap): share contact field schema across mapping refresh#162
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Keap integration by moving the contactFields array to an exported constant and integrating it into the configuration refresh logic. Feedback indicates that importing this constant into KeapCommonFunc.js creates a circular dependency that should be resolved by moving shared constants to a separate file. Additionally, the assignment of contactFields should be moved outside the conditional block to ensure the configuration is updated regardless of whether custom fields are present.
| @@ -1,5 +1,6 @@ | |||
| import { __, sprintf } from '../../../Utils/i18nwrap' | |||
| import bitsFetch from '../../../Utils/bitsFetch' | |||
| import { contactFields } from './Keap' | |||
There was a problem hiding this comment.
This import introduces a circular dependency because Keap.jsx already imports from KeapCommonFunc.js. Since contactFields is defined at the bottom of Keap.jsx, it may be undefined when this module is evaluated due to the way ESM handles circular bindings with const. It is highly recommended to move contactFields to a separate constants file or directly into KeapCommonFunc.js to break the cycle and ensure the variable is available at runtime.
| if (result.data) { | ||
| newConf.contactFields = contactFields | ||
| newConf.customFields = result.data | ||
| } |
There was a problem hiding this comment.
The contactFields (base fields) should be updated regardless of whether custom fields are returned. This ensures that the integration always uses the latest base field schema defined in the code, even if no custom fields are present or if the API returns an empty response. Moving this assignment outside the conditional block also ensures that generateMappedField (called on line 203) always has access to the updated field definitions.
| if (result.data) { | |
| newConf.contactFields = contactFields | |
| newConf.customFields = result.data | |
| } | |
| newConf.contactFields = contactFields | |
| if (result.data) { | |
| newConf.customFields = result.data | |
| } |
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
There was a problem hiding this comment.
Pull request overview
This PR aims to keep Keap field mappings consistent by centralizing the base contact field schema and reusing it when refreshing Keap custom fields, preventing mapping drift during integration setup.
Changes:
- Moved the base Keap
contactFieldsschema to a shared exported constant. - Updated the custom-field refresh flow to re-apply base
contactFieldsbefore regeneratingfield_map.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| frontend/src/components/AllIntegrations/Keap/KeapCommonFunc.js | Reuses a shared contactFields source during custom field refresh before regenerating mappings. |
| frontend/src/components/AllIntegrations/Keap/Keap.jsx | Removes inline contactFields definition and exports it for reuse elsewhere. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,5 +1,6 @@ | |||
| import { __, sprintf } from '../../../Utils/i18nwrap' | |||
| import bitsFetch from '../../../Utils/bitsFetch' | |||
| import { contactFields } from './Keap' | |||
| export default Keap | ||
|
|
||
|
|
||
| export const contactFields = [ | ||
| { key: 'given_name', label: __('First Name', 'bit-integrations'), required: true }, | ||
| { key: 'middle_name', label: __('Middle Name', 'bit-integrations'), required: false }, | ||
| { key: 'family_name', label: __('Last Name', 'bit-integrations'), required: false }, |
Description
This PR fixes Keap field mapping consistency by centralizing contact field definitions and reusing them during custom field refresh. It prevents mapping drift when users reload Keap custom fields in integration setup.
Motivation & Context
Keap contact field metadata was defined inside the component only, so refresh flows could miss or desync base contact fields. Exporting and reusing one shared source keeps mapping stable and avoids configuration confusion.
Related Links: (if applicable)
Type of Change
Key Changes
Integrations
Frontend
contactFieldsdefinition instead of local inline duplication.Checklist
Changelog