Skip to content

Refactor: information&warning banner #111

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

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactor: information&warning banner
- can now include hyperlinks
- green or yellow background
- the banner is now tied to the workspace table
- resolves #106
  • Loading branch information
fioan89 committed Dec 5, 2022
commit efa98df279384a6f967c23090527b206e46b5bd7
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- warning system when plugin might not be compatible with Coder REST API
- a `Create workspace` button which links to Coder's templates page

### Changed
- redesigned the information&warning banner. Messages can now include hyperlinks

### Fixed
- outdated Coder CLI binaries are cleaned up
- workspace status color style: running workspaces are green, failed ones should be red, everything else is gray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import com.coder.gateway.icons.CoderIcons
import com.coder.gateway.models.CoderWorkspacesWizardModel
import com.coder.gateway.models.WorkspaceAgentModel
import com.coder.gateway.models.WorkspaceAgentStatus
import com.coder.gateway.models.WorkspaceAgentStatus.DELETING
import com.coder.gateway.models.WorkspaceAgentStatus.FAILED
import com.coder.gateway.models.WorkspaceAgentStatus.RUNNING
import com.coder.gateway.models.WorkspaceAgentStatus.STARTING
import com.coder.gateway.models.WorkspaceAgentStatus.STOPPED
import com.coder.gateway.models.WorkspaceAgentStatus.STOPPING
import com.coder.gateway.models.WorkspaceVersionStatus
import com.coder.gateway.sdk.Arch
import com.coder.gateway.sdk.CoderCLIManager
Expand All @@ -25,7 +22,6 @@ import com.coder.gateway.sdk.getOS
import com.coder.gateway.sdk.toURL
import com.coder.gateway.sdk.v2.models.Workspace
import com.coder.gateway.sdk.withPath
import com.intellij.icons.AllIcons
import com.intellij.ide.ActivityTracker
import com.intellij.ide.BrowserUtil
import com.intellij.ide.IdeBundle
Expand Down Expand Up @@ -72,7 +68,6 @@ import org.zeroturnaround.exec.ProcessExecutor
import java.awt.Component
import java.awt.Dimension
import javax.swing.Icon
import javax.swing.JLabel
import javax.swing.JTable
import javax.swing.JTextField
import javax.swing.ListSelectionModel
Expand All @@ -99,7 +94,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
WorkspaceStatusColumnInfo("Status")
)

private val notificationBand = JLabel()
private val notificationBanner = NotificationBanner()
private var tableOfWorkspaces = TableView(listTableModelOfWorkspaces).apply {
setEnableAntialiasing(true)
rowSelectionAllowed = true
Expand All @@ -116,13 +111,12 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
selectionModel.addListSelectionListener {
enableNextButtonCallback(selectedObject != null && selectedObject?.agentStatus == RUNNING && selectedObject?.agentOS == OS.LINUX)
if (selectedObject?.agentOS != OS.LINUX) {
notificationBand.apply {
notificationBanner.apply {
isVisible = true
icon = AllIcons.General.Information
text = CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.unsupported.os.info")
showInfo(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.unsupported.os.info"))
}
} else {
notificationBand.isVisible = false
notificationBanner.component.isVisible = false
}
updateWorkspaceActions()
}
Expand All @@ -142,6 +136,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
.addExtraAction(updateWorkspaceTemplateAction)
.addExtraAction(createWorkspaceAction)


private var poller: Job? = null

override val component = panel {
Expand Down Expand Up @@ -174,15 +169,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
cell()
}
row {
scrollCell(toolbar.createPanel()).resizableColumn().horizontalAlign(HorizontalAlign.FILL).verticalAlign(VerticalAlign.FILL)
scrollCell(toolbar.createPanel().apply {
add(notificationBanner.component.apply { isVisible = false }, "South")
}).resizableColumn().horizontalAlign(HorizontalAlign.FILL).verticalAlign(VerticalAlign.FILL)
cell()
}.topGap(TopGap.NONE).resizableRow()
row {
cell(notificationBand).resizableColumn().horizontalAlign(HorizontalAlign.FILL).applyToComponent {
font = JBFont.h4().asBold()
isVisible = false
}
}
}.topGap(TopGap.NONE).bottomGap(BottomGap.NONE).resizableRow()
}
}.apply { background = WelcomeScreenUIManager.getMainAssociatedComponentBackground() }

