Skip to content

Commit 72f30f0

Browse files
committed
impl: sort table by workspace name, template name or status
1 parent 1793f91 commit 72f30f0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Added
88
- ability to open a template in the Dashboard
9+
- ability to sort by workspace name, or by template name or by workspace status
910

1011
### Changed
1112
- renamed the plugin from `Coder Gateway` to `Gateway`

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,16 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
656656
return workspace?.name
657657
}
658658

659+
override fun getComparator(): Comparator<WorkspaceAgentModel>? {
660+
return Comparator { a, b ->
661+
if (a === b) 0
662+
if (a == null) -1
663+
if (b == null) 1
664+
665+
a.name.compareTo(b.name, ignoreCase = true)
666+
}
667+
}
668+
659669
override fun getRenderer(item: WorkspaceAgentModel?): TableCellRenderer {
660670
return object : DefaultTableCellRenderer() {
661671
override fun getTableCellRendererComponent(table: JTable, value: Any, isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component {
@@ -676,6 +686,16 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
676686
return workspace?.templateName
677687
}
678688

689+
override fun getComparator(): java.util.Comparator<WorkspaceAgentModel>? {
690+
return Comparator { a, b ->
691+
if (a === b) 0
692+
if (a == null) -1
693+
if (b == null) 1
694+
695+
a.templateName.compareTo(b.templateName, ignoreCase = true)
696+
}
697+
}
698+
679699
override fun getRenderer(item: WorkspaceAgentModel?): TableCellRenderer {
680700
val simpleH3 = JBFont.h3()
681701

@@ -729,6 +749,16 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
729749
return workspace?.agentStatus?.label
730750
}
731751

752+
override fun getComparator(): java.util.Comparator<WorkspaceAgentModel>? {
753+
return Comparator { a, b ->
754+
if (a === b) 0
755+
if (a == null) -1
756+
if (b == null) 1
757+
758+
a.agentStatus.label.compareTo(b.agentStatus.label, ignoreCase = true)
759+
}
760+
}
761+
732762
override fun getRenderer(item: WorkspaceAgentModel?): TableCellRenderer {
733763
return object : DefaultTableCellRenderer() {
734764
override fun getTableCellRendererComponent(table: JTable, value: Any, isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component {

0 commit comments

Comments
 (0)