feat(integrations): add wpDataTables action with table/column mapping#166
feat(integrations): add wpDataTables action with table/column mapping#166RishadAlam wants to merge 5 commits into
Conversation
…' in WpDataTablesIntegLayout
🔍 WordPress Plugin Check Report
📊 Report
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
mismatched_plugin_name | Plugin name "Bit integrations - Form Integration, Webhook, Spreadsheets, CRM, LMS & Email Automation" is different from the name declared in plugin header "Bit Integrations". |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check
There was a problem hiding this comment.
Pull request overview
This PR adds a new wpDataTables action integration that allows flows to insert rows into a selected wpDataTables table via a table/column discovery + field-mapping UI, backed by new AJAX endpoints and execution logic.
Changes:
- Added frontend setup/edit screens for wpDataTables, including table selection, column refresh, and dynamic field mapping.
- Added backend AJAX routes/controllers to authorize wpDataTables presence and fetch tables/columns.
- Added backend execution helper to transform mapped fields and delegate “add row” behavior via hooks.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/components/Flow/New/SelectAction.jsx | Adds WpDataTables to the selectable action list. |
| frontend/src/components/AllIntegrations/WpDataTables/WpDataTables.jsx | New multi-step “new integration” flow for wpDataTables. |
| frontend/src/components/AllIntegrations/WpDataTables/WpDataTablesAuthorization.jsx | New authorization/check screen for wpDataTables activation. |
| frontend/src/components/AllIntegrations/WpDataTables/WpDataTablesIntegLayout.jsx | New action/table selection + mapping layout with refresh controls. |
| frontend/src/components/AllIntegrations/WpDataTables/WpDataTablesFieldMap.jsx | New per-row mapping component (form field/custom value → column). |
| frontend/src/components/AllIntegrations/WpDataTables/WpDataTablesCommonFunc.js | New shared helpers: validation + fetch tables/columns. |
| frontend/src/components/AllIntegrations/WpDataTables/staticData.js | Defines wpDataTables action metadata (e.g., Add Row). |
| frontend/src/components/AllIntegrations/WpDataTables/EditWpDataTables.jsx | New edit screen for existing wpDataTables actions. |
| frontend/src/components/AllIntegrations/NewInteg.jsx | Registers new integration route/rendering for wpDataTables. |
| frontend/src/components/AllIntegrations/EditInteg.jsx | Registers edit route/rendering for wpDataTables. |
| frontend/src/components/AllIntegrations/IntegInfo.jsx | Adds wpDataTables to Integration Info rendering. |
| backend/Core/Util/AllTriggersName.php | Registers wpDataTables in the (pro) integration name registry. |
| backend/Actions/WpDataTables/Routes.php | Registers AJAX routes for authorize/tables/columns. |
| backend/Actions/WpDataTables/WpDataTablesController.php | Implements authorize + table/column discovery + integration execute entrypoint. |
| backend/Actions/WpDataTables/RecordApiHelper.php | Implements execution mapping + hook-based add-row dispatch + logging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { checkIsPro, getProLabel } from '../../Utilities/ProUtilHelpers' | ||
| import { addFieldMap } from '../IntegrationHelpers/IntegrationHelpers' | ||
| import { | ||
| generateMappedField, |
There was a problem hiding this comment.
Removed the unused generateMappedField import from WpDataTablesIntegLayout.jsx.
| case 'WpDataTables': | ||
| return <WpDataTablesAuthorization wpDataTablesConf={integrationConf} step={1} isInfo /> |
There was a problem hiding this comment.
Fixed by adding isInfo support to WpDataTablesAuthorization. When isInfo is true, the name input is disabled and the Connect/Next buttons are hidden — matching the pattern used by other auth components (e.g. AutonamiAuthorization). No additional props need to be passed at the IntegInfo.jsx call site.
| setSnackbar | ||
| }) { | ||
| const [isAuthorized, setIsAuthorized] = useState(false) | ||
| const [showAuthMsg, setShowAuthMsg] = useState(false) | ||
|
|
||
| const authorizeHandler = () => { | ||
| setIsLoading('auth') | ||
| bitsFetch({}, 'wp_data_tables_authorize').then(result => { | ||
| if (result?.success) { | ||
| setIsAuthorized(true) | ||
| setSnackbar({ | ||
| show: true, | ||
| msg: __('Connected with wpDataTables Successfully', 'bit-integrations') | ||
| }) | ||
| } | ||
| setIsLoading(false) | ||
| setShowAuthMsg(true) | ||
| }) | ||
| } | ||
|
|
||
| const handleInput = e => { | ||
| const newConf = { ...wpDataTablesConf } | ||
| newConf[e.target.name] = e.target.value | ||
| setWpDataTablesConf(newConf) |
There was a problem hiding this comment.
Added isInfo prop to WpDataTablesAuthorization. When true: name input is disabled, and the Connect/Next button block is hidden inside {!isInfo && ...}. Callback props (setIsLoading, setSnackbar, setWpDataTablesConf, nextPage) are only invoked when those buttons are rendered.
{!isInfo && (
<>
<button onClick={authorizeHandler} ... />
<button onClick={() => nextPage(2)} ... />
</>
)}| $fields = []; | ||
| $tableContent = json_decode(reset($table), true) ?? []; |
There was a problem hiding this comment.
Added null check for $wpdb->get_row() result and switched from reset($table) to named key access $table['content'].
if (empty($table)) {
wp_send_json_error(__('Table not found', 'bit-integrations'), 404);
}
$tableContent = json_decode($table['content'], true) ?? [];| type="button"> | ||
| + | ||
| </button> | ||
| <button | ||
| onClick={() => delFieldMap(i, wpDataTablesConf, setWpDataTablesConf)} | ||
| className="icn-btn sh-sm ml-1" | ||
| type="button" | ||
| aria-label="btn"> |
There was a problem hiding this comment.
Updated aria-label on the delete mapping button from "btn" to a descriptive label using the i18n helper:
aria-label={__('Remove mapping row', 'bit-integrations')}There was a problem hiding this comment.
Code Review
This pull request introduces a new integration for wpDataTables, enabling the 'Add Row' action. It includes backend controllers, routing, and helper classes for data processing, alongside a comprehensive frontend implementation for authorization, table selection, and field mapping. The review feedback highlights the need for robust error handling, specifically recommending the use of is_wp_error() to prevent fatal errors, validating database query results to avoid PHP warnings, and ensuring method visibility consistency by declaring static helper methods correctly.
| break; | ||
| } | ||
|
|
||
| $responseType = isset($response['success']) && $response['success'] ? 'success' : 'error'; |
There was a problem hiding this comment.
When handling responses that may return a WP_Error object, it is important to validate the response using is_wp_error() before accessing it as an array. This ensures compliance with the organization's general rules and prevents potential fatal errors in PHP 8.0+.
$responseType = !is_wp_error($response) && isset($response['success']) && $response['success'] ? 'success' : 'error';References
- In PHP, when handling responses that may return a WP_Error object, always use the is_wp_error() function to validate the response before accessing it as an array or object. This prevents fatal errors in PHP 8.0+.
There was a problem hiding this comment.
Valid. Added is_wp_error() guard before accessing $response as an array:
$responseType = !is_wp_error($response) && isset($response['success']) && $response['success'] ? 'success' : 'error';| return $response; | ||
| } | ||
|
|
||
| private function generateReqDataFromFieldMap($fieldMap, $fieldValues) |
There was a problem hiding this comment.
There was a problem hiding this comment.
Valid. Added static to the method declaration — it uses no instance properties and was already being called via static:::
private static function generateReqDataFromFieldMap($fieldMap, $fieldValues)|
|
||
| $fields = []; | ||
| $tableContent = json_decode(reset($table), true) ?? []; |
There was a problem hiding this comment.
The result of $wpdb->get_row should be checked for existence before processing. If no row is found, $table will be null, and calling reset($table) will trigger a PHP warning. Additionally, accessing the column by name is more robust and readable than using reset().
if (empty($table)) {
wp_send_json_error(__('Table not found', 'bit-integrations'), 404);
}
$fields = [];
$tableContent = json_decode($table['content'], true) ?? [];There was a problem hiding this comment.
Already fixed — null check added and switched to $table['content'] named access.
Description
This PR introduces a new
wpDataTablesintegration action that lets users insert rows into selected wpDataTables tables from their automation flows. It adds backend routes/controllers for table and column discovery and a complete frontend setup/edit experience with field mapping, refresh controls, and loading feedback. It also updates integration labels to use “wpDataTables Columns” for clarity.Motivation & Context
Users need a direct way to send mapped form/trigger data into wpDataTables rows without manual copy or custom code. This change enables a guided setup flow where users can authorize, select a table, fetch columns, and map fields reliably before saving the action.
Related Links: (if applicable)
Type of Change
Key Changes
Backend
WpDataTablesControllerendpoints to authorize plugin presence, fetch wpDataTables table list, and fetch selected table columns.RecordApiHelperexecution logic to transform mapped fields and trigger add-row behavior via hooks.Frontend
UX/Validation
Checklist
Changelog