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!, onRowSelected: undefined!,
setFilter: undefined!, setFilter: undefined!,
data: [], data: [],
columns: [] columns: [],
setDataValues: undefined!
}); });
let loadingComponent: () => azdata.LoadingComponent = () => Object.assign({}, componentBase, { let loadingComponent: () => azdata.LoadingComponent = () => Object.assign({}, componentBase, {

View File

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

View File

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

View File

@@ -274,6 +274,12 @@ declare module 'azdata' {
* will clear the filter * will clear the filter
*/ */
setFilter(rowIndexes: number[] | undefined): void; 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 { 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[][]; 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[] { public get columns(): azdata.DeclarativeTableColumn[] {
return this.properties['columns']; return this.properties['columns'];
} }

View File

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