Expand Down Expand Up @@ -317,20 +308,18 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
try {
coderClient.initClientSession(localWizardModel.coderURL.toURL(), token)
if (!CoderSemVer.isValidVersion(coderClient.buildVersion)) {
notificationBand.apply {
isVisible = true
icon = AllIcons.General.Warning
text = CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.invalid.coder.version", coderClient.buildVersion)
notificationBanner.apply {
component.isVisible = true
showWarning(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.invalid.coder.version", coderClient.buildVersion))
}
} else {
val coderVersion = CoderSemVer.parse(coderClient.buildVersion)
val testedCoderVersion = CoderSupportedVersions.lastTestedVersion

if (!testedCoderVersion.isCompatibleWith(coderVersion)) {
notificationBand.apply {
isVisible = true
icon = AllIcons.General.Warning
text = CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.unsupported.coder.version", coderClient.buildVersion)
notificationBanner.apply {
component.isVisible = true
showWarning(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.unsupported.coder.version", coderClient.buildVersion))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.coder.gateway.views.steps

import com.intellij.icons.AllIcons
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
import com.intellij.util.ui.JBUI
import javax.swing.JEditorPane
import javax.swing.JLabel

class NotificationBanner {
var component: DialogPanel
private lateinit var icon: JLabel
private lateinit var txt: JEditorPane

init {
component = panel {
row {
icon = icon(AllIcons.General.Warning).applyToComponent {
border = JBUI.Borders.empty(0, 5)
}.component
txt = text("").resizableColumn().horizontalAlign(HorizontalAlign.FILL).applyToComponent { foreground = JBUI.CurrentTheme.NotificationWarning.foregroundColor() }.component
}
}.apply {
background = JBUI.CurrentTheme.NotificationWarning.backgroundColor()
}
}

fun showWarning(warning: String) {
icon.icon = AllIcons.General.Warning
txt.apply {
text = warning
foreground = JBUI.CurrentTheme.NotificationWarning.foregroundColor()
}

component.background = JBUI.CurrentTheme.NotificationWarning.backgroundColor()

}

fun showInfo(info: String) {
icon.icon = AllIcons.General.Information
txt.apply {
text = info
foreground = JBUI.CurrentTheme.NotificationInfo.foregroundColor()
}

component.background = JBUI.CurrentTheme.NotificationInfo.backgroundColor()
}
}
4 changes: 2 additions & 2 deletions src/main/resources/messages/CoderGatewayBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ gateway.connector.view.coder.workspaces.stop.text=Stop Workspace
gateway.connector.view.coder.workspaces.update.text=Update Workspace Template
gateway.connector.view.coder.workspaces.create.text=Create workspace
gateway.connector.view.coder.workspaces.unsupported.os.info=Gateway supports only Linux machines. Support for macOS and Windows is planned.
gateway.connector.view.coder.workspaces.invalid.coder.version=Could not parse Coder version {0}. Coder Gateway plugin might not be compatible with this version.
gateway.connector.view.coder.workspaces.unsupported.coder.version=Coder version {0} might not be compatible with this plugin version.
gateway.connector.view.coder.workspaces.invalid.coder.version=Could not parse Coder version {0}. Coder Gateway plugin might not be compatible with this version. <a href='https://coder.com/docs/coder-oss/latest/ides/gateway#creating-a-new-jetbrains-gateway-connection'>Connect to a Coder workspace manually</a>
gateway.connector.view.coder.workspaces.unsupported.coder.version=Coder version {0} might not be compatible with this plugin version. <a href='https://coder.com/docs/coder-oss/latest/ides/gateway#creating-a-new-jetbrains-gateway-connection'>Connect to a Coder workspace manually</a>
gateway.connector.view.coder.remoteproject.loading.text=Retrieving products...
gateway.connector.view.coder.remoteproject.ide.error.text=Could not retrieve any IDE for workspace {0} because an error was encountered
gateway.connector.view.coder.remoteproject.next.text=Start IDE and connect
Expand Down