Skip to content

refactor: remove jQuery/DOM manipulation from v0/src/components/DialogBox/CombinationalAnalysis.vue #580

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

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

Conversation

blazethunderstorm
Copy link

@blazethunderstorm blazethunderstorm commented Jun 7, 2025

Fixes #433

Describe the changes you have made in this PR -

Replace jQuery selectors and DOM queries with Vue reactive data processing
in v0/src/components/DialogBox/CombinationalAnalysis.vue"

Screenshots of the changes (If any) -

Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.

Summary by CodeRabbit

  • Refactor
    • Improved performance and reliability of the boolean logic table by replacing legacy DOM manipulation and jQuery with Vue 3 reactive data handling.
    • Enhanced table printing with updated formatting and more consistent data extraction.
    • Minor adjustments to alert positioning and overall table styling for a better user experience.

Copy link
Contributor

coderabbitai bot commented Jun 7, 2025

Walkthrough

This change refactors the CombinationalAnalysis.vue component to remove jQuery and direct DOM manipulation, replacing them with Vue 3 reactive state and computed properties for managing and extracting boolean logic table data. Functions for data generation and printing are updated to use reactive data, and minor CSS and code cleanups are included.

Changes

File(s) Change Summary
v0/src/components/DialogBox/CombinationalAnalysis.vue Replaced jQuery and DOM queries with Vue 3 reactive/computed properties; refactored table data generation and printing; added template ref; improved equality checks; minor CSS and code cleanups.

Assessment against linked issues

