Skip to content

Commit

Permalink
feat: trigger re-scan when settings change
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed Mar 18, 2024
1 parent aaae141 commit d3f1dbc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/io/snyk/plugin/ui/SnykSettingsDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class SnykSettingsDialog(
private val codeAlertPanel = scanTypesPanelOuter.codeAlertPanel
private val scanTypesPanel = scanTypesPanelOuter.panel

private val issueViewOptionsPanel = IssueViewOptionsPanel().panel
private val issueViewOptionsPanel = IssueViewOptionsPanel(project).panel

private val severityEnablementPanel = SeveritiesEnablementPanel().panel

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package io.snyk.plugin.ui.settings

import com.intellij.openapi.project.Project
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.layout.panel
import com.intellij.util.ui.JBUI
import io.snyk.plugin.getSnykTaskQueueService
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.ui.SnykBalloonNotificationHelper

class IssueViewOptionsPanel {
class IssueViewOptionsPanel(
private val project: Project,
) {
private val settings
get() = pluginSettings()

Expand All @@ -22,8 +26,11 @@ class IssueViewOptionsPanel {
setter = { settings.openIssuesEnabled = it }
).component.apply {
this.addItemListener {
isOptionNotSelected(this, currentOpenIssuesEnabled)
currentOpenIssuesEnabled = this.isSelected
if (canOptionChange(this, currentOpenIssuesEnabled)) {
currentOpenIssuesEnabled = this.isSelected
settings.openIssuesEnabled = currentOpenIssuesEnabled
getSnykTaskQueueService(project)?.scan()
}
}
name = "Open issues"
}
Expand All @@ -37,8 +44,11 @@ class IssueViewOptionsPanel {
setter = { settings.ignoredIssuesEnabled = it }
).component.apply {
this.addItemListener {
isOptionNotSelected(this, currentIgnoredIssuesEnabled)
currentIgnoredIssuesEnabled = this.isSelected
if (canOptionChange(this, currentIgnoredIssuesEnabled)) {
currentIgnoredIssuesEnabled = this.isSelected
settings.ignoredIssuesEnabled =currentIgnoredIssuesEnabled
getSnykTaskQueueService(project)?.scan()
}
}
name = "Ignored issues"
}
Expand All @@ -49,7 +59,7 @@ class IssueViewOptionsPanel {
border = JBUI.Borders.empty(2)
}

private fun isOptionNotSelected(component: JBCheckBox, wasEnabled: Boolean): Boolean {
private fun canOptionChange(component: JBCheckBox, wasEnabled: Boolean): Boolean {
val onlyOneEnabled = arrayOf(
currentOpenIssuesEnabled,
currentIgnoredIssuesEnabled,
Expand All @@ -61,7 +71,8 @@ class IssueViewOptionsPanel {
"At least one option should be selected",
component
)
return false
}
return onlyOneEnabled
return true
}
}

0 comments on commit d3f1dbc

Please sign in to comment.