-
Notifications
You must be signed in to change notification settings - Fork 128
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
Conversation
WalkthroughThe pull request focuses on enhancing the Changes
Assessment against linked issues
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for circuitverse ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this 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
andcircuitNameVal
parameters but doesn't use them in thedialogBoxConformation
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;
const sTable = messageBoxElement.innerHTML; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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); | ||
} |
There was a problem hiding this comment.
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.
lemme change the branch and push again |
Fixes #414
Fixes #433
@JoshVarga @Arnabdaz @devartstar @niladrix719
Summary by CodeRabbit
Refactor
Style
Bug Fixes
false