Skip to content

Commit

Permalink
Swap case-switch for a map to select lang
Browse files Browse the repository at this point in the history
Utilizes a map for handling the selection of the PrismJS language class
instead of the original switch statement for brevity.
  • Loading branch information
signus committed Feb 23, 2024
1 parent b8a4e20 commit ebbc364
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ function updateBackendSyntax() {
let backend = getSelectValue("select-backend");
let language = "";
let prev_language = "";
let default_language = "language-sql";

// Determines what class was previously present upon a new backend selection
let prev_lang_class = document.getElementById("query-code").classList;
Expand All @@ -325,27 +326,15 @@ function updateBackendSyntax() {
}
}

// TODO: Find a more effective method (e.g. Enum) to implement targets
// with their respective language syntax highlighting.
switch(backend) {
case "azure":
language = "language-kusto";
break;
case "ibm-qradar-aql":
language = "language-sql";
break;
case "microsoft365defender":
language = "language-kusto";
break;
case "splunk":
language = "language-splunk-spl";
break;
case "qradar":
language = "language-sql";
break;
default:
language = "language-sql";
}
const languageMap = {
"azure" : "language-kusto",
"ibm-qradar-aql": "language-sql",
"microsoft365defender": "language-kusto",
"splunk": "language-splunk-spl",
"qradar": "language-sql"
};

language = languageMap[backend] ? languageMap[backend] : default_language;

document.getElementById("query-code").classList.remove(prev_language);
document.getElementById("query-code").classList.toggle(language);
Expand Down

0 comments on commit ebbc364

Please sign in to comment.