Skip to content

feat(integrations): add wpDataTables action with table/column mapping#166

Open
RishadAlam wants to merge 5 commits into
mainfrom
feat/wpdatatables
Open

feat(integrations): add wpDataTables action with table/column mapping#166
RishadAlam wants to merge 5 commits into
mainfrom
feat/wpdatatables

Conversation

@RishadAlam
Copy link
Copy Markdown
Member

Description

This PR introduces a new wpDataTables integration 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

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • ⚡ Improvement
  • 🔄 Code refactor

Key Changes

Backend

  • Added WpDataTablesController endpoints to authorize plugin presence, fetch wpDataTables table list, and fetch selected table columns.
  • Added wpDataTables action route registrations for authorize, table fetch, and column fetch.
  • Added RecordApiHelper execution logic to transform mapped fields and trigger add-row behavior via hooks.
  • Updated trigger/action naming registry to include wpDataTables integration support.

Frontend

  • Added new wpDataTables integration setup screen and edit screen components.
  • Added table and column refresh utilities with loading states and user feedback toasts.
  • Added dynamic field-mapping UI for wpDataTables columns, including support for custom values.
  • Added integration selection entry points and registration in integration info/new/edit/select-action flows.
  • Added wpDataTables integration icon asset and static action metadata.

UX/Validation

  • Improved setup validation to ensure action/table selection and mapped fields are present before continuing/saving.
  • Fixed wording from “wpDataTables Fields” to “wpDataTables Columns” for clearer mapping context.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Tests added/updated
  • Documentation updated if needed
  • README updated if needed

Changelog

  • Feature: Added a new wpDataTables action so users can insert rows into selected wpDataTables tables from automations.
  • Improvement: Added table/column fetch and refresh controls to make wpDataTables setup faster and more reliable.
  • Fix: Updated mapping labels to “wpDataTables Columns” for clearer field-to-column mapping during setup.

Copilot AI review requested due to automatic review settings May 18, 2026 09:57
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
1 0 1

⚠️ Warnings (1)

📁 readme.txt (1 warning)
📍 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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed the unused generateMappedField import from WpDataTablesIntegLayout.jsx.

Comment on lines +645 to +646
case 'WpDataTables':
return <WpDataTablesAuthorization wpDataTablesConf={integrationConf} step={1} isInfo />
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment on lines +14 to +37
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)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)} ... />
  </>
)}

Comment on lines +61 to +62
$fields = [];
$tableContent = json_decode(reset($table), true) ?? [];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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) ?? [];

Comment on lines +89 to +96
type="button">
+
</button>
<button
onClick={() => delFieldMap(i, wpDataTablesConf, setWpDataTablesConf)}
className="icn-btn sh-sm ml-1"
type="button"
aria-label="btn">
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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')}

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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
  1. 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+.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The method generateReqDataFromFieldMap is called statically on line 31 but defined as an instance method. It should be declared as static since it does not access any instance properties.

    private static function generateReqDataFromFieldMap($fieldMap, $fieldValues)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)

Comment on lines +60 to +62

$fields = [];
$tableContent = json_decode(reset($table), true) ?? [];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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) ?? [];

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Already fixed — null check added and switched to $table['content'] named access.

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