Objective Addressed Explanation
Remove remaining jQuery and DOM manipulations, migrate logic to Vue reactives (#433)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • Arnabdaz

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-07T15_05_27_444Z-debug-0.log


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@blazethunderstorm
Copy link
Author

@niladrix719 @Arnabdaz pls review the pr , thanks

Copy link

netlify bot commented Jun 7, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit e3b9a85
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/684454ddb557260008cd555f
😎 Deploy Preview https://deploy-preview-580--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 43 (🔴 down 3 from production)
Accessibility: 72 (no change from production)
Best Practices: 92 (no change from production)
SEO: 80 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
v0/src/components/DialogBox/CombinationalAnalysis.vue (2)

16-16: Remove unused template ref or document its intended purpose.

The messageBoxRef is declared and assigned to the template but is never used in the component logic. If it's not needed, consider removing it to keep the code clean.

         @button-click="
             (selectedOption, circuitItem, circuitNameVal) =>
                 dialogBoxConformation(selectedOption)
         "
-        ref="messageBoxRef"
     />

And remove the declaration:

 const SimulatorState = useState()
-const messageBoxRef = ref(null)

Also applies to: 44-44


694-747: Excellent refactoring of printBooleanTable using Vue reactive patterns.

The refactored function successfully removes jQuery dependencies and properly uses Vue's reactive system with nextTick. The HTML generation from reactive data is clean and maintainable.

Minor suggestion: Consider extracting the inline styles to a constant for better maintainability.

+const PRINT_TABLE_STYLES = `<style>
+    table {font: 40px Calibri;}
+    table, th, td {border: solid 1px #DDD;border-collapse: collapse;}
+    th, td {padding: 8px; text-align: center;}
+    thead {background-color: #f2f2f2;}
+</style>`

 async function printBooleanTable() {
     // ... existing code ...
     
-    const style = `<style>
-        table {font: 40px Calibri;}
-        table, th, td {border: solid 1px #DDD;border-collapse: collapse;}
-        th, td {padding: 8px; text-align: center;}
-        thead {background-color: #f2f2f2;}
-    </style>`
-    
     const win = window.open('', '', 'height=700,width=700')
     const htmlBody = `
         <html>
             <head>
                 <title>Boolean Logic Table</title>
-                ${style}
+                ${PRINT_TABLE_STYLES}
             </head>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f64c366 and e3b9a85.

📒 Files selected for processing (1)
  • v0/src/components/DialogBox/CombinationalAnalysis.vue (13 hunks)
🔇 Additional comments (3)
v0/src/components/DialogBox/CombinationalAnalysis.vue (3)

27-27: LGTM! Proper Vue 3 imports for reactive refactoring.

The addition of ref, computed, and nextTick imports is appropriate for replacing jQuery/DOM manipulation with Vue's reactive system.


115-115: Good improvement: Proper boolean types for checkbox values.

Using false instead of empty strings for checkbox default values is the correct approach and improves type safety.

Also applies to: 140-140


216-216: Excellent defensive programming with stricter null checks.

The enhanced checks for both null and empty arrays (output.value !== null && output.value.length > 0) provide better protection against edge cases and potential runtime errors.

Also applies to: 247-247, 265-265, 291-291, 295-295, 677-677

Comment on lines +62 to +76
// Reactive computed property for table data extraction
const currentTableData = computed(() => {
if (!tableBody.value || tableBody.value.length === 0) {
return []
}

const fw = inputArr.value[4]?.val === true ? 1 : 0
return tableBody.value.map((row, index) => ({
index,
inputs: row.slice(fw, fw + inputListNames.value.length),
outputs: row.slice(fw + inputListNames.value.length),
decimal: fw > 0 ? row[0] : index
}))
})

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused computed property.

The currentTableData computed property is well-implemented but is never used anywhere in the component. This adds unnecessary complexity and memory overhead.

Either remove this unused code or implement its intended functionality:

-// Reactive computed property for table data extraction
-const currentTableData = computed(() => {
-    if (!tableBody.value || tableBody.value.length === 0) {
-        return []
-    }
-    
-    const fw = inputArr.value[4]?.val === true ? 1 : 0
-    return tableBody.value.map((row, index) => ({
-        index,
-        inputs: row.slice(fw, fw + inputListNames.value.length),
-        outputs: row.slice(fw + inputListNames.value.length),
-        decimal: fw > 0 ? row[0] : index
-    }))
-})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Reactive computed property for table data extraction
const currentTableData = computed(() => {
if (!tableBody.value || tableBody.value.length === 0) {
return []
}
const fw = inputArr.value[4]?.val === true ? 1 : 0
return tableBody.value.map((row, index) => ({
index,
inputs: row.slice(fw, fw + inputListNames.value.length),
outputs: row.slice(fw + inputListNames.value.length),
decimal: fw > 0 ? row[0] : index
}))
})
🤖 Prompt for AI Agents
In v0/src/components/DialogBox/CombinationalAnalysis.vue between lines 62 and
76, the computed property currentTableData is defined but never used in the
component. To fix this, either remove the entire currentTableData computed
property to eliminate unused code and reduce complexity, or identify where its
data should be used in the component and integrate it accordingly.

Comment on lines 315 to +339
const generateBooleanTableData = (outputListNames) => {
const data = {};

const table = document.querySelector('.content-table');
const rows = table?.querySelectorAll('tbody tr') || [];

const rowData = [...rows].slice(1).map((row, index) => {
const cells = row.cells;
const lastValue = cells[cells.length - 1]?.textContent.trim();
return { index, value: lastValue };
});

for (const outputName of outputListNames) {
data[outputName] = { x: [], 1: [], 0: [] };

rowData.forEach(({ index, value }) => {
if (value === '0') {
data[outputName]['0'].push(String(index));
} else if (value === '1') {
data[outputName]['1'].push(String(index));
} else {
data[outputName]['x'].push(String(index));
}
});
}

return data;
};

const data = {}

// Use reactive table data instead of DOM manipulation
const fw = inputArr.value[4]?.val === true ? 1 : 0
const outputStartIndex = fw + inputListNames.value.length

for (const outputName of outputListNames) {
data[outputName] = { x: [], 1: [], 0: [] }

tableBody.value.forEach((row, index) => {
const outputValue = row[outputStartIndex]?.toString().trim()

if (outputValue === '0') {
data[outputName]['0'].push(String(index))
} else if (outputValue === '1') {
data[outputName]['1'].push(String(index))
} else {
data[outputName]['x'].push(String(index))
}
})
}

return data
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify handling of multiple outputs in refactored function.

The refactored generateBooleanTableData successfully removes jQuery dependencies. However, the function only accesses row[outputStartIndex] which suggests it handles only the first output column, while the original implementation supported multiple outputs.

If multiple outputs are needed, consider updating line 326:

-const outputValue = row[outputStartIndex]?.toString().trim()
+const outputIndex = outputStartIndex + outputListNames.indexOf(outputName)
+const outputValue = row[outputIndex]?.toString().trim()

🏁 Script executed:

#!/bin/bash
# Check if the function is called with multiple outputs anywhere
rg -A 5 "generateBooleanTableData" --type vue

Length of output: 73


Continuing verification of generateBooleanTableData usage and invocation:


🏁 Script executed:

#!/bin/bash
# Locate the component file and search for generateBooleanTableData usage
comp=$(fd CombinationalAnalysis.vue)
echo "Found component at: $comp"
grep -n "generateBooleanTableData" "$comp" || true
rg -n "generateBooleanTableData\(" --color=never || true

Length of output: 2063


🏁 Script executed:

#!/bin/bash
# Inspect original generateBooleanTableData function implementation to confirm multiple output support
rg -n -B3 -A15 "function generateBooleanTableData" src/simulator/src/combinationalAnalysis.js

Length of output: 609


Ensure multi-output columns are handled in generateBooleanTableData

The refactored generateBooleanTableData correctly removes jQuery, but it always reads from row[outputStartIndex]—only the first output column. To support multiple outputs, each outputName needs its own column offset:

Files needing attention:

  • v1/src/components/DialogBox/CombinationalAnalysis.vue (around lines 315–339)

Suggested change:

- for (const outputName of outputListNames) {
+ for (let i = 0; i < outputListNames.length; i++) {
+   const outputName = outputListNames[i]
+   const columnIndex = outputStartIndex + i
    data[outputName] = { x: [], 1: [], 0: [] }
    
-   tableBody.value.forEach((row, index) => {
-       const outputValue = row[outputStartIndex]?.toString().trim()
+   tableBody.value.forEach((row, index) => {
+       const outputValue = row[columnIndex]?.toString().trim()
  
       if (outputValue === '0') {
         data[outputName]['0'].push(String(index))
@@

This ensures each output name maps to its corresponding column in the reactive table.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const generateBooleanTableData = (outputListNames) => {
const data = {};
const table = document.querySelector('.content-table');
const rows = table?.querySelectorAll('tbody tr') || [];
const rowData = [...rows].slice(1).map((row, index) => {
const cells = row.cells;
const lastValue = cells[cells.length - 1]?.textContent.trim();
return { index, value: lastValue };
});
for (const outputName of outputListNames) {
data[outputName] = { x: [], 1: [], 0: [] };
rowData.forEach(({ index, value }) => {
if (value === '0') {
data[outputName]['0'].push(String(index));
} else if (value === '1') {
data[outputName]['1'].push(String(index));
} else {
data[outputName]['x'].push(String(index));
}
});
}
return data;
};
const data = {}
// Use reactive table data instead of DOM manipulation
const fw = inputArr.value[4]?.val === true ? 1 : 0
const outputStartIndex = fw + inputListNames.value.length
for (const outputName of outputListNames) {
data[outputName] = { x: [], 1: [], 0: [] }
tableBody.value.forEach((row, index) => {
const outputValue = row[outputStartIndex]?.toString().trim()
if (outputValue === '0') {
data[outputName]['0'].push(String(index))
} else if (outputValue === '1') {
data[outputName]['1'].push(String(index))
} else {
data[outputName]['x'].push(String(index))
}
})
}
return data
}
const generateBooleanTableData = (outputListNames) => {
const data = {}
// Use reactive table data instead of DOM manipulation
const fw = inputArr.value[4]?.val === true ? 1 : 0
const outputStartIndex = fw + inputListNames.value.length
// Handle each output column by its offset
for (let i = 0; i < outputListNames.length; i++) {
const outputName = outputListNames[i]
const columnIndex = outputStartIndex + i
data[outputName] = { x: [], 1: [], 0: [] }
tableBody.value.forEach((row, index) => {
const outputValue = row[columnIndex]?.toString().trim()
if (outputValue === '0') {
data[outputName]['0'].push(String(index))
} else if (outputValue === '1') {
data[outputName]['1'].push(String(index))
} else {
data[outputName]['x'].push(String(index))
}
})
}
return data
}
🤖 Prompt for AI Agents
In v0/src/components/DialogBox/CombinationalAnalysis.vue around lines 315 to
339, the generateBooleanTableData function currently reads output values only
from row[outputStartIndex], which handles just the first output column. To fix
this and support multiple outputs, update the code inside the loop over
outputListNames to calculate the correct column index for each output by adding
the output's index to outputStartIndex, then access row at that computed index.
This ensures each outputName corresponds to its proper column in the reactive
table data.

@Arnabdaz
Copy link
Member

Arnabdaz commented Jun 7, 2025

Can you also make a pr for the src folder instead of v0 as we would be syncing both soon.

@blazethunderstorm
Copy link
Author

@Arnabdaz can I make a pr for v1 folder ?

@Arnabdaz
Copy link
Member

Arnabdaz commented Jun 7, 2025

@Arnabdaz can I make a pr for v1 folder ?

we'll let you know regarding that for now you can make for src/ dir.

@blazethunderstorm
Copy link
Author

@Arnabdaz alright , thanks for your help

@ThatDeparted2061
Copy link
Member

Thanks for the PR but we don't want ts integration in v0 or v1 at the moment, You can try it for files which dont have pre-existing PRs

@blazethunderstorm
Copy link
Author

@ThatDeparted2061 alright

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.

Removal of JQuery to Vue's reactives
3 participants