fix agent types (#13340)

This commit is contained in:
Aditya Bist
2020-11-10 13:38:57 -08:00
committed by GitHub
parent d7a6b55f82
commit 8bbcfff119
5 changed files with 42 additions and 57 deletions

View File

@@ -22,7 +22,7 @@ export interface CommandEventArgs<T extends Slick.SlickData> {
export class HeaderFilter<T extends Slick.SlickData> { export class HeaderFilter<T extends Slick.SlickData> {
public onFilterApplied = new Slick.Event(); public onFilterApplied = new Slick.Event<{ grid: Slick.Grid<T>, column: IExtendedColumn<T>}>();
public onCommand = new Slick.Event<CommandEventArgs<T>>(); public onCommand = new Slick.Event<CommandEventArgs<T>>();
private grid!: Slick.Grid<T>; private grid!: Slick.Grid<T>;
@@ -331,7 +331,7 @@ export class HeaderFilter<T extends Slick.SlickData> {
private handleApply(e: JQuery.Event<HTMLElement, null>, columnDef: Slick.Column<T>) { private handleApply(e: JQuery.Event<HTMLElement, null>, columnDef: Slick.Column<T>) {
this.hideMenu(); this.hideMenu();
this.onFilterApplied.notify({ 'grid': this.grid, 'column': columnDef }, e, self); this.onFilterApplied.notify({ grid: this.grid, column: columnDef }, e, self);
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
} }

View File

@@ -79,12 +79,12 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
private _jobCacheObject: JobCacheObject; private _jobCacheObject: JobCacheObject;
private rowDetail: RowDetailView<IItem>; private rowDetail: RowDetailView<IItem>;
private filterPlugin: any; private filterPlugin: HeaderFilter<IItem>;
private dataView: any; private dataView: Slick.Data.DataView<IItem>;
public _isCloud: boolean; public _isCloud: boolean;
private filterStylingMap: { [columnName: string]: [any]; } = {}; private filterStylingMap: { [columnName: string]: IItem[]; } = {};
private filterStack = ['start']; private filterStack = ['start'];
private filterValueMap: { [columnName: string]: string[]; } = {}; private filterValueMap: { [columnName: string]: { filterValues: string[], filteredItems: IItem[] } } = {};
private sortingStylingMap: { [columnName: string]: any; } = {}; private sortingStylingMap: { [columnName: string]: any; } = {};
public jobs: azdata.AgentJobInfo[]; public jobs: azdata.AgentJobInfo[];
@@ -157,7 +157,7 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
column.rerenderOnResize = true; column.rerenderOnResize = true;
return column; return column;
}); });
let options = <Slick.GridOptions<any>>{ let options = <Slick.GridOptions<IItem>>{
syncColumnCellResize: true, syncColumnCellResize: true,
enableColumnReorder: false, enableColumnReorder: false,
rowHeight: ROW_HEIGHT, rowHeight: ROW_HEIGHT,
@@ -181,7 +181,7 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
}); });
this.rowDetail = rowDetail; this.rowDetail = rowDetail;
columns.unshift(this.rowDetail.getColumnDefinition()); columns.unshift(this.rowDetail.getColumnDefinition());
let filterPlugin = new HeaderFilter<{ inlineFilters: false }>(); let filterPlugin = new HeaderFilter<IItem>();
this._register(attachButtonStyler(filterPlugin, this._themeService)); this._register(attachButtonStyler(filterPlugin, this._themeService));
this.filterPlugin = filterPlugin; this.filterPlugin = filterPlugin;
jQuery(this._gridEl.nativeElement).empty(); jQuery(this._gridEl.nativeElement).empty();
@@ -254,6 +254,7 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
this._table.grid.resetActiveCell(); this._table.grid.resetActiveCell();
let filterValues = args.column.filterValues; let filterValues = args.column.filterValues;
if (filterValues) { if (filterValues) {
let currentFilteredItems = this.dataView.getFilteredItems();
if (filterValues.length === 0) { if (filterValues.length === 0) {
// if an associated styling exists with the current filters // if an associated styling exists with the current filters
if (this.filterStylingMap[args.column.name]) { if (this.filterStylingMap[args.column.name]) {
@@ -270,9 +271,8 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
delete this.filterValueMap[args.column.name]; delete this.filterValueMap[args.column.name];
} }
// apply the previous filter styling // apply the previous filter styling
let currentItems = this.dataView.getFilteredItems(); let previousFilteredItems = this.filterValueMap[this.filterStack[this.filterStack.length - 1]].filteredItems;
let styledItems = this.filterValueMap[this.filterStack[this.filterStack.length - 1]][1]; if (previousFilteredItems === currentFilteredItems) {
if (styledItems === currentItems) {
let lastColStyle = this.filterStylingMap[this.filterStack[this.filterStack.length - 1]]; let lastColStyle = this.filterStylingMap[this.filterStack[this.filterStack.length - 1]];
for (let i = 0; i < lastColStyle.length; i++) { for (let i = 0; i < lastColStyle.length; i++) {
this._table.grid.setCellCssStyles(lastColStyle[i][0], lastColStyle[i][1]); this._table.grid.setCellCssStyles(lastColStyle[i][0], lastColStyle[i][1]);
@@ -280,14 +280,13 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
} else { } else {
// style it all over again // style it all over again
let seenJobs = 0; let seenJobs = 0;
for (let i = 0; i < currentItems.length; i++) { for (let i = 0; i < currentFilteredItems.length; i++) {
this._table.grid.removeCellCssStyles('error-row' + i.toString()); this._table.grid.removeCellCssStyles('error-row' + i.toString());
let item = this.dataView.getFilteredItems()[i]; let item = this.dataView.getFilteredItems()[i];
if (item.lastRunOutcome === 'Failed') { if (item.lastRunOutcome === 'Failed') {
this.addToStyleHash(seenJobs, false, this.filterStylingMap, args.column.name); this.addToStyleHash(seenJobs, false, this.filterStylingMap, args.column.name);
if (this.filterStack.indexOf(args.column.name) < 0) { if (this.filterStack.indexOf(args.column.name) < 0) {
this.filterStack.push(args.column.name); this.filterStack.push(args.column.name);
this.filterValueMap[args.column.name] = [filterValues];
} }
// one expansion for the row and one for // one expansion for the row and one for
// the error detail // the error detail
@@ -297,7 +296,6 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
seenJobs++; seenJobs++;
} }
this.dataView.refresh(); this.dataView.refresh();
this.filterValueMap[args.column.name].push(this.dataView.getFilteredItems());
this._table.grid.resetActiveCell(); this._table.grid.resetActiveCell();
} }
if (this.filterStack.length === 0) { if (this.filterStack.length === 0) {
@@ -312,12 +310,11 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
// current filter // current filter
if (filterValues.find(x => x === item[args.column.field])) { if (filterValues.find(x => x === item[args.column.field])) {
// check all previous filters // check all previous filters
if (this.checkPreviousFilters(item)) { if (this.isItemFiltered(item)) {
if (item.lastRunOutcome === 'Failed') { if (item.lastRunOutcome === 'Failed') {
this.addToStyleHash(seenJobs, false, this.filterStylingMap, args.column.name); this.addToStyleHash(seenJobs, false, this.filterStylingMap, args.column.name);
if (this.filterStack.indexOf(args.column.name) < 0) { if (this.filterStack.indexOf(args.column.name) < 0) {
this.filterStack.push(args.column.name); this.filterStack.push(args.column.name);
this.filterValueMap[args.column.name] = [filterValues];
} }
// one expansion for the row and one for // one expansion for the row and one for
// the error detail // the error detail
@@ -329,11 +326,7 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
} }
} }
this.dataView.refresh(); this.dataView.refresh();
if (this.filterValueMap[args.column.name]) { this.filterValueMap[args.column.name] = { filterValues: filterValues, filteredItems: this.dataView.getFilteredItems() };
this.filterValueMap[args.column.name].push(this.dataView.getFilteredItems());
} else {
this.filterValueMap[args.column.name] = this.dataView.getFilteredItems();
}
this._table.grid.resetActiveCell(); this._table.grid.resetActiveCell();
} }
@@ -389,7 +382,7 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
// cache the dataview for future use // cache the dataview for future use
this._jobCacheObject.dataView = this.dataView; this._jobCacheObject.dataView = this.dataView;
this.filterValueMap['start'] = [[], this.dataView.getItems()]; this.filterValueMap['start'] = { filterValues: [], filteredItems: this.dataView.getItems() };
this.loadJobHistories().catch(onUnexpectedError); this.loadJobHistories().catch(onUnexpectedError);
} }
@@ -559,12 +552,13 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe
return [failing, nonFailing]; return [failing, nonFailing];
} }
private checkPreviousFilters(item): boolean { /**
* Returns true if the item matches all filters currently applied
*/
private isItemFiltered(item: IItem): boolean {
for (let column in this.filterValueMap) { for (let column in this.filterValueMap) {
if (column !== 'start' && this.filterValueMap[column][0].length > 0) { if (column !== 'start' && this.filterValueMap[column]) {
let temp = this.filterValueMap[column][0] as unknown; if (!this.filterValueMap[column].filterValues.includes(item[JobManagementUtilities.convertColNameToField(column)])) {
let arr = temp as [];
if (!arr.find(x => x === item[JobManagementUtilities.convertColNameToField(column)])) {
return false; return false;
} }
} }

View File

@@ -78,12 +78,12 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
private _notebookCacheObject: NotebookCacheObject; private _notebookCacheObject: NotebookCacheObject;
private rowDetail: RowDetailView<IItem>; private rowDetail: RowDetailView<IItem>;
private filterPlugin: any; private filterPlugin: HeaderFilter<IItem>;
private dataView: any; private dataView: Slick.Data.DataView<IItem>;
public _isCloud: boolean; public _isCloud: boolean;
private filterStylingMap: { [columnName: string]: [any]; } = {}; private filterStylingMap: { [columnName: string]: IItem[]; } = {};
private filterStack = ['start']; private filterStack = ['start'];
private filterValueMap: { [columnName: string]: string[]; } = {}; private filterValueMap: { [columnName: string]: { filterValues: string[], filteredItems: IItem[] } } = {};
private sortingStylingMap: { [columnName: string]: any; } = {}; private sortingStylingMap: { [columnName: string]: any; } = {};
public notebooks: azdata.AgentNotebookInfo[]; public notebooks: azdata.AgentNotebookInfo[];
@@ -156,7 +156,7 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
column.rerenderOnResize = true; column.rerenderOnResize = true;
return column; return column;
}); });
let options = <Slick.GridOptions<any>>{ let options = <Slick.GridOptions<IItem>>{
syncColumnCellResize: true, syncColumnCellResize: true,
enableColumnReorder: false, enableColumnReorder: false,
rowHeight: ROW_HEIGHT, rowHeight: ROW_HEIGHT,
@@ -180,7 +180,7 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
}); });
this.rowDetail = rowDetail; this.rowDetail = rowDetail;
columns.unshift(this.rowDetail.getColumnDefinition()); columns.unshift(this.rowDetail.getColumnDefinition());
let filterPlugin = new HeaderFilter<{ inlineFilters: false }>(); let filterPlugin = new HeaderFilter<IItem>();
this._register(attachButtonStyler(filterPlugin, this._themeService)); this._register(attachButtonStyler(filterPlugin, this._themeService));
this.filterPlugin = filterPlugin; this.filterPlugin = filterPlugin;
jQuery(this._gridEl.nativeElement).empty(); jQuery(this._gridEl.nativeElement).empty();
@@ -260,6 +260,7 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
this._table.grid.resetActiveCell(); this._table.grid.resetActiveCell();
let filterValues = args.column.filterValues; let filterValues = args.column.filterValues;
if (filterValues) { if (filterValues) {
let currentFilteredItems = this.dataView.getFilteredItems();
if (filterValues.length === 0) { if (filterValues.length === 0) {
// if an associated styling exists with the current filters // if an associated styling exists with the current filters
if (this.filterStylingMap[args.column.name]) { if (this.filterStylingMap[args.column.name]) {
@@ -276,9 +277,8 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
delete this.filterValueMap[args.column.name]; delete this.filterValueMap[args.column.name];
} }
// apply the previous filter styling // apply the previous filter styling
let currentItems = this.dataView.getFilteredItems(); let previousFilteredItems = this.filterValueMap[this.filterStack[this.filterStack.length - 1]].filteredItems;
let styledItems = this.filterValueMap[this.filterStack[this.filterStack.length - 1]][1]; if (previousFilteredItems === currentFilteredItems) {
if (styledItems === currentItems) {
let lastColStyle = this.filterStylingMap[this.filterStack[this.filterStack.length - 1]]; let lastColStyle = this.filterStylingMap[this.filterStack[this.filterStack.length - 1]];
for (let i = 0; i < lastColStyle.length; i++) { for (let i = 0; i < lastColStyle.length; i++) {
this._table.grid.setCellCssStyles(lastColStyle[i][0], lastColStyle[i][1]); this._table.grid.setCellCssStyles(lastColStyle[i][0], lastColStyle[i][1]);
@@ -286,7 +286,7 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
} else { } else {
// style it all over again // style it all over again
let seenJobs = 0; let seenJobs = 0;
for (let i = 0; i < currentItems.length; i++) { for (let i = 0; i < currentFilteredItems.length; i++) {
this._table.grid.removeCellCssStyles('error-row' + i.toString()); this._table.grid.removeCellCssStyles('error-row' + i.toString());
this._table.grid.removeCellCssStyles('notebook-error-row' + i.toString()); this._table.grid.removeCellCssStyles('notebook-error-row' + i.toString());
let item = this.dataView.getFilteredItems()[i]; let item = this.dataView.getFilteredItems()[i];
@@ -294,7 +294,6 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
this.addToStyleHash(seenJobs, false, this.filterStylingMap, args.column.name); this.addToStyleHash(seenJobs, false, this.filterStylingMap, args.column.name);
if (this.filterStack.indexOf(args.column.name) < 0) { if (this.filterStack.indexOf(args.column.name) < 0) {
this.filterStack.push(args.column.name); this.filterStack.push(args.column.name);
this.filterValueMap[args.column.name] = [filterValues];
} }
// one expansion for the row and one for // one expansion for the row and one for
// the error detail // the error detail
@@ -304,7 +303,6 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
seenJobs++; seenJobs++;
} }
this.dataView.refresh(); this.dataView.refresh();
this.filterValueMap[args.column.name].push(this.dataView.getFilteredItems());
this._table.grid.resetActiveCell(); this._table.grid.resetActiveCell();
} }
if (this.filterStack.length === 0) { if (this.filterStack.length === 0) {
@@ -320,12 +318,11 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
// current filter // current filter
if (!!filterValues.find(x => x === item[args.column.field])) { if (!!filterValues.find(x => x === item[args.column.field])) {
// check all previous filters // check all previous filters
if (this.checkPreviousFilters(item)) { if (this.isItemFiltered(item)) {
if (item.lastRunOutcome === 'Failed') { if (item.lastRunOutcome === 'Failed') {
this.addToStyleHash(seenNotebooks, false, this.filterStylingMap, args.column.name); this.addToStyleHash(seenNotebooks, false, this.filterStylingMap, args.column.name);
if (this.filterStack.indexOf(args.column.name) < 0) { if (this.filterStack.indexOf(args.column.name) < 0) {
this.filterStack.push(args.column.name); this.filterStack.push(args.column.name);
this.filterValueMap[args.column.name] = [filterValues];
} }
// one expansion for the row and one for // one expansion for the row and one for
// the error detail // the error detail
@@ -337,11 +334,7 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
} }
} }
this.dataView.refresh(); this.dataView.refresh();
if (this.filterValueMap[args.column.name]) { this.filterValueMap[args.column.name] = { filterValues: filterValues, filteredItems: this.dataView.getFilteredItems() };
this.filterValueMap[args.column.name].push(this.dataView.getFilteredItems());
} else {
this.filterValueMap[args.column.name] = this.dataView.getFilteredItems();
}
this._table.grid.resetActiveCell(); this._table.grid.resetActiveCell();
} }
@@ -414,7 +407,7 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
// cache the dataview for future use // cache the dataview for future use
this._notebookCacheObject.dataView = this.dataView; this._notebookCacheObject.dataView = this.dataView;
this.filterValueMap['start'] = [[], this.dataView.getItems()]; this.filterValueMap['start'] = { filterValues: [], filteredItems: this.dataView.getItems() };
this.loadJobHistories().catch(onUnexpectedError); this.loadJobHistories().catch(onUnexpectedError);
} }
@@ -608,12 +601,13 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
return [failing, nonFailing]; return [failing, nonFailing];
} }
private checkPreviousFilters(item): boolean { /**
* Returns true if the item matches all filters currently applied
*/
private isItemFiltered(item: IItem): boolean {
for (let column in this.filterValueMap) { for (let column in this.filterValueMap) {
if (column !== 'start' && this.filterValueMap[column][0].length > 0) { if (column !== 'start' && this.filterValueMap[column]) {
let temp = this.filterValueMap[column][0] as unknown; if (!this.filterValueMap[column].filterValues.includes(item[JobManagementUtilities.convertColNameToField(column)])) {
let arr = temp as [];
if (!arr.find(x => x === item[JobManagementUtilities.convertColNameToField(column)])) {
return false; return false;
} }
} }

View File

@@ -57,11 +57,7 @@ export class JobManagementUtilities {
} }
public static setRunnable(icon: HTMLElement, index: number) { public static setRunnable(icon: HTMLElement, index: number) {
let temp = icon.className as unknown; icon.classList.remove('non-runnable');
let classNameArr = temp as [];
if (classNameArr.find(x => x === 'non-runnable')) {
icon.className = icon.className.slice(0, index);
}
} }
public static getActionIconClassName(startIcon: HTMLElement, stopIcon: HTMLElement, executionStatus: number) { public static getActionIconClassName(startIcon: HTMLElement, stopIcon: HTMLElement, executionStatus: number) {

View File

@@ -1584,6 +1584,7 @@ declare namespace Slick {
public setPagingOptions(args: PagingOptions): void; public setPagingOptions(args: PagingOptions): void;
public getPagingInfo(): PagingOptions; public getPagingInfo(): PagingOptions;
public getItems(): T[]; public getItems(): T[];
public getFilteredItems(): T[]; // manually adding this type - it's present in the definition but not the typings file from DefinitelyTyped
public setItems(data: T[], objectIdProperty?: string): void; public setItems(data: T[], objectIdProperty?: string): void;
public setFilter(filterFn: (item: T, args: any) => boolean): void; // todo: typeof(args) public setFilter(filterFn: (item: T, args: any) => boolean): void; // todo: typeof(args)
public sort(comparer: Function, ascending: boolean): void; // todo: typeof(comparer), should be the same callback as Array.sort public sort(comparer: Function, ascending: boolean): void; // todo: typeof(comparer), should be the same callback as Array.sort