Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit a070427

Browse files
authored
feat(gui): preview message of @Todo annotation (#777)
* feat(gui): preview message of `@Todo` annotation * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 9c03ff0 commit a070427

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { truncate } from './stringOperations';
2+
3+
describe('truncate', () => {
4+
test('should return strings with at most max length unchanged', () => {
5+
expect(truncate('Lorem ipsum', 11)).toBe('Lorem ipsum');
6+
});
7+
8+
test('should truncate strings longer than max length and append ...', () => {
9+
expect(truncate('Lorem ipsum', 10)).toBe('Lorem ips\u2026');
10+
});
11+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const truncate = function (text: string, maxLength: number): string {
2+
return text.length > maxLength ? text.substring(0, maxLength - 1) + '\u2026' : text;
3+
};

api-editor/gui/src/features/annotations/AnnotationView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
showRenameAnnotationForm,
6565
showTodoAnnotationForm,
6666
} from '../ui/uiSlice';
67+
import { truncate } from '../../common/util/stringOperations';
6768

6869
interface AnnotationViewProps {
6970
target: string;
@@ -252,6 +253,7 @@ export const AnnotationView: React.FC<AnnotationViewProps> = function ({ target
252253
{todoAnnotation && (
253254
<AnnotationTag
254255
type="todo"
256+
name={truncate(todoAnnotation.newTodo, 50)}
255257
annotation={todoAnnotation}
256258
onEdit={() => dispatch(showTodoAnnotationForm(target))}
257259
onDelete={() => dispatch(removeTodo(target))}

0 commit comments

Comments
 (0)