Fix Grid Links (#2393)

* fix grid links

* formatting

* remove commented code

* revert formatting functions

* fix build break
This commit is contained in:
Anthony Dresser
2018-09-04 17:44:16 -07:00
committed by GitHub
parent 0e7f89169e
commit ce0c955c29
4 changed files with 109 additions and 16 deletions

View File

@@ -3,6 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { $ } from 'vs/base/browser/dom';
import { escape } from 'sql/base/common/strings';
export class DBCellValue {
@@ -14,6 +15,7 @@ export class DBCellValue {
}
}
/**
* Format xml field into a hyperlink and performs HTML entity encoding
*/
@@ -53,4 +55,55 @@ export function textFormatter(row: number, cell: any, value: any, columnDef: any
}
return `<span title="${valueToDisplay}" class="${cellClasses}">${valueToDisplay}</span>`;
}
}
/** 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
* the tests to test for html escaping fail. I'm keeping this code around as we should migrate to it if we ever
* integrate into actual DOM testing (electron running in normal mode) later on.
export const hyperLinkFormatter: Slick.Formatter<any> = (row, cell, value, columnDef, dataContext): string => {
let classes: Array<string> = ['grid-cell-value-container'];
let displayValue = '';
if (DBCellValue.isDBCellValue(value)) {
if (!value.isNull) {
displayValue = value.displayValue;
classes.push('queryLink');
let linkContainer = $('a', {
class: classes.join(' '),
title: displayValue
});
linkContainer.innerText = displayValue;
return linkContainer.outerHTML;
} else {
classes.push('missing-value');
}
}
let cellContainer = $('span', { class: classes.join(' '), title: displayValue });
cellContainer.innerText = displayValue;
return cellContainer.outerHTML;
};
export const textFormatter: Slick.Formatter<any> = (row, cell, value, columnDef, dataContext): string => {
let displayValue = '';
let classes: Array<string> = ['grid-cell-value-container'];
if (DBCellValue.isDBCellValue(value)) {
if (!value.isNull) {
displayValue = value.displayValue.replace(/(\r\n|\n|\r)/g, ' ');
} else {
classes.push('missing-value');
displayValue = 'NULL';
}
}
let cellContainer = $('span', { class: classes.join(' '), title: displayValue });
cellContainer.innerText = displayValue;
return cellContainer.outerHTML;
};
*/