render xml properly in the grid (#4674)

* render xml properly in the grid

* fix html injection

* fix tslint error

* add comments and fix an issue

* fix comment
This commit is contained in:
Alan Ren
2019-03-26 11:48:55 -07:00
committed by GitHub
parent bceeda1cfd
commit 819b7b93d1
4 changed files with 29 additions and 8 deletions

View File

@@ -52,14 +52,31 @@ export function textFormatter(row: number, cell: any, value: any, columnDef: any
} else {
cellClasses += ' missing-value';
}
} else if (typeof value === 'string') {
valueToDisplay = escape(value.length > 250 ? value.slice(0, 250) + '...' : value);
} else if (typeof value === 'string' || (value && value.text)) {
if (value.text) {
valueToDisplay = value.text;
} else {
valueToDisplay = value;
}
valueToDisplay = escape(valueToDisplay.length > 250 ? valueToDisplay.slice(0, 250) + '...' : valueToDisplay);
titleValue = valueToDisplay;
}
return `<span title="${titleValue}" class="${cellClasses}">${valueToDisplay}</span>`;
}
/**
* Provide slick grid cell with encoded ariaLabel and plain text.
* text will be escaped by the textFormatter and ariaLabel will be consumed by slickgrid directly.
*/
export function slickGridDataItemColumnValueExtractor(value: any, columnDef: any): { text: string; ariaLabel: string; } {
let displayValue = value[columnDef.field];
return {
text: displayValue,
ariaLabel: displayValue ? escape(displayValue) : displayValue
};
}
/** The following code is a rewrite over the both formatter function using dom builder
* rather than string manipulation, which is a safer and easier method of achieving the same goal.
* However, when electron is in "Run as node" mode, dom creation acts differently than normal and therefore

View File

@@ -25,7 +25,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Event, Emitter } from 'vs/base/common/event';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Dimension } from 'vs/base/browser/dom';
import { textFormatter } from 'sql/parts/grid/services/sharedServices';
import { textFormatter, slickGridDataItemColumnValueExtractor } from 'sql/parts/grid/services/sharedServices';
import { PROFILER_MAX_MATCHES } from 'sql/parts/profiler/editor/controller/profilerFindWidget';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IStatusbarService, StatusbarAlignment, IStatusbarEntry } from 'vs/platform/statusbar/common/statusbar';
@@ -88,7 +88,9 @@ export class ProfilerTableEditor extends BaseEditor implements IProfilerControll
}
}
}
});
}, {
dataItemColumnValueExtractor: slickGridDataItemColumnValueExtractor
});
this._profilerTable.setSelectionModel(new RowSelectionModel());
attachTableStyler(this._profilerTable, this._themeService);

View File

@@ -15,7 +15,7 @@ import { ProfilerTableEditor, ProfilerTableViewState } from './controller/profil
import * as Actions from 'sql/parts/profiler/contrib/profilerActions';
import { CONTEXT_PROFILER_EDITOR, PROFILER_TABLE_COMMAND_SEARCH } from './interfaces';
import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox';
import { textFormatter } from 'sql/parts/grid/services/sharedServices';
import { textFormatter, slickGridDataItemColumnValueExtractor } from 'sql/parts/grid/services/sharedServices';
import { ProfilerResourceEditor } from './profilerResourceEditor';
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { ITextModel } from 'vs/editor/common/model';
@@ -365,7 +365,10 @@ export class ProfilerEditor extends BaseEditor {
formatter: textFormatter
}
]
}, { forceFitColumns: true });
}, {
forceFitColumns: true,
dataItemColumnValueExtractor: slickGridDataItemColumnValueExtractor
});
this._detailTableData.onRowCountChange(() => {
this._detailTable.updateRowCount();

View File

@@ -18,7 +18,6 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { Event, Emitter } from 'vs/base/common/event';
import { generateUuid } from 'vs/base/common/uuid';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { escape } from 'sql/base/common/strings';
import * as types from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import Severity from 'vs/base/common/severity';
@@ -258,7 +257,7 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
let columnName = this._columnMapping[key];
if (columnName) {
let value = e.values[key];
data[columnName] = escape(value);
data[columnName] = value;
}
}
newEvents.push(data);