Arc - Fix KeyValueContainer refresh (#11077)

This commit is contained in:
Brian Bergeron
2020-06-24 14:19:21 -07:00
committed by GitHub
parent de263eacd1
commit e1bbbf2c9e
2 changed files with 19 additions and 7 deletions

View File

@@ -11,24 +11,37 @@ import { IconPathHelper, cssStyles } from '../../constants';
/** A container with a single vertical column of KeyValue pairs */ /** A container with a single vertical column of KeyValue pairs */
export class KeyValueContainer { export class KeyValueContainer {
public container: azdata.DivContainer; public container: azdata.DivContainer;
private keyToComponent: Map<string, (azdata.TextComponent | azdata.InputBoxComponent)>;
constructor(private modelBuilder: azdata.ModelBuilder, pairs: KeyValue[]) { constructor(private modelBuilder: azdata.ModelBuilder, pairs: KeyValue[]) {
this.container = modelBuilder.divContainer().component(); this.container = modelBuilder.divContainer().component();
this.keyToComponent = new Map<string, azdata.Component>();
this.refresh(pairs); this.refresh(pairs);
} }
// TODO: Support removing KeyValues, and handle race conditions when
// adding/removing KeyValues concurrently. For now this should only be used
// when the set of keys won't change (though their values can be refreshed).
public refresh(pairs: KeyValue[]) { public refresh(pairs: KeyValue[]) {
this.container.clearItems(); pairs.forEach(p => {
this.container.addItems( let component = this.keyToComponent.get(p.key);
pairs.map(p => p.getComponent(this.modelBuilder)), if (component) {
{ CSSStyles: { 'margin-bottom': '15px', 'min-height': '30px' } } component.value = p.value;
); } else {
component = p.getComponent(this.modelBuilder);
this.keyToComponent.set(p.key, component);
this.container.addItem(
component,
{ CSSStyles: { 'margin-bottom': '15px', 'min-height': '30px' } }
);
}
});
} }
} }
/** A key value pair in the KeyValueContainer */ /** A key value pair in the KeyValueContainer */
export abstract class KeyValue { export abstract class KeyValue {
constructor(protected key: string, protected value: string) { } constructor(public key: string, public value: string) { }
/** Returns a component representing the entire KeyValue pair */ /** Returns a component representing the entire KeyValue pair */
public getComponent(modelBuilder: azdata.ModelBuilder) { public getComponent(modelBuilder: azdata.ModelBuilder) {

View File

@@ -383,7 +383,6 @@ export class PostgresOverviewPage extends DashboardPage {
this.nodesTable!.data = this.getNodes(); this.nodesTable!.data = this.getNodes();
this.nodesTableLoading!.loading = false; this.nodesTableLoading!.loading = false;
} }
private handlePodsUpdated() { private handlePodsUpdated() {