Skip to content
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

refactor : jquery removal and ts integration src/components/DialogBox/CombinationalAnalysis.vue #439

Closed
wants to merge 1 commit into from

Conversation

ThatDeparted2061
Copy link
Contributor

@ThatDeparted2061 ThatDeparted2061 commented Jan 26, 2025

Fixes #414
Fixes #433

@JoshVarga @Arnabdaz @devartstar @niladrix719

Summary by CodeRabbit

  • Refactor

    • Enhanced type safety for functions and variables in the Combinational Analysis component
    • Improved code clarity with explicit TypeScript type annotations
    • Standardized variable initializations and type declarations
  • Style

    • Added semicolons for consistency
    • Refined code formatting and readability
  • Bug Fixes

    • Updated checkbox input default state to false
    • Streamlined alert message handling

Copy link
Contributor

coderabbitai bot commented Jan 26, 2025

Walkthrough

The pull request focuses on enhancing the CombinationalAnalysis.vue component by adding TypeScript type annotations and improving code type safety. The changes involve updating function signatures, explicitly typing reactive variables, and refactoring some logic for better consistency. The modifications aim to strengthen the component's type checking and make the code more maintainable without altering its core functionality.

Changes

File Change Summary
src/components/DialogBox/CombinationalAnalysis.vue - Added TypeScript type annotations to function signatures
- Explicitly typed reactive variables (inputArr, buttonArr, showAlert, etc.)
- Updated variable initializations with type-specific references
- Minor code refactoring and formatting improvements

Assessment against linked issues

