@@ -13,6 +13,36 @@ internal struct FavoriteEditItem: Identifiable {
1313 let folderId : UUID ?
1414}
1515
16+ internal enum FavoriteSelection : Hashable {
17+ case table( schema: String ? , name: String )
18+ case node( id: String )
19+ }
20+
21+ extension FavoriteSelection : RawRepresentable {
22+ private static let separator = " \u{1} "
23+
24+ init ? ( rawValue: String ) {
25+ let parts = rawValue. components ( separatedBy: Self . separator)
26+ switch parts. first {
27+ case " table " where parts. count == 3 :
28+ self = . table( schema: parts [ 1 ] . isEmpty ? nil : parts [ 1 ] , name: parts [ 2 ] )
29+ case " node " where parts. count >= 2 :
30+ self = . node( id: parts. dropFirst ( ) . joined ( separator: Self . separator) )
31+ default :
32+ return nil
33+ }
34+ }
35+
36+ var rawValue : String {
37+ switch self {
38+ case . table( let schema, let name) :
39+ return [ " table " , schema ?? " " , name] . joined ( separator: Self . separator)
40+ case . node( let id) :
41+ return [ " node " , id] . joined ( separator: Self . separator)
42+ }
43+ }
44+ }
45+
1646internal struct FavoriteNode : Identifiable , Hashable {
1747 enum Content : Hashable {
1848 case folder( SQLFavoriteFolder )
@@ -353,20 +383,8 @@ internal final class FavoritesSidebarViewModel {
353383 }
354384 }
355385
356- func favoriteForNodeId( _ id: String ) -> SQLFavorite ? {
357- findNode ( nodes, id: id, extract: \. asFavorite)
358- }
359-
360- func linkedFavoriteForNodeId( _ id: String ) -> LinkedSQLFavorite ? {
361- findNode ( nodes, id: id, extract: \. asLinkedFavorite)
362- }
363-
364- func folderForNodeId( _ id: String ) -> SQLFavoriteFolder ? {
365- findNode ( nodes, id: id, extract: \. asFolder)
366- }
367-
368- func linkedFolderForNodeId( _ id: String ) -> LinkedSQLFolder ? {
369- findNode ( nodes, id: id, extract: \. asLinkedFolder)
386+ func node( forId id: String ) -> FavoriteNode ? {
387+ findNode ( nodes, id: id, extract: { $0 } )
370388 }
371389
372390 private func findNode< T> (
0 commit comments