@@ -14,20 +14,20 @@ namespace K8sFileBrowser.ViewModels;
14
14
15
15
public class MainWindowViewModel : ViewModelBase
16
16
{
17
- private ObservableAsPropertyHelper < IEnumerable < ClusterContext > > _clusterContexts = null ! ;
18
- public IEnumerable < ClusterContext > ClusterContexts => _clusterContexts . Value ;
17
+ [ Reactive ]
18
+ public IEnumerable < ClusterContext > ClusterContexts { get ; set ; } = null ! ;
19
19
20
20
[ Reactive ]
21
21
public ClusterContext ? SelectedClusterContext { get ; set ; }
22
22
23
23
[ Reactive ]
24
- public IEnumerable < Namespace > Namespaces { get ; set ; }
24
+ public IEnumerable < Namespace > Namespaces { get ; set ; } = null ! ;
25
25
26
26
[ Reactive ]
27
27
public Namespace ? SelectedNamespace { get ; set ; }
28
28
29
- private ObservableAsPropertyHelper < IEnumerable < Pod > > _pods = null ! ;
30
- public IEnumerable < Pod > Pods => _pods . Value ;
29
+ [ Reactive ]
30
+ public IEnumerable < Pod > Pods { get ; set ; } = null ! ;
31
31
32
32
[ Reactive ]
33
33
public Pod ? SelectedPod { get ; set ; }
@@ -38,8 +38,8 @@ public class MainWindowViewModel : ViewModelBase
38
38
[ Reactive ]
39
39
public Container ? SelectedContainer { get ; set ; }
40
40
41
- private ObservableAsPropertyHelper < IEnumerable < FileInformation > > _fileInformation = null ! ;
42
- public IEnumerable < FileInformation > FileInformation => _fileInformation . Value ;
41
+ [ Reactive ]
42
+ public IEnumerable < FileInformation > FileInformation { get ; set ; } = null ! ;
43
43
44
44
[ Reactive ]
45
45
public FileInformation ? SelectedFile { get ; set ; }
@@ -48,7 +48,7 @@ public class MainWindowViewModel : ViewModelBase
48
48
public string ? SelectedPath { get ; set ; }
49
49
50
50
[ Reactive ]
51
- public Message Message { get ; set ; }
51
+ public Message Message { get ; set ; } = null ! ;
52
52
53
53
public ReactiveCommand < Unit , Unit > DownloadCommand { get ; private set ; } = null ! ;
54
54
public ReactiveCommand < Unit , Unit > DownloadLogCommand { get ; private set ; } = null ! ;
@@ -86,18 +86,22 @@ private void InitiallyLoadContexts(IKubernetesService kubernetesService)
86
86
// load the cluster contexts when the view model is created
87
87
var loadContexts = ReactiveCommand
88
88
. Create < Unit , IEnumerable < ClusterContext > > ( _ => kubernetesService . GetClusterContexts ( ) ) ;
89
- _clusterContexts = loadContexts . Execute ( ) . ToProperty (
90
- this , x => x . ClusterContexts , scheduler : RxApp . MainThreadScheduler ) ;
91
-
92
- // select the current cluster context
93
- SelectedClusterContext = ClusterContexts
94
- . FirstOrDefault ( x => x . Name == kubernetesService . GetCurrentContext ( ) ) ;
89
+ loadContexts . Execute ( )
90
+ . Throttle ( new TimeSpan ( 10 ) )
91
+ . ObserveOn ( RxApp . MainThreadScheduler )
92
+ . Subscribe ( x =>
93
+ {
94
+ ClusterContexts = x ;
95
+ // select the current cluster context
96
+ SelectedClusterContext = ClusterContexts
97
+ . FirstOrDefault ( x => x . Name == kubernetesService . GetCurrentContext ( ) ) ;
98
+ } ) ;
95
99
}
96
100
97
101
private void RegisterResetPath ( )
98
102
{
99
103
// reset the path when the pod or namespace changes
100
- this . WhenAnyValue ( c => c . SelectedPod , c => c . SelectedNamespace )
104
+ this . WhenAnyValue ( c => c . SelectedContainer )
101
105
. Throttle ( new TimeSpan ( 10 ) )
102
106
. ObserveOn ( RxApp . TaskpoolScheduler )
103
107
. Subscribe ( _ => SelectedPath = "/" ) ;
@@ -107,13 +111,17 @@ private void RegisterReadContainers()
107
111
{
108
112
// read the file information when the path changes
109
113
this
110
- . WhenAnyValue ( c => c . SelectedPod , c => c . SelectedNamespace )
114
+ . WhenAnyValue ( c => c . SelectedPod )
111
115
. Throttle ( new TimeSpan ( 10 ) )
112
- . Select ( x => x . Item2 == null || x . Item1 == null
116
+ . Select ( x => x == null
113
117
? new List < Container > ( )
114
- : x . Item1 . Containers . Select ( c => new Container { Name = c } ) )
118
+ : x . Containers . Select ( c => new Container { Name = c } ) )
115
119
. ObserveOn ( RxApp . MainThreadScheduler )
116
- . Subscribe ( x => Containers = x ) ;
120
+ . Subscribe ( x =>
121
+ {
122
+ Containers = x ;
123
+ FileInformation = new List < FileInformation > ( ) ;
124
+ } ) ;
117
125
118
126
this . WhenAnyValue ( x => x . Containers )
119
127
. Throttle ( new TimeSpan ( 10 ) )
@@ -124,25 +132,30 @@ private void RegisterReadContainers()
124
132
private void RegisterReadFiles ( IKubernetesService kubernetesService )
125
133
{
126
134
// read the file information when the path changes
127
- _fileInformation = this
128
- . WhenAnyValue ( c => c . SelectedPath , c => c . SelectedPod , c => c . SelectedNamespace , c => c . SelectedContainer )
135
+ this
136
+ . WhenAnyValue ( c => c . SelectedContainer )
129
137
. Throttle ( new TimeSpan ( 10 ) )
130
- . Select ( x => x . Item3 == null || x . Item2 == null || x . Item1 == null || x . Item4 == null
138
+ . Select ( x => x == null
131
139
? new List < FileInformation > ( )
132
- : GetFileInformation ( kubernetesService , x . Item1 , x . Item2 , x . Item3 , x . Item4 ) )
140
+ : GetFileInformation ( kubernetesService , SelectedPath ! , SelectedPod ! , SelectedNamespace ! , x ) )
133
141
. ObserveOn ( RxApp . MainThreadScheduler )
134
- . ToProperty ( this , x => x . FileInformation ) ;
142
+ . Subscribe ( x => FileInformation = x ) ;
135
143
}
136
144
137
145
private void RegisterReadPods ( )
138
146
{
139
147
// read the pods when the namespace changes
140
- _pods = this
148
+ this
141
149
. WhenAnyValue ( c => c . SelectedNamespace )
142
150
. Throttle ( new TimeSpan ( 10 ) )
143
151
. SelectMany ( ns => GetPodsForNamespace . Execute ( ns ! ) )
144
152
. ObserveOn ( RxApp . MainThreadScheduler )
145
- . ToProperty ( this , x => x . Pods ) ;
153
+ . Subscribe ( x =>
154
+ {
155
+ Pods = x ;
156
+ Containers = null ;
157
+ FileInformation = new List < FileInformation > ( ) ;
158
+ } ) ;
146
159
}
147
160
148
161
private void RegisterReadNamespaces ( IKubernetesService kubernetesService )
@@ -153,7 +166,13 @@ private void RegisterReadNamespaces(IKubernetesService kubernetesService)
153
166
. Throttle ( new TimeSpan ( 10 ) )
154
167
. SelectMany ( context => GetClusterContextAsync ( context , kubernetesService ) )
155
168
. ObserveOn ( RxApp . MainThreadScheduler )
156
- . Subscribe ( ns => Namespaces = ns ) ;
169
+ . Subscribe ( ns =>
170
+ {
171
+ Namespaces = ns ;
172
+ Pods = new List < Pod > ( ) ;
173
+ Containers = null ;
174
+ FileInformation = new List < FileInformation > ( ) ;
175
+ } ) ;
157
176
}
158
177
159
178
private void ConfigureGetPodsForNamespaceCommand ( IKubernetesService kubernetesService )
0 commit comments