-
-
Notifications
You must be signed in to change notification settings - Fork 329
feat(connections): show tag and group in the connection switcher and welcome list #1752
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
datlechin
merged 3 commits into
main
from
emdash/feat-tags-groups-connection-list-vrzdq
Jun 22, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
67cd678
feat(connections): show tag and group in the connection switcher and …
datlechin acd3326
Merge remote-tracking branch 'origin/main' into emdash/feat-tags-grou…
datlechin c666eba
refactor(connections): extract testable tag-badge layout and prioriti…
datlechin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // | ||
| // ConnectionMetadataBadges.swift | ||
| // TablePro | ||
| // | ||
|
|
||
| import SwiftUI | ||
|
|
||
| enum ConnectionMetadata { | ||
| static func resolve( | ||
| connection: DatabaseConnection, | ||
| tags: [ConnectionTag], | ||
| groups: [ConnectionGroup] | ||
| ) -> (tags: [ConnectionTag], group: ConnectionGroup?) { | ||
| let resolvedTags = connection.tagIds.compactMap { id in tags.first { $0.id == id } } | ||
| let group = connection.groupId.flatMap { id in groups.first { $0.id == id } } | ||
| return (resolvedTags, group) | ||
| } | ||
| } | ||
|
|
||
| struct ConnectionTagsBadgeLayout: Equatable { | ||
| let shown: [ConnectionTag] | ||
| let overflow: Int | ||
| let name: String? | ||
|
|
||
| init(tags: [ConnectionTag]) { | ||
| let visible = Array(tags.prefix(3)) | ||
| shown = visible | ||
| overflow = tags.count - visible.count | ||
| name = tags.count == 1 ? tags.first?.name : nil | ||
| } | ||
| } | ||
|
|
||
| struct ConnectionTagsBadge: View { | ||
| let tags: [ConnectionTag] | ||
|
|
||
| var body: some View { | ||
| if !tags.isEmpty { | ||
| let layout = ConnectionTagsBadgeLayout(tags: tags) | ||
| HStack(spacing: 4) { | ||
| ForEach(layout.shown) { tag in | ||
| Circle() | ||
| .fill(tag.color.color) | ||
| .frame(width: 8, height: 8) | ||
| } | ||
| if let name = layout.name { | ||
| Text(name) | ||
| .font(.caption) | ||
| .foregroundStyle(.secondary) | ||
| .lineLimit(1) | ||
| } else if layout.overflow > 0 { | ||
| Text("+\(layout.overflow)") | ||
| .font(.caption) | ||
| .foregroundStyle(.secondary) | ||
| } | ||
| } | ||
| .help(tags.map(\.name).joined(separator: ", ")) | ||
| .accessibilityElement(children: .combine) | ||
| .accessibilityLabel(String(format: String(localized: "Tags: %@"), tags.map(\.name).joined(separator: ", "))) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct ConnectionGroupBadge: View { | ||
| let group: ConnectionGroup | ||
|
|
||
| private var iconColor: Color { | ||
| group.color.isDefault ? .secondary : group.color.color | ||
| } | ||
|
|
||
| var body: some View { | ||
| HStack(spacing: 4) { | ||
| Image(systemName: "folder") | ||
| .imageScale(.small) | ||
| .foregroundStyle(iconColor) | ||
| Text(group.name) | ||
| .font(.caption) | ||
| .foregroundStyle(.secondary) | ||
| .lineLimit(1) | ||
| } | ||
| .accessibilityElement(children: .combine) | ||
| .accessibilityLabel(String(format: String(localized: "Group: %@"), group.name)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // | ||
| // ConnectionMetadataTests.swift | ||
| // TableProTests | ||
| // | ||
|
|
||
| import Foundation | ||
| import TableProPluginKit | ||
| import Testing | ||
|
|
||
| @testable import TablePro | ||
|
|
||
| @Suite("ConnectionMetadata") | ||
| struct ConnectionMetadataTests { | ||
| private func makeConnection(tagIds: [UUID] = [], groupId: UUID? = nil) -> DatabaseConnection { | ||
| var connection = DatabaseConnection(name: "Test") | ||
| connection.tagIds = tagIds | ||
| connection.groupId = groupId | ||
| return connection | ||
| } | ||
|
|
||
| private let production = ConnectionTag(name: "production", color: .red) | ||
| private let staging = ConnectionTag(name: "staging", color: .orange) | ||
| private let group = ConnectionGroup(id: UUID(), name: "Backend", sortOrder: 0) | ||
|
|
||
| @Test("Resolves assigned tags in order and the assigned group") | ||
| func resolvesAssigned() { | ||
| let connection = makeConnection(tagIds: [staging.id, production.id], groupId: group.id) | ||
|
|
||
| let result = ConnectionMetadata.resolve( | ||
| connection: connection, | ||
| tags: [production, staging], | ||
| groups: [group] | ||
| ) | ||
|
|
||
| #expect(result.tags == [staging, production]) | ||
| #expect(result.group == group) | ||
| } | ||
|
|
||
| @Test("Returns no tags and no group when nothing is assigned") | ||
| func returnsEmptyWhenUnassigned() { | ||
| let connection = makeConnection() | ||
|
|
||
| let result = ConnectionMetadata.resolve( | ||
| connection: connection, | ||
| tags: [production], | ||
| groups: [group] | ||
| ) | ||
|
|
||
| #expect(result.tags.isEmpty) | ||
| #expect(result.group == nil) | ||
| } | ||
|
|
||
| @Test("Drops tag and group references that no longer exist") | ||
| func dropsStaleReferences() { | ||
| let connection = makeConnection(tagIds: [production.id, UUID()], groupId: UUID()) | ||
|
|
||
| let result = ConnectionMetadata.resolve( | ||
| connection: connection, | ||
| tags: [production], | ||
| groups: [group] | ||
| ) | ||
|
|
||
| #expect(result.tags == [production]) | ||
| #expect(result.group == nil) | ||
| } | ||
| } | ||
|
|
||
| @Suite("ConnectionTagsBadgeLayout") | ||
| struct ConnectionTagsBadgeLayoutTests { | ||
| private func tags(_ count: Int) -> [ConnectionTag] { | ||
| (0 ..< count).map { ConnectionTag(name: "tag\($0)") } | ||
| } | ||
|
|
||
| @Test("Empty input shows nothing") | ||
| func empty() { | ||
| let layout = ConnectionTagsBadgeLayout(tags: []) | ||
|
|
||
| #expect(layout.shown.isEmpty) | ||
| #expect(layout.overflow == 0) | ||
| #expect(layout.name == nil) | ||
| } | ||
|
|
||
| @Test("A single tag shows its name and no overflow") | ||
| func single() { | ||
| let tag = ConnectionTag(name: "production") | ||
| let layout = ConnectionTagsBadgeLayout(tags: [tag]) | ||
|
|
||
| #expect(layout.shown == [tag]) | ||
| #expect(layout.overflow == 0) | ||
| #expect(layout.name == "production") | ||
| } | ||
|
|
||
| @Test("Up to three tags show dots only, no name and no overflow") | ||
| func threeShowDotsOnly() { | ||
| let layout = ConnectionTagsBadgeLayout(tags: tags(3)) | ||
|
|
||
| #expect(layout.shown.count == 3) | ||
| #expect(layout.overflow == 0) | ||
| #expect(layout.name == nil) | ||
| } | ||
|
|
||
| @Test("More than three tags cap at three dots and report the overflow count") | ||
| func overflow() { | ||
| let layout = ConnectionTagsBadgeLayout(tags: tags(5)) | ||
|
|
||
| #expect(layout.shown.count == 3) | ||
| #expect(layout.overflow == 2) | ||
| #expect(layout.name == nil) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When an already-open connection is edited or moved to a group, the form/group actions update
ConnectionStoragebut do not refreshDatabaseManager.activeSessions[...].connection; because active rows resolve badges from that session snapshot and the saved copy is filtered out ofinactiveSaved, reopening the switcher can keep showing the old tag/group or no group until the connection is reconnected. Use the current saved connection for the metadata lookup when the row is active, or update the session metadata on connection changes.Useful? React with 👍 / 👎.