11import { DependencyName , getEnvironment , getLogger } from "@azure/bonito-core" ;
22import { MockHttpClient , MockHttpResponse } from "@azure/bonito-core/lib/http" ;
3- import { action , IObservableArray , makeObservable , observable } from "mobx" ;
3+ import { action , makeObservable , observable , runInAction } from "mobx" ;
44import { AbstractModelListView , SelectableListView } from "../view" ;
55import { Certificate } from "./certificate-models" ;
66import type { CertificateService } from "./certificate-service" ;
@@ -12,27 +12,18 @@ export class CertificateListView
1212 extends AbstractModelListView < CertificateService , Certificate >
1313 implements SelectableListView < Certificate >
1414{
15- @observable selectedItems : IObservableArray < Certificate > ;
15+ @observable selectedItems : Certificate [ ] = [ ] ;
1616 @observable batchAccount : string ;
1717
1818 private _logger = getLogger ( "CertificateListView" ) ;
1919
2020 constructor ( service : CertificateService , models : Certificate [ ] = [ ] ) {
2121 super ( service , models ) ;
22- this . selectedItems = observable ( [ ] ) ;
2322 // TODO: Get Batch account either from the URL or the context
2423 this . batchAccount = "prodtest1" ;
2524 makeObservable ( this ) ;
2625 }
2726
28- @action
29- update ( items : Certificate [ ] ) : void {
30- this . clear ( ) ;
31- for ( const cert of items ) {
32- this . items . push ( cert ) ;
33- }
34- }
35-
3627 firstSelection ( ) : Certificate | null {
3728 if ( this . selectedItems . length > 0 ) {
3829 return this . selectedItems [ 0 ] ;
@@ -51,13 +42,14 @@ export class CertificateListView
5142
5243 @action
5344 clearSelection ( ) : void {
54- this . selectedItems . clear ( ) ;
45+ this . selectedItems = [ ] ;
5546 }
5647
5748 /**
5849 * Gets new models from the service and updates the model list
5950 */
6051 async load ( ) : Promise < void > {
52+ this . loading = true ;
6153 // KLUDGE: Mock out the call to list certificates until HTTP auth is supported
6254 const httpClient : MockHttpClient = getEnvironment ( ) . getInjectable (
6355 DependencyName . HttpClient
@@ -100,8 +92,15 @@ export class CertificateListView
10092 } ) ,
10193 } )
10294 ) ;
103-
104- const result = await this . service . listAll ( ) ;
105- this . update ( result . models ) ;
95+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
96+ try {
97+ const result = await this . service . listAll ( ) ;
98+ runInAction ( ( ) => {
99+ this . loading = false ;
100+ this . items = result . models ;
101+ } ) ;
102+ } finally {
103+ this . loading = false ;
104+ }
106105 }
107106}
0 commit comments