Add a check for strings with only new line chars
This commit is contained in:
@@ -12,11 +12,14 @@ const codes: { [key: string]: any } = {
|
||||
'\0': 'U+0000',
|
||||
'\b': 'U+0008',
|
||||
'\t': 'U+0009',
|
||||
'\n': 'U+000A',
|
||||
'\v': 'U+000B',
|
||||
'\r': 'U+000D'
|
||||
};
|
||||
|
||||
function onlyNewLine(element: string, index: number, array: string[]) {
|
||||
return element === '\n';
|
||||
}
|
||||
|
||||
export default function RawTableValue(props: Props): JSX.Element {
|
||||
const rawValue = props.value;
|
||||
|
||||
@@ -26,12 +29,17 @@ export default function RawTableValue(props: Props): JSX.Element {
|
||||
|| typeof rawValue === 'boolean'
|
||||
) {
|
||||
const text = rawValue.toString();
|
||||
const newVal = text.split('');
|
||||
for (let i = 0; i < newVal.length; i++) {
|
||||
newVal[i] = codes[newVal[i]] || newVal[i];
|
||||
const newVal = text.split('').filter((element: string) => element !== ' ');
|
||||
if (newVal.every(onlyNewLine)) {
|
||||
const cleanVal = '[' + newVal.join('') + ']';
|
||||
return <span>{cleanVal}</span>;
|
||||
} else {
|
||||
for (let i = 0; i < newVal.length; i++) {
|
||||
newVal[i] = codes[newVal[i]] || newVal[i];
|
||||
}
|
||||
const cleanVal = newVal.join('');
|
||||
return <span>{cleanVal}</span>;
|
||||
}
|
||||
const cleanVal = newVal.join('');
|
||||
return <span>{cleanVal}</span>;
|
||||
}
|
||||
|
||||
return renderLocation(rawValue.url, rawValue.label, props.databaseUri);
|
||||
|
||||
Reference in New Issue
Block a user