Skip to content

Commit d364364

Browse files
wanghoppehoppe
andauthored
fix certificate display list issue (#2815)
* fix cert list display * update model-list-view --------- Co-authored-by: hoppe <hoppewang@microsoft.com>
1 parent 54a9e5e commit d364364

4 files changed

Lines changed: 31 additions & 31 deletions

File tree

packages/react/src/components/certificate/certificate-list.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const CertificateList = observer((props: CertificateListProps) => {
2929
{ prop: "stateTransitionTime", label: "Last Updated" },
3030
]}
3131
items={view.items}
32+
hasMore={view.loading}
3233
/>
3334
);
3435
});

packages/react/src/components/certificate/certificate-page.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export const CertificatePage = observer(() => {
1919
new CertificateListView(new CertificateService())
2020
);
2121

22+
const onCertificateSelected = React.useCallback(
23+
(_, index) => {
24+
certListView.clearSelection();
25+
certListView.selectByIndex(index);
26+
},
27+
[certListView]
28+
);
29+
2230
useAsyncEffect(async () => {
2331
await certListView.load();
2432
}, [certListView]);
@@ -27,10 +35,7 @@ export const CertificatePage = observer(() => {
2735
<Stack tokens={{ childrenGap: 16 }}>
2836
<CertificateList
2937
view={certListView}
30-
onCertificateSelected={(_, index) => {
31-
certListView.clearSelection();
32-
certListView.selectByIndex(index);
33-
}}
38+
onCertificateSelected={onCertificateSelected}
3439
/>
3540
<DisplayPane
3641
title="Certificates"

packages/service/src/certificate/certificate-list-view.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DependencyName, getEnvironment, getLogger } from "@azure/bonito-core";
22
import { MockHttpClient, MockHttpResponse } from "@azure/bonito-core/lib/http";
3-
import { action, IObservableArray, makeObservable, observable } from "mobx";
3+
import { action, makeObservable, observable, runInAction } from "mobx";
44
import { AbstractModelListView, SelectableListView } from "../view";
55
import { Certificate } from "./certificate-models";
66
import 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
}
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { action, computed, IObservableArray, observable } from "mobx";
1+
import { action, computed, observable } from "mobx";
22
import { View } from "./view";
33

44
export interface ModelListView<S, T> extends View {
55
readonly service: S;
6-
readonly items: IObservableArray<T>;
6+
readonly items: T[];
77
length: number;
8-
update(items: T[]): void;
98
}
109

1110
export interface SelectableListView<T> {
12-
readonly selectedItems: IObservableArray<T>;
11+
readonly selectedItems: T[];
1312
selectByIndex(index: number): void;
1413
clearSelection(): void;
1514
}
@@ -19,8 +18,8 @@ export abstract class AbstractModelListView<S, T>
1918
{
2019
readonly service: S;
2120

22-
@observable items: IObservableArray<T>;
23-
@observable loading: boolean;
21+
@observable items: T[] = [];
22+
@observable loading: boolean = false;
2423

2524
@computed
2625
get length(): number {
@@ -29,15 +28,11 @@ export abstract class AbstractModelListView<S, T>
2928

3029
constructor(service: S, items: T[] = []) {
3130
this.service = service;
32-
this.items = observable([]);
33-
this.loading = false;
34-
this.update(items);
31+
this.items = items;
3532
}
3633

3734
@action
3835
clear(): void {
39-
this.items.clear();
36+
this.items = [];
4037
}
41-
42-
abstract update(items: T[]): void;
4338
}

0 commit comments

Comments
 (0)