Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OPTIC-108: Text on grid view should be truncated #5369

Merged
merged 19 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/dist/libs/datamanager/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/dist/libs/datamanager/main.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* global describe, test, expect */
import { format } from 'date-fns';
import { dateTimeFormat } from '../DateTimeCell';
import { valueToString } from '../StringCell';

describe('StringCell valueToString', () => {
test('Undefined/Null', () => {
expect(valueToString(undefined)).toBe("");
expect(valueToString(null)).toBe("");
});

test('Boolean', () => {
expect(valueToString(true)).toBe("true");
expect(valueToString(false)).toBe("false");
});

test('Date', () => {
const testDate = new Date();

expect(valueToString(testDate)).toBe(format(testDate, dateTimeFormat));
});

test('String', () => {
const testString = 'Hello World!';
const testString2 = `Hello


World!`;

expect(valueToString(testString)).toBe(testString);
expect(valueToString(testString2)).toBe(testString2);
});

test('JSON', () => {
const json1 = {
a: 1,
b: '2',
c: null,
};
const jsonCircular = { b: 5 };

jsonCircular.a = jsonCircular;

expect(valueToString(json1)).toBe(JSON.stringify(json1));
expect(valueToString(jsonCircular)).toBe('Error: Invalid JSON');
});

test('Number', () => {
const test = 1234;

expect(valueToString(test)).toBe(test.toString());
expect(valueToString(0)).toBe("0");
});
});
10 changes: 8 additions & 2 deletions web/libs/datamanager/src/components/DataGroups/AudioDataGroup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { MediaPlayer } from "../Common/MediaPlayer/MediaPlayer";

export const AudioDataGroup = ({ value }) => {
const style = {
padding: 10,
height: AudioDataGroup.height,
boxSizing: "content-box",
};

return (
<div style={{ padding: 10, height: AudioDataGroup.height }}>
<div style={style}>
<MediaPlayer src={value} />
</div>
);
};

AudioDataGroup.height = 42;
AudioDataGroup.height = 32;
28 changes: 21 additions & 7 deletions web/libs/datamanager/src/components/DataGroups/TextDataGroup.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
const valueToString = (value) => {
import { format, isValid } from "date-fns";
import { dateTimeFormat } from "../CellViews/DateTimeCell";

export const valueToString = (value) => {
if (typeof value === "string") return value;
/* if undefined or null we'll treat it as empty string */
if (value === undefined || value === null) return "";
if (value instanceof Date && isValid(value)) return format(value, dateTimeFormat);

try {
/* JSON.stringify will handle JSON and non-strings, non-null, non-undefined */
return JSON.stringify(value);
} catch {
return value.toString();
return 'Error: Invalid JSON';
}
};

export const TextDataGroup = ({ value }) => {
const output = valueToString(value);
const style = {
padding: 5,
height: TextDataGroup.height,
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
};

return (
<div
style={{ padding: 5, height: TextDataGroup.height, overflow: "hidden" }}
>
{value ? valueToString(value) : ""}
<div style={style} title={output}>
{output}
</div>
);
};

TextDataGroup.height = 77;
TextDataGroup.height = 32;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* global describe, test, expect */
import { format } from 'date-fns';

import { valueToString } from '../TextDataGroup';
import { dateTimeFormat } from '../../CellViews/DateTimeCell';

describe('TextDataGroup valueToString', () => {
test('Undefined/Null', () => {
expect(valueToString(undefined)).toBe("");
expect(valueToString(null)).toBe("");
});

test('Boolean', () => {
expect(valueToString(true)).toBe("true");
expect(valueToString(false)).toBe("false");
});

test('Date', () => {
const testDate = new Date();

expect(valueToString(testDate)).toBe(format(testDate, dateTimeFormat));
});

test('String', () => {
const testString = 'Hello World!';
const testString2 = `Hello


World!`;

expect(valueToString(testString)).toBe(testString);
expect(valueToString(testString2)).toBe(testString2);
});

test('JSON', () => {
const json1 = {
a: 1,
b: '2',
c: null,
};
const jsonCircular = { b: 5 };

jsonCircular.a = jsonCircular;

expect(valueToString(json1)).toBe(JSON.stringify(json1));
expect(valueToString(jsonCircular)).toBe('Error: Invalid JSON');
});

test('Number', () => {
const test = 1234;

expect(valueToString(test)).toBe(test.toString());
expect(valueToString(0)).toBe("0");
});
});
Loading