fix race condition in declarative table (#15801)

This commit is contained in:
Alan Ren
2021-06-18 11:40:19 -07:00
committed by GitHub
parent 4c2f6eafe0
commit aeda95bb70
6 changed files with 24 additions and 8 deletions

View File

@@ -109,7 +109,8 @@ export function createViewContext(): ViewTestContext {
onRowSelected: undefined!,
setFilter: undefined!,
data: [],
columns: []
columns: [],
setDataValues: undefined!
});
let loadingComponent: () => azdata.LoadingComponent = () => Object.assign({}, componentBase, {

View File

@@ -350,6 +350,7 @@ class TestDeclarativeTableComponent extends TestComponentBase implements azdata.
setFilter: undefined;
data: any[][];
columns: azdata.DeclarativeTableColumn[];
setDataValues: undefined;
}
class TestButtonComponent extends TestComponentBase implements azdata.ButtonComponent {

View File

@@ -186,7 +186,8 @@ describe('Manage Package Dialog', () => {
onRowSelected: undefined!,
setFilter: undefined!,
data: [],
columns: []
columns: [],
setDataValues: undefined!
});
let loadingComponent: () => azdata.LoadingComponent = () => Object.assign({}, componentBase, {

View File

@@ -274,6 +274,12 @@ declare module 'azdata' {
* will clear the filter
*/
setFilter(rowIndexes: number[] | undefined): void;
/**
* Sets the data values.
* @param v The new data values
*/
setDataValues(v: DeclarativeTableCellValue[][]): Promise<void>;
}
/*
@@ -372,7 +378,8 @@ declare module 'azdata' {
export interface DeclarativeTableProperties {
/**
* dataValues will only be used if data is an empty array
* dataValues will only be used if data is an empty array.
* To set the dataValues, it is recommended to use the setDataValues method that returns a promise.
*/
dataValues?: DeclarativeTableCellValue[][];

View File

@@ -1568,6 +1568,11 @@ class DeclarativeTableWrapper extends ComponentWrapper implements azdata.Declara
});
}
async setDataValues(v: azdata.DeclarativeTableCellValue[][]): Promise<void> {
await this.clearItems();
await this.setProperty('dataValues', v);
}
public get columns(): azdata.DeclarativeTableColumn[] {
return this.properties['columns'];
}

View File

@@ -298,17 +298,18 @@ export default class DeclarativeTableComponent extends ContainerBase<any, azdata
this._data = finalData;
}
const newSelectedRow = properties.selectedRow ?? -1;
if (newSelectedRow !== this.selectedRow && properties.enableRowSelection) {
const previousSelectedRow = this.selectedRow;
super.setProperties(properties);
if (this.selectedRow !== previousSelectedRow && this.enableRowSelection) {
this.fireEvent({
eventType: ComponentEventType.onSelectedRowChanged,
args: {
row: properties.selectedRow
row: this.selectedRow
}
});
}
super.setProperties(properties);
}
public override clearContainer(): void {