Skip to content

feat(client): db sync and save meta model #1179

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

Merged
merged 1 commit into from
May 27, 2025

Conversation

SuryaNarayanan-Kgs
Copy link
Contributor

Description

Changes Made

How to Test

  1. Steps to reproduce/test the behavior
  2. Expected outcomes

Notes

@SuryaNarayanan-Kgs SuryaNarayanan-Kgs requested a review from a team as a code owner May 20, 2025 07:28
@SuryaNarayanan-Kgs SuryaNarayanan-Kgs linked an issue May 20, 2025 that may be closed by this pull request
2 tasks
Copy link

@CodiumAI-Agent /describe

@CodiumAI-Agent
Copy link

Title

feat(client): db sync and save meta model


User description

Description

Changes Made

How to Test

  1. Steps to reproduce/test the behavior
  2. Expected outcomes

Notes


PR Type

Enhancement


Description

  • Add Refresh Data and Sync Changes modal

  • Refactor nodes/edges to support custom updates

  • Introduce Pixel queries for external JDBC sync

  • Create table/view selection UI component


Changes walkthrough 📝

Relevant files
Enhancement
EngineMetadataPage.tsx
Add refresh and sync functionality                                             

packages/client/src/pages/engine/EngineMetadataPage.tsx

  • Imported useEffect and SyncChangesModal component
  • Added state for customNodes, customEdges, tabledata, viewdata,
    showSyncModal
  • Introduced refreshData and handleSyncApply functions with Pixel
    queries
  • Updated to use customNodes/customEdges fallbacks
  • Enhanced header with "Refresh Data" and "Print Metadata" buttons
  • +236/-275
    SyncChangesModal.tsx
    Implement SyncChangesModal component                                         

    packages/client/src/pages/engine/SyncChangesModal.tsx

  • New SyncChangesModal component for DB sync selection
  • UI for searching and filtering tables and views
  • Checkbox lists with select-all and individual toggles
  • onApply callback passes selected tables/views
  • +200/-0 

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    @CodiumAI-Agent /review

    Copy link

    @CodiumAI-Agent /improve

    @CodiumAI-Agent
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Type Mismatch

    The generic type for usePixel response does not include edges, positions, or descriptions, causing potential runtime errors when accessing these fields.

    const getDatabaseMetamodel = usePixel<{
        dataTypes: Record<string, 'INT' | 'DOUBLE' | 'STRING'>;
        logicalNames: Record<string, string[]>;
        nodes: { propSet: string[]; conceptualName: string }[];
    Missing Node Type

    The initial state for selectedNode lacks an explicit type definition, which may lead to type inference issues or runtime errors in onSelectNode and related logic.

    const [selectedNode, setSelectedNode] = useState(null);
    Incorrect Bulk Selection

    The "Select searched items" checkbox toggles the full tables/views lists instead of just the filtered results, which can lead to unexpected selections. Consider basing the toggle on filteredTables/filteredViews.

    <FormControlLabel
        control={
            <Checkbox
                checked={allTablesSelected}
                onChange={() =>
                    setSelectedTables(
                        allTablesSelected ? [] : tables,
                    )
                }

    @CodiumAI-Agent
    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Sync tables select logic

    Update the select-all behavior for tables to only select filtered items and reflect
    that in the allTablesSelected calculation. This prevents selecting tables not
    visible in the search.

    packages/client/src/pages/engine/SyncChangesModal.tsx [64-115]

    -const allTablesSelected = selectedTables.length === tables.length;
    +const allTablesSelected = selectedTables.length === filteredTables.length;
     <FormControlLabel
         control={
             <Checkbox
                 checked={allTablesSelected}
                 onChange={() =>
                     setSelectedTables(
    -                    allTablesSelected ? [] : tables,
    +                    allTablesSelected ? [] : filteredTables,
                     )
                 }
             />
         }
         label="(Select searched items)"
     />
    Suggestion importance[1-10]: 8

    __

    Why: This fixes a bug where the "Select searched items" checkbox actually selects all tables instead of only the filtered ones, aligning behavior with the label and improving UX.

    Medium
    General
    Handle refresh errors

    Add error handling to the refreshData promise chain to catch and handle API
    failures, preventing unhandled promise rejections and updating UI state accordingly.

    packages/client/src/pages/engine/EngineMetadataPage.tsx [141-149]

     const refreshData = () => {
         const pixel = `ExternalUpdateJdbcTablesAndViews(database=["${id}"]);`;
    -    monolithStore.runQuery(pixel).then((response) => {
    -        const output = response.pixelReturn[0].output;
    -        setTabledata(output.tables ?? []);
    -        setViewdata(output.views ?? []);
    -        setShowSyncModal(true);
    -    });
    +    monolithStore.runQuery(pixel)
    +        .then((response) => {
    +            const output = response.pixelReturn[0].output;
    +            setTabledata(output.tables ?? []);
    +            setViewdata(output.views ?? []);
    +            setShowSyncModal(true);
    +        })
    +        .catch((error) => {
    +            console.error('Error refreshing data:', error);
    +            setShowSyncModal(false);
    +        });
     };
    Suggestion importance[1-10]: 7

    __

    Why: Adding a .catch prevents unhandled promise rejections and allows for graceful error handling in refreshData, improving robustness.

    Medium
    Reset modal state on open

    Reset search inputs and selections whenever the modal opens to avoid stale filters
    or selections from previous sessions. This ensures users see a fresh state each
    time.

    packages/client/src/pages/engine/SyncChangesModal.tsx [31-34]

     const [tableSearch, setTableSearch] = useState('');
     const [viewSearch, setViewSearch] = useState('');
     const [selectedTables, setSelectedTables] = useState<string[]>([]);
     const [selectedViews, setSelectedViews] = useState<string[]>([]);
    +useEffect(() => {
    +    if (open) {
    +        setTableSearch('');
    +        setViewSearch('');
    +        setSelectedTables([]);
    +        setSelectedViews([]);
    +    }
    +}, [open]);
    Suggestion importance[1-10]: 6

    __

    Why: Initializing the search and selection state on each open prevents stale filters or selections, ensuring a clean modal experience without persisting old data.

    Low

    Copy link
    Contributor

    @johbaxter johbaxter left a comment

    Choose a reason for hiding this comment

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

    Alright so this works with my client databases.

    Diabetes dataset was giving me some weird stuff

    Will approve as this is new functionality

    @johbaxter johbaxter merged commit c98ebe0 into dev May 27, 2025
    4 checks passed
    @johbaxter johbaxter deleted the 55-fe-allow-db-sync-and-save-of-metamodel branch May 27, 2025 15:38
    Copy link

    @CodiumAI-Agent /update_changelog

    @johbaxter
    Copy link
    Contributor

    johbaxter commented May 27, 2025

    @ppatel9703 @roxyramos @memisrose possibly set up for testing?

    Also remember us having to press a save button in legacy, is that not anymore

    Looks like it doesn't save metamodel rn, not sure

    @CodiumAI-Agent
    Copy link

    Changelog updates: 🔄

    2025-05-27 *

    Added

    • Database sync and metamodel save support in the client
    • "Refresh Data" button and Sync Changes modal for selecting and applying external updates

    to commit the new content to the CHANGELOG.md file, please type:
    '/update_changelog --pr_update_changelog.push_changelog_changes=true'

    @CodiumAI-Agent
    Copy link

    Changelog updates: 🔄

    2025-05-27 *

    Added

    • Support for syncing external database tables and views into the metamodel
    • New SyncChangesModal for selecting and applying schema updates
    • Refresh and save metamodel functionality on the Engine Metadata page

    to commit the new content to the CHANGELOG.md file, please type:
    '/update_changelog --pr_update_changelog.push_changelog_changes=true'

    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.

    [FE] Allow DB Sync and Save of Metamodel
    3 participants