Objective Addressed Explanation
Typescript Integration [#414]
Removal of JQuery to Vue's reactives [#433] No direct evidence of JQuery removal in this specific change

Poem

🐰 A Rabbit's TypeScript Tale 🔍

In Vue's domain, types now shine bright,
Annotations dancing with delight,
Reactive refs, no longer plain,
Code clarity is our refrain!
TypeScript magic, clean and neat! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link

netlify bot commented Jan 26, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit ea9deeb
🔍 Latest deploy log https://app.netlify.com/sites/circuitverse/deploys/679665e3b33cb20008015683
😎 Deploy Preview https://deploy-preview-439--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site 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 (4)
src/components/DialogBox/CombinationalAnalysis.vue (4)

13-14: Remove unused parameters from event handler.

The event handler captures circuitItem and circuitNameVal parameters but doesn't use them in the dialogBoxConformation call. This could lead to confusion.

-            (selectedOption: string, circuitItem: any, circuitNameVal: any) =>
-                dialogBoxConformation(selectedOption)
+            (selectedOption: string) => dialogBoxConformation(selectedOption)

30-38: Improve type safety for InputItem interface.

The val property type could be more specific based on the input type.

 type InputItem = {
     text: string;
-    val: string | boolean;
+    val: string | boolean | null;
     placeholder: string;
     id: string;
     style: string;
     class: string;
-    type: string;
+    type: 'text' | 'checkbox' | 'nil';
 };

Line range hint 113-122: Consider using const assertion for buttonArray.

Since this array is used as a constant reference for resetting the state, we should prevent accidental modifications.

-const buttonArray: ButtonItem[] = [
+const buttonArray = [
     {
         text: 'Next',
         emitOption: 'showLogicTable',
     },
     {
         text: 'Close',
         emitOption: 'closeMessageBox',
     },
-];
+] as const;

169-171: Improve type safety by avoiding type assertions.

Multiple type assertions could be replaced with proper type guards or validation.

-    let inputList = stripTags(inputArr.value[0].val as string).split(',');
-    let outputList = stripTags(inputArr.value[1].val as string).split(',');
-    let booleanExpression = inputArr.value[3].val as string;
+    const input = inputArr.value[0].val;
+    const output = inputArr.value[1].val;
+    const boolExpr = inputArr.value[3].val;
+
+    if (typeof input !== 'string' || typeof output !== 'string' || typeof boolExpr !== 'string') {
+        showAlert.value = true;
+        alertType.value = 'error';
+        alertMessage.value = 'Invalid input types';
+        return;
+    }
+
+    let inputList = stripTags(input).split(',');
+    let outputList = stripTags(output).split(',');
+    let booleanExpression = boolExpr;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6eae6ed and ea9deeb.

📒 Files selected for processing (1)
  • src/components/DialogBox/CombinationalAnalysis.vue (4 hunks)

Comment on lines +283 to +284
const sTable = messageBoxElement.innerHTML;

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

Fix potential XSS vulnerability in printBooleanTable.

The function directly injects innerHTML into a new window, which could lead to XSS attacks.

Consider using DOMPurify or similar sanitization library:

+import DOMPurify from 'dompurify';
 const sTable = messageBoxElement.innerHTML;
+const sanitizedTable = DOMPurify.sanitize(sTable);

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +168 to 211
function createLogicTable(): void {
let inputList = stripTags(inputArr.value[0].val as string).split(',');
let outputList = stripTags(inputArr.value[1].val as string).split(',');
let booleanExpression = inputArr.value[3].val as string;

inputList = inputList.map((x) => x.trim())
inputList = inputList.filter((e) => e)
outputList = outputList.map((x) => x.trim())
outputList = outputList.filter((e) => e)
booleanExpression = booleanExpression.replace(/ /g, '')
booleanExpression = booleanExpression.toUpperCase()
inputList = inputList.map((x) => x.trim()).filter((e) => e);
outputList = outputList.map((x) => x.trim()).filter((e) => e);
booleanExpression = booleanExpression.replace(/ /g, '').toUpperCase();

var booleanInputVariables = []
for (var i = 0; i < booleanExpression.length; i++) {
const booleanInputVariables: string[] = [];
for (let i = 0; i < booleanExpression.length; i++) {
if (booleanExpression[i] >= 'A' && booleanExpression[i] <= 'Z') {
if (booleanExpression.indexOf(booleanExpression[i]) == i) {
booleanInputVariables.push(booleanExpression[i])
if (booleanExpression.indexOf(booleanExpression[i]) === i) {
booleanInputVariables.push(booleanExpression[i]);
}
}
}
booleanInputVariables.sort()
booleanInputVariables.sort();

if (
inputList.length > 0 &&
outputList.length > 0 &&
booleanInputVariables.length == 0
) {
// $(this).dialog('close')
SimulatorState.dialogBox.combinationalanalysis_dialog = false

createBooleanPrompt(inputList, outputList, null)
} else if (
booleanInputVariables.length > 0 &&
inputList.length == 0 &&
outputList.length == 0
) {
// $(this).dialog('close')
SimulatorState.dialogBox.combinationalanalysis_dialog = false
output.value = []
solveBooleanFunction(booleanInputVariables, booleanExpression)
if (output.value != null) {
createBooleanPrompt(booleanInputVariables, booleanExpression)
if (inputList.length > 0 && outputList.length > 0 && booleanInputVariables.length === 0) {
SimulatorState.dialogBox.combinationalanalysis_dialog = false;
createBooleanPrompt(inputList, outputList, null);
} else if (booleanInputVariables.length > 0 && inputList.length === 0 && outputList.length === 0) {
SimulatorState.dialogBox.combinationalanalysis_dialog = false;
output.value = [];
solveBooleanFunction(booleanInputVariables, booleanExpression);
if (output.value !== null) {
createBooleanPrompt(booleanInputVariables, booleanExpression);
}
} else if (
(inputList.length == 0 || outputList.length == 0) &&
booleanInputVariables == 0
) {
showAlert.value = true
alertType.value = 'info'
alertMessage.value =
'Enter Input / Output Variable(s) OR Boolean Function!'
} else if ((inputList.length === 0 || outputList.length === 0) && booleanInputVariables.length === 0) {
showAlert.value = true;
alertType.value = 'info';
alertMessage.value = 'Enter Input / Output Variable(s) OR Boolean Function!';
setTimeout(() => {
showAlert.value = false
}, 2000)
showAlert.value = false;
}, 2000);
} else {
showAlert.value = true
alertType.value = 'warning'
alertMessage.value =
'Use Either Combinational Analysis Or Boolean Function To Generate Circuit!'
showAlert.value = true;
alertType.value = 'warning';
alertMessage.value = 'Use Either Combinational Analysis Or Boolean Function To Generate Circuit!';
setTimeout(() => {
showAlert.value = false
}, 2000)
showAlert.value = false;
}, 2000);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor complex conditions in createLogicTable.

The function has nested conditions that make it hard to follow. Consider extracting the validation logic and using early returns.

 function createLogicTable(): void {
     let inputList = stripTags(inputArr.value[0].val as string).split(',');
     let outputList = stripTags(inputArr.value[1].val as string).split(',');
     let booleanExpression = inputArr.value[3].val as string;

     inputList = inputList.map((x) => x.trim()).filter((e) => e);
     outputList = outputList.map((x) => x.trim()).filter((e) => e);
     booleanExpression = booleanExpression.replace(/ /g, '').toUpperCase();

     const booleanInputVariables = extractBooleanVariables(booleanExpression);

+    if (!isValidInput(inputList, outputList, booleanInputVariables)) {
+        return;
+    }
+
+    if (shouldUseBooleanFunction(inputList, outputList, booleanInputVariables)) {
+        handleBooleanFunction(booleanInputVariables, booleanExpression);
+        return;
+    }
+
+    if (shouldUseCombinationalAnalysis(inputList, outputList, booleanInputVariables)) {
+        handleCombinationalAnalysis(inputList, outputList);
+        return;
+    }
-    // ... rest of the function
 }

+function extractBooleanVariables(expression: string): string[] {
+    const variables: string[] = [];
+    for (let i = 0; i < expression.length; i++) {
+        if (expression[i] >= 'A' && expression[i] <= 'Z' && 
+            expression.indexOf(expression[i]) === i) {
+            variables.push(expression[i]);
+        }
+    }
+    return variables.sort();
+}

Committable suggestion skipped: line range outside the PR's diff.

@ThatDeparted2061
Copy link
Contributor Author

lemme change the branch and push again

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 Typescript Integration in /simulator/src files
1 participant